From 771415e751e39731f9ac8e329a945ac5e303fd25 Mon Sep 17 00:00:00 2001 From: Sarmad Date: Sat, 18 Jun 2016 01:31:56 +0500 Subject: [PATCH 1/7] updated git data commit response with signature Verification object --- CustomDictionary.xml | 1 + .../Clients/CommitsClientTests.cs | 17 ++++ Octokit.Tests/Clients/CommitsClientTests.cs | 2 +- Octokit/Clients/CommitsClient.cs | 2 +- Octokit/Helpers/AcceptHeaders.cs | 4 +- Octokit/Models/Response/Commit.cs | 6 +- Octokit/Models/Response/Verification.cs | 96 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 13 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 Octokit/Models/Response/Verification.cs diff --git a/CustomDictionary.xml b/CustomDictionary.xml index 0f5443f0dd..5bb0276c70 100644 --- a/CustomDictionary.xml +++ b/CustomDictionary.xml @@ -25,6 +25,7 @@ Tarball Unsuspend Zipball + Gpg diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index aa46429f66..7d50d27857 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -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", "source-repo-20160517084127190", "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 1465990529 +0500\ncommitter noonari 1465990529 +0500\n\ngpg stuff\n"); + + Assert.Equal(commit.Verification.Reason.ToString(), "UnknownKey"); + } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CommitsClientTests.cs b/Octokit.Tests/Clients/CommitsClientTests.cs index 6c1c420168..72d3dafff6 100644 --- a/Octokit.Tests/Clients/CommitsClientTests.cs +++ b/Octokit.Tests/Clients/CommitsClientTests.cs @@ -31,7 +31,7 @@ public void RequestsCorrectUrl() client.Get("owner", "repo", "reference"); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/commits/reference")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/commits/reference"), Arg.Any>(), "application/vnd.github.cryptographer-preview+sha"); } } diff --git a/Octokit/Clients/CommitsClient.cs b/Octokit/Clients/CommitsClient.cs index ea5588ea09..37ba2bc75d 100644 --- a/Octokit/Clients/CommitsClient.cs +++ b/Octokit/Clients/CommitsClient.cs @@ -35,7 +35,7 @@ public Task Get(string owner, string name, string reference) Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - return ApiConnection.Get(ApiUrls.Commit(owner, name, reference)); + return ApiConnection.Get(ApiUrls.Commit(owner, name, reference), null, AcceptHeaders.SignatureVerification); } /// diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 0002896ac7..05d30cc1c5 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -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 SignatureVerification = "application/vnd.github.cryptographer-preview+sha"; + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] public const string GpgKeysPreview = "application/vnd.github.cryptographer-preview"; } diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 374398c0bb..8564777835 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using Octokit.Internal; +using Octokit.Models.Response; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; @@ -34,5 +36,7 @@ public Commit(string url, string label, string @ref, string sha, User user, Repo public IReadOnlyList Parents { get; protected set; } public int CommentCount { get; protected set; } + + public Verification Verification { get; protected set; } } } diff --git a/Octokit/Models/Response/Verification.cs b/Octokit/Models/Response/Verification.cs new file mode 100644 index 0000000000..a1fb207427 --- /dev/null +++ b/Octokit/Models/Response/Verification.cs @@ -0,0 +1,96 @@ +using Octokit.Internal; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit.Models.Response +{ + /// + /// Represents a Signature Verification Object in Git Data Commit Payload. + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class Verification + { + /// + /// Does GitHub consider the signature in this commit to be verified? + /// + public bool Verified { get; set; } + + /// + /// The reason for verified value. + /// + [Parameter(Key = "reason")] + public Reason Reason { get; set; } + + /// + /// The signature that was extracted from the commit. + /// + public string Signature { get; set; } + + /// + /// The value that was signed. + /// + public string Payload { get; 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 Reason + { + [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 + + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 6a0db8dd3c..7c6a3564f6 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -484,6 +484,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 928b8440ba..8b66b03d30 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -495,6 +495,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index b0d416fe45..68b0e6ff83 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -491,6 +491,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index ee2e5bc965..c7a7f4fa47 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -481,6 +481,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 7ac0288d97..3d7d9a74d8 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -488,6 +488,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 6c21d844fa..29da34ce5c 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -394,6 +394,7 @@ + From 484b63a3a9eb92327c38d1124d1c9d4ab4062844 Mon Sep 17 00:00:00 2001 From: Sarmad Date: Sat, 18 Jun 2016 02:54:08 +0500 Subject: [PATCH 2/7] how stupid i am sometimes... --- Octokit/Models/Response/Verification.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit/Models/Response/Verification.cs b/Octokit/Models/Response/Verification.cs index a1fb207427..b40f5a2f60 100644 --- a/Octokit/Models/Response/Verification.cs +++ b/Octokit/Models/Response/Verification.cs @@ -18,23 +18,23 @@ public class Verification /// /// Does GitHub consider the signature in this commit to be verified? /// - public bool Verified { get; set; } + public bool Verified { get; protected set; } /// /// The reason for verified value. /// [Parameter(Key = "reason")] - public Reason Reason { get; set; } + public Reason Reason { get; protected set; } /// /// The signature that was extracted from the commit. /// - public string Signature { get; set; } + public string Signature { get; protected set; } /// /// The value that was signed. /// - public string Payload { get; set; } + public string Payload { get; protected set; } internal string DebuggerDisplay { From bb2338f95c1c4f805f019fdf5bc100de7ca3b645 Mon Sep 17 00:00:00 2001 From: Sarmad Date: Sat, 18 Jun 2016 05:32:23 +0500 Subject: [PATCH 3/7] some fixes --- Octokit.Tests.Integration/Clients/CommitsClientTests.cs | 6 +++--- Octokit/Models/Response/Commit.cs | 5 ++--- Octokit/Models/Response/Verification.cs | 9 ++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index 7d50d27857..3815d106a6 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -49,15 +49,15 @@ public async Task CanDeserializeVerificationObjectInResponse() { var github = Helper.GetAuthenticatedClient(); - var commit = await github.Git.Commit.Get("noonari", "source-repo-20160517084127190", "1965d149ce1151cf411300d15f8d890d9259bd21"); + 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, + Assert.Equal(commit.Verification.Payload, "tree c91c844f37974093a3f0a864755441b577e7663a\nparent 6eb645f6badd46de65700b4d7b6fcdb97684ce5a\nauthor noonari 1465990529 +0500\ncommitter noonari 1465990529 +0500\n\ngpg stuff\n"); - Assert.Equal(commit.Verification.Reason.ToString(), "UnknownKey"); + Assert.Equal(commit.Verification.Reason, commit.Verification.Reason); } } \ No newline at end of file diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 8564777835..6f19c94344 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -1,9 +1,8 @@ -using Octokit.Internal; -using Octokit.Models.Response; -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using Octokit.Models.Response; namespace Octokit { diff --git a/Octokit/Models/Response/Verification.cs b/Octokit/Models/Response/Verification.cs index b40f5a2f60..d1fb9baa7a 100644 --- a/Octokit/Models/Response/Verification.cs +++ b/Octokit/Models/Response/Verification.cs @@ -1,11 +1,6 @@ -using Octokit.Internal; -using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.Diagnostics; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Octokit.Internal; namespace Octokit.Models.Response { From 711c5de07e3eeba9c0304c2a37b27241eb48f470 Mon Sep 17 00:00:00 2001 From: Sarmad Date: Mon, 20 Jun 2016 19:24:39 +0500 Subject: [PATCH 4/7] "Cleaning Up" --- Octokit/Helpers/AcceptHeaders.cs | 2 +- Octokit/Models/Response/Verification.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 05d30cc1c5..b9c762772b 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -28,7 +28,7 @@ public static class AcceptHeaders public const string ReactionsPreview = "application/vnd.github.squirrel-girl-preview"; - public const string SignatureVerification = "application/vnd.github.cryptographer-preview+sha"; + 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"; diff --git a/Octokit/Models/Response/Verification.cs b/Octokit/Models/Response/Verification.cs index d1fb9baa7a..9095d9c1a8 100644 --- a/Octokit/Models/Response/Verification.cs +++ b/Octokit/Models/Response/Verification.cs @@ -19,7 +19,7 @@ public class Verification /// The reason for verified value. /// [Parameter(Key = "reason")] - public Reason Reason { get; protected set; } + public VerificationReason Reason { get; protected set; } /// /// The signature that was extracted from the commit. @@ -46,7 +46,7 @@ internal string DebuggerDisplay } } - public enum Reason + public enum VerificationReason { [Parameter(Value = "expired_key")] ExpiredKey, @@ -86,6 +86,5 @@ public enum Reason [Parameter(Value = "valid")] Valid - } } From 46a81afb99145a5dcb06a722710d6c5ef77aca07 Mon Sep 17 00:00:00 2001 From: Sarmad Date: Mon, 20 Jun 2016 20:18:38 +0500 Subject: [PATCH 5/7] fix minor renaming issue --- Octokit/Clients/CommitsClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/CommitsClient.cs b/Octokit/Clients/CommitsClient.cs index 37ba2bc75d..555b661736 100644 --- a/Octokit/Clients/CommitsClient.cs +++ b/Octokit/Clients/CommitsClient.cs @@ -35,7 +35,7 @@ public Task Get(string owner, string name, string reference) Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - return ApiConnection.Get(ApiUrls.Commit(owner, name, reference), null, AcceptHeaders.SignatureVerification); + return ApiConnection.Get(ApiUrls.Commit(owner, name, reference), null, AcceptHeaders.SignatureVerificationPreview); } /// From 3b941d9cd0296870120377df864f71c65277b0be Mon Sep 17 00:00:00 2001 From: Sarmad Date: Mon, 20 Jun 2016 21:06:31 +0500 Subject: [PATCH 6/7] minor improvement --- Octokit.Tests.Integration/Clients/CommitsClientTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index 3815d106a6..80cc944c25 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Octokit; +using Octokit.Models.Response; using Octokit.Tests.Integration.Helpers; using Octokit.Tests.Integration; using Xunit; @@ -58,6 +59,6 @@ public async Task CanDeserializeVerificationObjectInResponse() Assert.Equal(commit.Verification.Payload, "tree c91c844f37974093a3f0a864755441b577e7663a\nparent 6eb645f6badd46de65700b4d7b6fcdb97684ce5a\nauthor noonari 1465990529 +0500\ncommitter noonari 1465990529 +0500\n\ngpg stuff\n"); - Assert.Equal(commit.Verification.Reason, commit.Verification.Reason); + Assert.Equal(commit.Verification.Reason, VerificationReason.UnknownKey); } } \ No newline at end of file From 6e1ded0c546db81c0a8e9d3d0c5f1ab9c6a1c12f Mon Sep 17 00:00:00 2001 From: Sarmad Date: Mon, 27 Jun 2016 00:23:50 +0500 Subject: [PATCH 7/7] fix namespace --- Octokit.Tests.Integration/Clients/CommitsClientTests.cs | 1 - Octokit/Models/Response/Commit.cs | 1 - Octokit/Models/Response/Verification.cs | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index 80cc944c25..6ccf365a2a 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using Octokit; -using Octokit.Models.Response; using Octokit.Tests.Integration.Helpers; using Octokit.Tests.Integration; using Xunit; diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 6f19c94344..7023193790 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -2,7 +2,6 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; -using Octokit.Models.Response; namespace Octokit { diff --git a/Octokit/Models/Response/Verification.cs b/Octokit/Models/Response/Verification.cs index 9095d9c1a8..fdc703bf3f 100644 --- a/Octokit/Models/Response/Verification.cs +++ b/Octokit/Models/Response/Verification.cs @@ -2,7 +2,7 @@ using System.Globalization; using Octokit.Internal; -namespace Octokit.Models.Response +namespace Octokit { /// /// Represents a Signature Verification Object in Git Data Commit Payload.