Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add test for lowercase "X-OAuth-Scopes" header
Browse files Browse the repository at this point in the history
  • Loading branch information
jcansdale committed Nov 2, 2020
1 parent 87b5ac8 commit acf6a88
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/GitHub.Api.UnitTests/LoginManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,30 @@ public void InvalidResponseScopesCauseException()
Assert.ThrowsAsync<IncorrectScopesException>(() => target.Login(host, client, "foo", "bar"));
}

IGitHubClient CreateClient(User user = null, string[] responseScopes = null)
[TestCase("X-OAuth-Scopes")]
[TestCase("x-oauth-scopes")]
public void ValidResponseScopesDoesNotThrow(string scopesHeader)
{
var client = CreateClient(responseScopes: scopes, scopesHeader: scopesHeader);
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>())
.Returns(CreateApplicationAuthorization("123abc"));

var keychain = Substitute.For<IKeychain>();
var tfa = new Lazy<ITwoFactorChallengeHandler>(() => Substitute.For<ITwoFactorChallengeHandler>());
var oauthListener = Substitute.For<IOAuthCallbackListener>();

var target = new LoginManager(keychain, tfa, oauthListener, "id", "secret", scopes, scopes);

Assert.DoesNotThrowAsync(() => target.Login(host, client, "foo", "bar"));
}

IGitHubClient CreateClient(User user = null, string[] responseScopes = null, string scopesHeader = "X-OAuth-Scopes")
{
var result = Substitute.For<IGitHubClient>();
var userResponse = Substitute.For<IApiResponse<User>>();
userResponse.HttpResponse.Headers.Returns(new Dictionary<string, string>
{
{ "X-OAuth-Scopes", string.Join(",", responseScopes ?? scopes) }
{ scopesHeader, string.Join(",", responseScopes ?? scopes) }
});
userResponse.Body.Returns(user ?? new User());
result.Connection.Get<User>(new Uri("user", UriKind.Relative), null, null).Returns(userResponse);
Expand Down

0 comments on commit acf6a88

Please sign in to comment.