Skip to content
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

Updated git data commit response with signature verification object #1398

Merged
merged 7 commits into from
Jun 26, 2016
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
1 change: 1 addition & 0 deletions CustomDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Word>Tarball</Word>
<Word>Unsuspend</Word>
<Word>Zipball</Word>
<Word>Gpg</Word>
</Recognized>
</Words>
<Acronyms>
Expand Down
17 changes: 17 additions & 0 deletions Octokit.Tests.Integration/Clients/CommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ public async Task CanCreateAndRetrieveCommit()
Assert.NotNull(retrieved);
}
}

[IntegrationTest]
public async Task CanDeserializeVerificationObjectInResponse()
{
var github = Helper.GetAuthenticatedClient();

var commit = await github.Git.Commit.Get("noonari", "Signature-Verification", "1965d149ce1151cf411300d15f8d890d9259bd21");

Assert.False(commit.Verification.Verified);
Assert.Equal(commit.Verification.Signature,
"-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1\n\niQEcBAABAgAGBQJXYT2BAAoJEJyZ1vxIV0+N9ZwIAKlf3dk9n1q1mD5AT3Ahtj9o\nF4H25zsHynJk2lnH4YxVvDBEc/uMCXzX6orihZiSdA5UXE7tPyEEZddQdp8pxulX\ncIsFKcrfQqHJnTbT90z5PhAk94lyN9fFngzPW1tgZZVjp2YiiqgXduBWWm6EREOh\nS1Iu9wBqScQomhTXoksmNZyGTZ0LviSi0pkqRY64pQhKnpLlu1OFXaeDvhYocB+E\nY5URZsXodvIkBuzCkWCu8ra4eaXIIARkas4+jIvn0FIx9CzEVz0Zau/5Fk+BR+Te\n7a3/7JH7yuObPB0hqPSuFYyxtvPfxtayvhkGD3YkQqDAkWCpISGyVFzxrrC7z0Y=\n=kbih\n-----END PGP SIGNATURE-----");

Assert.Equal(commit.Verification.Payload,
"tree c91c844f37974093a3f0a864755441b577e7663a\nparent 6eb645f6badd46de65700b4d7b6fcdb97684ce5a\nauthor noonari <[email protected]> 1465990529 +0500\ncommitter noonari <[email protected]> 1465990529 +0500\n\ngpg stuff\n");

Assert.Equal(commit.Verification.Reason, VerificationReason.UnknownKey);
}
}
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/CommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void RequestsCorrectUrl()

client.Get("owner", "repo", "reference");

connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"));
connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"), Arg.Any<Dictionary<string, string>>(), "application/vnd.github.cryptographer-preview+sha");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/CommitsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Task<Commit> Get(string owner, string name, string reference)
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");

return ApiConnection.Get<Commit>(ApiUrls.Commit(owner, name, reference));
return ApiConnection.Get<Commit>(ApiUrls.Commit(owner, name, reference), null, AcceptHeaders.SignatureVerificationPreview);
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Octokit/Helpers/AcceptHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public static class AcceptHeaders
public const string MigrationsApiPreview = "application/vnd.github.wyandotte-preview+json";

public const string ReactionsPreview = "application/vnd.github.squirrel-girl-preview";


public const string SignatureVerificationPreview = "application/vnd.github.cryptographer-preview+sha";

[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
public const string GpgKeysPreview = "application/vnd.github.cryptographer-preview";
}
Expand Down
2 changes: 2 additions & 0 deletions Octokit/Models/Response/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ public Commit(string url, string label, string @ref, string sha, User user, Repo
public IReadOnlyList<GitReference> Parents { get; protected set; }

public int CommentCount { get; protected set; }

public Verification Verification { get; protected set; }
}
}
90 changes: 90 additions & 0 deletions Octokit/Models/Response/Verification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;

namespace Octokit
{
/// <summary>
/// Represents a Signature Verification Object in Git Data Commit Payload.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Verification
{
/// <summary>
/// Does GitHub consider the signature in this commit to be verified?
/// </summary>
public bool Verified { get; protected set; }

/// <summary>
/// The reason for verified value.
/// </summary>
[Parameter(Key = "reason")]
public VerificationReason Reason { get; protected set; }

/// <summary>
/// The signature that was extracted from the commit.
/// </summary>
public string Signature { get; protected set; }

/// <summary>
/// The value that was signed.
/// </summary>
public string Payload { get; protected set; }

internal string DebuggerDisplay
{
get
{
return string.Format(
CultureInfo.InvariantCulture,
"Verification: {0} Verified: {1} Reason: {2} Signature: {3} Payload",
Verified,
Reason.ToString(),
Signature,
Payload);
}
}
}

public enum VerificationReason
{
[Parameter(Value = "expired_key")]
ExpiredKey,

[Parameter(Value = "not_signing_key")]
NotSigningKey,

[Parameter(Value = "gpgverify_error")]
GpgVerifyError,

[Parameter(Value = "gpgverify_unavailable")]
GpgVerifyUnavailable,

[Parameter(Value = "unsigned")]
Unsigned,

[Parameter(Value = "unknown_signature_type")]
UnknownSignatureType,

[Parameter(Value = "no_user")]
NoUser,

[Parameter(Value = "unverified_email")]
UnverifiedEmail,

[Parameter(Value = "bad_email")]
BadEmail,

[Parameter(Value = "unknown_key")]
UnknownKey,

[Parameter(Value = "malformed_signature")]
MalformedSignature,

[Parameter(Value = "inavlid")]
Invalid,

[Parameter(Value = "valid")]
Valid
}
}
1 change: 1 addition & 0 deletions Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@
<Compile Include="Clients\UserGpgKeysClient.cs" />
<Compile Include="Models\Request\NewGpgKey.cs" />
<Compile Include="Models\Response\GpgKey.cs" />
<Compile Include="Models\Response\Verification.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@
<Compile Include="Models\Request\NewGpgKey.cs" />
<Compile Include="Models\Response\GpgKey.cs" />
<Compile Include="Models\Response\ReactionSummary.cs" />
<Compile Include="Models\Response\Verification.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
<Compile Include="Models\Request\NewGpgKey.cs" />
<Compile Include="Models\Response\GpgKey.cs" />
<Compile Include="Models\Response\ReactionSummary.cs" />
<Compile Include="Models\Response\Verification.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
<Compile Include="Models\Request\NewGpgKey.cs" />
<Compile Include="Models\Response\GpgKey.cs" />
<Compile Include="Models\Response\ReactionSummary.cs" />
<Compile Include="Models\Response\Verification.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@
<Compile Include="Models\Request\NewGpgKey.cs" />
<Compile Include="Models\Response\GpgKey.cs" />
<Compile Include="Models\Response\ReactionSummary.cs" />
<Compile Include="Models\Response\Verification.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Models\Response\TagObject.cs" />
<Compile Include="Models\Response\AccountType.cs" />
<Compile Include="Models\Response\Verification.cs" />
<Compile Include="Models\Response\WeeklyCommitActivity.cs" />
<Compile Include="Models\Response\Participation.cs" />
<Compile Include="Models\Response\WeeklyHash.cs" />
Expand Down