mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 11:24:44 +00:00
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:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user