Skip to content

Commit 26dd4b6

Browse files
A-Ovchinnikov-mxAlexander Ovchinnikov
A-Ovchinnikov-mx
authored and
Alexander Ovchinnikov
committed
Add missing CertificateCheckHandler parameter to some APIs
1 parent 6e99ab0 commit 26dd4b6

File tree

6 files changed

+52
-21
lines changed

6 files changed

+52
-21
lines changed

LibGit2Sharp.Tests/NetworkFixture.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public void CanListRemoteReferencesWithCredentials()
127127
{
128128
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
129129

130-
var references = repo.Network.ListReferences(remote, Constants.PrivateRepoCredentials, new ProxyOptions());
130+
var references = repo.Network.ListReferences(remote,
131+
Constants.PrivateRepoCredentials, Constants.PrivateRepoCertificateCheck, new ProxyOptions());
131132

132133
foreach (var reference in references)
133134
{

LibGit2Sharp.Tests/RepositoryFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public void CanListRemoteReferencesWithCredentials()
697697
"Populate Constants.PrivateRepo* to run this test");
698698

699699
IEnumerable<Reference> references = Repository.ListRemoteReferences(Constants.PrivateRepoUrl,
700-
Constants.PrivateRepoCredentials, new ProxyOptions());
700+
Constants.PrivateRepoCredentials, Constants.PrivateRepoCertificateCheck, new ProxyOptions());
701701

702702
foreach (var reference in references)
703703
{

LibGit2Sharp.Tests/TestHelpers/Constants.cs

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
5151
return null;
5252
}
5353

54+
public static bool PrivateRepoCertificateCheck(Certificate certificate, bool valid, string host)
55+
{
56+
return true;
57+
}
58+
5459
public static string BuildPath()
5560
{
5661
string tempPath = null;

LibGit2Sharp/Network.cs

+22-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote)
5252
{
5353
Ensure.ArgumentNotNull(remote, "remote");
5454

55-
return ListReferencesInternal(remote.Url, null, null);
55+
return ListReferencesInternal(remote.Url, null, null, null);
5656
}
5757

5858
/// <summary>
@@ -66,14 +66,19 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote)
6666
/// </summary>
6767
/// <param name="remote">The <see cref="Remote"/> to list from.</param>
6868
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
69+
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
6970
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings</param>
7071
/// <returns>The references in the <see cref="Remote"/> repository.</returns>
71-
public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
72+
public virtual IEnumerable<Reference> ListReferences(
73+
Remote remote,
74+
CredentialsHandler credentialsProvider,
75+
CertificateCheckHandler certificateCheckHandler,
76+
ProxyOptions proxyOptions)
7277
{
7378
Ensure.ArgumentNotNull(remote, "remote");
7479
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
7580

76-
return ListReferencesInternal(remote.Url, credentialsProvider, proxyOptions);
81+
return ListReferencesInternal(remote.Url, credentialsProvider, certificateCheckHandler, proxyOptions);
7782
}
7883

7984
/// <summary>
@@ -91,7 +96,7 @@ public virtual IEnumerable<Reference> ListReferences(string url)
9196
{
9297
Ensure.ArgumentNotNull(url, "url");
9398

94-
return ListReferencesInternal(url, null, null);
99+
return ListReferencesInternal(url, null, null, null);
95100
}
96101

97102
/// <summary>
@@ -105,17 +110,26 @@ public virtual IEnumerable<Reference> ListReferences(string url)
105110
/// </summary>
106111
/// <param name="url">The url to list from.</param>
107112
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
113+
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
108114
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings</param>
109115
/// <returns>The references in the remote repository.</returns>
110-
public virtual IEnumerable<Reference> ListReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
116+
public virtual IEnumerable<Reference> ListReferences(
117+
string url,
118+
CredentialsHandler credentialsProvider,
119+
CertificateCheckHandler certificateCheckHandler,
120+
ProxyOptions proxyOptions)
111121
{
112122
Ensure.ArgumentNotNull(url, "url");
113123
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
114124

115-
return ListReferencesInternal(url, credentialsProvider, proxyOptions);
125+
return ListReferencesInternal(url, credentialsProvider, certificateCheckHandler, proxyOptions);
116126
}
117127

