diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index e108b9c0..99b236aa 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -109,6 +109,21 @@ namespace Octokit.Tests.Clients Args.Object); } + [Fact] + public void GetsOrCreatesAuthenticationAtCorrectUrlUsingTwoFactor() + { + var data = new NewAuthorization(); + var client = Substitute.For(); + var authEndpoint = new AuthorizationsClient(client); + + authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "two-factor"); + + client.Received().Put( + Arg.Is(u => u.ToString() == "/authorizations/clients/clientId"), + Args.Object, + "two-factor"); + } + [Fact] public async Task WrapsTwoFactorFailureWithTwoFactorException() { diff --git a/Octokit.Tests/Http/ConnectionTests.cs b/Octokit.Tests/Http/ConnectionTests.cs index f005f37d..989260f0 100644 --- a/Octokit.Tests/Http/ConnectionTests.cs +++ b/Octokit.Tests/Http/ConnectionTests.cs @@ -236,6 +236,7 @@ namespace Octokit.Tests.Http req.BaseAddress == ExampleUri && (string)req.Body == data && req.Method == HttpVerb.Patch && + req.ContentType == "application/x-www-form-urlencoded" && req.Endpoint == new Uri("/endpoint", UriKind.Relative))); } } @@ -243,7 +244,7 @@ namespace Octokit.Tests.Http public class ThePutAsyncMethod { [Fact] - public async Task RunsConfiguredAppWithAppropriateEnv() + public async Task MakesPutRequestWithData() { string data = SimpleJson.SerializeObject(new object()); var httpClient = Substitute.For(); @@ -261,6 +262,31 @@ namespace Octokit.Tests.Http req.BaseAddress == ExampleUri && (string)req.Body == data && req.Method == HttpMethod.Put && + req.ContentType == "application/x-www-form-urlencoded" && + req.Endpoint == new Uri("/endpoint", UriKind.Relative))); + } + + [Fact] + public async Task MakesPutRequestWithDataAndTwoFactor() + { + string data = SimpleJson.SerializeObject(new object()); + var httpClient = Substitute.For(); + IResponse response = new ApiResponse(); + httpClient.Send(Args.Request).Returns(Task.FromResult(response)); + var connection = new Connection("Test Runner", + ExampleUri, + Substitute.For(), + httpClient, + Substitute.For()); + + await connection.PutAsync(new Uri("/endpoint", UriKind.Relative), new object(), "two-factor"); + + httpClient.Received(1).Send(Arg.Is(req => + req.BaseAddress == ExampleUri && + (string)req.Body == data && + req.Method == HttpMethod.Put && + req.Headers["X-GitHub-OTP"] == "two-factor" && + req.ContentType == "application/x-www-form-urlencoded" && req.Endpoint == new Uri("/endpoint", UriKind.Relative))); } } diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index d45fb62b..a5f17d00 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -123,7 +123,10 @@ namespace Octokit public async Task> PutAsync(Uri endpoint, object body, string twoFactorAuthenticationCode) { - return await SendData(endpoint, HttpMethod.Put, body, twoFactorAuthenticationCode); + return await SendData(endpoint, + HttpMethod.Put, + body, + twoFactorAuthenticationCode: twoFactorAuthenticationCode); } async Task> SendData(