Implemented methods for creating an authorization without having to specify an app clientid/clientsecret.

These methods will ONLY work with username/password Basic Auth.

Added a helper method to return a GitHub client using basic auth credentials as if you have both password and oauth token environment variables, you get credentials based on the oauth token.
This commit is contained in:
Henrik Andersson
2015-12-11 00:16:36 +10:00
parent 2c2ba0ce6d
commit 2152ba4d14
6 changed files with 254 additions and 0 deletions
@@ -7,6 +7,40 @@ namespace Octokit.Tests.Integration.Clients
{
public class AuthorizationClientTests
{
[IntegrationTest]
public async Task CanCreatePersonalToken()
{
var github = Helper.GetBasicAuthClient();
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new string[] { "user" });
var created = await github.Authorization.Create(newAuthorization);
Assert.False(String.IsNullOrWhiteSpace(created.Token));
Assert.False(String.IsNullOrWhiteSpace(created.TokenLastEight));
Assert.False(String.IsNullOrWhiteSpace(created.HashedToken));
var get = await github.Authorization.Get(created.Id);
Assert.Equal(created.Id, get.Id);
Assert.Equal(created.Note, get.Note);
}
[IntegrationTest]
public async Task CannotCreatePersonalTokenWhenUsingOauthTokenCredentials()
{
var github = Helper.GetAuthenticatedClient();
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new string[] { "user" });
var error = Assert.ThrowsAsync<ForbiddenException>(() => github.Authorization.Create(newAuthorization));
Assert.True(error.Result.Message.Contains("username and password Basic Auth"));
}
[ApplicationTest]
public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
{