Skip to content

Add missing CertificateCheckHandler parameter to some APIs #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LibGit2Sharp.Tests/NetworkFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public void CanListRemoteReferencesWithCredentials()
{
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);

var references = repo.Network.ListReferences(remote, Constants.PrivateRepoCredentials, new ProxyOptions());
var references = repo.Network.ListReferences(remote,
Constants.PrivateRepoCredentials, Constants.PrivateRepoCertificateCheck, new ProxyOptions());

foreach (var reference in references)
{
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public void CanListRemoteReferencesWithCredentials()
"Populate Constants.PrivateRepo* to run this test");

IEnumerable<Reference> references = Repository.ListRemoteReferences(Constants.PrivateRepoUrl,
Constants.PrivateRepoCredentials, new ProxyOptions());
Constants.PrivateRepoCredentials, Constants.PrivateRepoCertificateCheck, new ProxyOptions());

foreach (var reference in references)
{
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
return null;
}

public static bool PrivateRepoCertificateCheck(Certificate certificate, bool valid, string host)
{
return true;
}

public static string BuildPath()
{
string tempPath = null;
Expand Down
30 changes: 22 additions & 8 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote)
{
Ensure.ArgumentNotNull(remote, "remote");

return ListReferencesInternal(remote.Url, null, null);
return ListReferencesInternal(remote.Url, null, null, null);
}

/// <summary>
Expand All @@ -66,14 +66,19 @@ public virtual IEnumerable<Reference> ListReferences(Remote remote)
/// </summary>
/// <param name="remote">The <see cref="Remote"/> to list from.</param>
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings</param>
/// <returns>The references in the <see cref="Remote"/> repository.</returns>
public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
public virtual IEnumerable<Reference> ListReferences(
Remote remote,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(remote, "remote");
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");

return ListReferencesInternal(remote.Url, credentialsProvider, proxyOptions);
return ListReferencesInternal(remote.Url, credentialsProvider, certificateCheckHandler, proxyOptions);
}

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

return ListReferencesInternal(url, null, null);
return ListReferencesInternal(url, null, null, null);
}

/// <summary>
Expand All @@ -105,17 +110,26 @@ public virtual IEnumerable<Reference> ListReferences(string url)
/// </summary>
/// <param name="url">The url to list from.</param>
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings</param>
/// <returns>The references in the remote repository.</returns>
public virtual IEnumerable<Reference> ListReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
public virtual IEnumerable<Reference> ListReferences(
string url,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");

return ListReferencesInternal(url, credentialsProvider, proxyOptions);
return ListReferencesInternal(url, credentialsProvider, certificateCheckHandler, proxyOptions);
}

private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
private IEnumerable<Reference> ListReferencesInternal(
string url,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
ProxyOptions proxyOptions)
{
using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url))
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
Expand All @@ -125,7 +139,7 @@ private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHan

if (credentialsProvider != null)
{
var callbacks = new RemoteCallbacks(credentialsProvider);
var callbacks = new RemoteCallbacks(credentialsProvider, certificateCheckHandler);
gitCallbacks = callbacks.GenerateCallbacks();
}

Expand Down
4 changes: 0 additions & 4 deletions LibGit2Sharp/RemoteCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ internal RemoteCallbacks(CredentialsHandler credentialsProvider, CertificateChec
CertificateCheck = certificateCheck;
}

internal RemoteCallbacks(CredentialsHandler credentialsProvider)
: this(credentialsProvider, null)
{ }

internal RemoteCallbacks(PushOptions pushOptions)
{
if (pushOptions == null)
Expand Down
29 changes: 22 additions & 7 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ internal Commit LookupCommit(string committish)
/// <returns>The references in the remote repository.</returns>
public static IEnumerable<Reference> ListRemoteReferences(string url)
{
return ListRemoteReferences(url, null, null);
return ListRemoteReferences(url, null, null, null);
}

/// <summary>
Expand All @@ -686,15 +686,20 @@ public static IEnumerable<Reference> ListRemoteReferences(string url)
/// </para>
/// <param name="url">The url to list from.</param>
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings.</param>
/// <returns>The references in the remote repository.</returns>
public static IEnumerable<Reference> ListRemoteReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
public static IEnumerable<Reference> ListRemoteReferences(
string url,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");

using (RepositoryHandle repositoryHandle = Proxy.git_repository_new())
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, proxyOptionsWrapper.GitProxyOptions))
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, certificateCheckHandler, proxyOptionsWrapper.GitProxyOptions))
{
return Proxy.git_remote_ls(null, remoteHandle);
}
Expand All @@ -705,29 +710,39 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, Credential
/// </summary>
/// <param name="url">The url to retrieve from.</param>
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
/// <param name="certificateCheckHandler">The <see cref="CertificateCheckHandler"/> used to resolve SSL certificate errors.</param>
/// <param name="proxyOptions"><see cref="ProxyOptions"/> controlling proxy settings.</param>
/// <returns>The reference name.</returns>
public static string GetRemoteDefaultBranch(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
public static string GetRemoteDefaultBranch(
string url,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");

using (RepositoryHandle repositoryHandle = Proxy.git_repository_new())
using (GitProxyOptionsWrapper proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions))
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, proxyOptionsWrapper.GitProxyOptions))
using (RemoteHandle remoteHandle = ConnectToAnonymousRemote(repositoryHandle, url, credentialsProvider, certificateCheckHandler, proxyOptionsWrapper.GitProxyOptions))
{
return Proxy.git_remote_default_branch(remoteHandle);
}
}

private static RemoteHandle ConnectToAnonymousRemote(RepositoryHandle repositoryHandle, string url, CredentialsHandler credentialsProvider, GitProxyOptions proxyOptions)
private static RemoteHandle ConnectToAnonymousRemote(
RepositoryHandle repositoryHandle,
string url,
CredentialsHandler credentialsProvider,
CertificateCheckHandler certificateCheckHandler,
GitProxyOptions proxyOptions)
{
RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url);

var gitCallbacks = new GitRemoteCallbacks { version = 1 };

if (credentialsProvider != null)
{
var callbacks = new RemoteCallbacks(credentialsProvider);
var callbacks = new RemoteCallbacks(credentialsProvider, certificateCheckHandler);
gitCallbacks = callbacks.GenerateCallbacks();
}

Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.111.0",
"version": "1.111.100",
"cloudBuild": {
"buildNumber": {
"enabled": true
Expand Down