118-
private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
128+
private IEnumerable<Reference> ListReferencesInternal(
129+
string url,
130+
CredentialsHandler credentialsProvider,
131+
CertificateCheckHandler certificateCheckHandler,
132+
ProxyOptions proxyOptions)
119133
{
120134
using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url))
121135
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
@@ -125,7 +139,7 @@ private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHan
125139

126140
if (credentialsProvider != null)
127141
{
128-
var callbacks = new RemoteCallbacks(credentialsProvider);
142+
var callbacks = new RemoteCallbacks(credentialsProvider, certificateCheckHandler);
129143
gitCallbacks = callbacks.GenerateCallbacks();
130144
}
131145

LibGit2Sharp/RemoteCallbacks.cs

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ internal RemoteCallbacks(CredentialsHandler credentialsProvider, CertificateChec
1818
CertificateCheck = certificateCheck;
1919
}
2020

21-
internal RemoteCallbacks(CredentialsHandler credentialsProvider)
22-
: this(credentialsProvider, null)
23-
{ }
24-
2521
internal RemoteCallbacks(PushOptions pushOptions)
2622
{
2723
if (pushOptions == null)

LibGit2Sharp/Repository.cs

+22-7
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ internal Commit LookupCommit(string committish)
673673
/// <returns>The references in the remote repository.</returns>
674674
public static IEnumerable<Reference> ListRemoteReferences(string url)
675675
{
676-
return ListRemoteReferences(url, null, null);
676+
return ListRemoteReferences(url, null, null, null);
677677
}
678678

679679
/// <summary>
@@ -686,15 +686,20 @@ public static IEnumerable<Reference> ListRemoteReferences(string url)
686686
/// </para>
687687
/// <param name="url">The url to list from.</param>
688688
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
689+
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
689690
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings.</param>
690691
/// <returns>The references in the remote repository.</returns>
691-
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
692+
public static IEnumerable<Reference> ListRemoteReferences(
693+
string url,
694+
CredentialsHandler credentialsProvider,
695+
CertificateCheckHandler certificateCheckHandler,
696+
ProxyOptions proxyOptions)
692697
{
693698
Ensure.ArgumentNotNull(url, "url");
694699

695700
using (RepositoryHandle repositoryHandle = Proxy.git_repository_new())
696701
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
697-
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, proxyOptionsWrapper.GitProxyOptions))
702+
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, certificateCheckHandler, proxyOptionsWrapper.GitProxyOptions))
698703
{
699704
return Proxy.git_remote_ls(null, remoteHandle);
700705
}
@@ -705,29 +710,39 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, Credential
705710
/// </summary>
706711
/// <param name="url">The url to retrieve from.</param>
707712
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
713+
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
708714
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings.</param>
709715
/// <returns>The reference name.</returns>
710-
public static string GetRemoteDefaultBranch(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
716+
public static string GetRemoteDefaultBranch(
717+
string url,
718+
CredentialsHandler credentialsProvider,
719+
CertificateCheckHandler certificateCheckHandler,
720+
ProxyOptions proxyOptions)
711721
{
712722
Ensure.ArgumentNotNull(url, "url");
713723

714724
using (RepositoryHandle repositoryHandle = Proxy.git_repository_new())
715725
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
716-
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, proxyOptionsWrapper.GitProxyOptions))
726+
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, certificateCheckHandler, proxyOptionsWrapper.GitProxyOptions))
717727
{
718728
return Proxy.git_remote_default_branch(remoteHandle);
719729
}
720730
}
721731

722-
private static RemoteHandle ConnectToAnonymousRemote(RepositoryHandle repositoryHandle, string url, CredentialsHandler credentialsProvider, GitProxyOptions proxyOptions)
732+
private static RemoteHandle ConnectToAnonymousRemote(
733+
RepositoryHandle repositoryHandle,
734+
string url,
735+
CredentialsHandler credentialsProvider,
736+
CertificateCheckHandler certificateCheckHandler,
737+
GitProxyOptions proxyOptions)
723738
{
724739
RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url);
725740

726741
var gitCallbacks = new GitRemoteCallbacks { version = 1 };
727742

728743
if (credentialsProvider != null)
729744
{
730-
var callbacks = new RemoteCallbacks(credentialsProvider);
745+
var callbacks = new RemoteCallbacks(credentialsProvider, certificateCheckHandler);
731746
gitCallbacks = callbacks.GenerateCallbacks();
732747
}
733748

0 commit comments

Comments
 (0)