-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add GetSigninUrl api and imporve userinfo api * feat: avoid Duplicate entry
- Loading branch information
Showing
11 changed files
with
136 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tests/Casdoor.Client.UnitTests/ApiClientTests/ClientTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Casdoor.Client.UnitTests.Fixtures; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Win32.SafeHandles; | ||
using Xunit.Abstractions; | ||
|
||
namespace Casdoor.Client.UnitTests.ApiClientTests; | ||
|
||
public class ClientTest : IClassFixture<ServicesFixture>, IClassFixture<ServicesFixtureWithoutSecret> | ||
{ | ||
private readonly ServicesFixture _servicesFixture; | ||
private readonly ServicesFixtureWithoutSecret _servicesFixtureWithoutSecret; | ||
private readonly ITestOutputHelper _testOutputHelper; | ||
|
||
public ClientTest(ServicesFixture servicesFixture, ServicesFixtureWithoutSecret servicesFixtureWithoutSecret, ITestOutputHelper testOutputHelper) | ||
{ | ||
_servicesFixture = servicesFixture; | ||
_servicesFixtureWithoutSecret = servicesFixtureWithoutSecret; | ||
_testOutputHelper = testOutputHelper; | ||
} | ||
|
||
[Fact] | ||
public async void TestClient() | ||
{ | ||
var tokenClient = _servicesFixture.ServiceProvider.GetService<ICasdoorClient>(); | ||
string name = "Token_" + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds().ToString(); | ||
string code = "Code_" + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds().ToString(); | ||
_testOutputHelper.WriteLine($"test with token name {name}"); | ||
string owner = "admin"; | ||
var verifier = "test"; | ||
|
||
var sha256Instance = SHA256.Create(); | ||
byte[] bytes = Encoding.Default.GetBytes(verifier); | ||
byte[] chanllengeCodeEncoded = sha256Instance.ComputeHash(bytes); | ||
string chanllengeCodeBase64Encoded = Convert.ToBase64String(chanllengeCodeEncoded).Replace("+", "-").Replace("/", "_").Replace("=", ""); | ||
|
||
CasdoorToken token = new CasdoorToken() | ||
{ | ||
Owner = owner, | ||
Name = name, | ||
CreatedTime = DateTime.Now.ToString(), | ||
Code = code, | ||
AccessToken = code + "123456", | ||
CodeChallenge = chanllengeCodeBase64Encoded, | ||
Application = "app-example", | ||
Organization = "casbin", | ||
User = "admin", | ||
CodeExpireIn = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds() + 19600 | ||
}; | ||
|
||
// Add the object | ||
Task<CasdoorResponse?> responseAsync = tokenClient.AddTokenAsync(token); | ||
CasdoorResponse? response = await responseAsync; | ||
_testOutputHelper.WriteLine($"{response.Status} {response.Msg}"); | ||
Assert.Equal(CasdoorConstants.DefaultCasdoorSuccessStatus, response.Status); | ||
|
||
var userClient = _servicesFixtureWithoutSecret.ServiceProvider.GetService<ICasdoorClient>(); | ||
|
||
if (userClient == null) | ||
{ | ||
Assert.NotNull(userClient); | ||
return; | ||
} | ||
|
||
var requestedToken = await userClient.RequestAuthorizationCodeTokenAsync(token.Code, "http://localhost:5000/callback", verifier); | ||
|
||
Assert.Equal(requestedToken.AccessToken, token.AccessToken); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters