-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature(oidc、sdk auth): add OIDC unit test、sdk auth ssoClient loginSe…
…rvice add LoginByLdapAsync method (#478) * feat:add oidc unit test * feat:oidc add grantType LDAP * feat:sdk auth thirdPartyIdpService add GetLdapOptions method * feat:sdk auth ssoClient loginService add LoginByLdapAsync method * refactor code
- Loading branch information
1 parent
d05865c
commit 079a0a5
Showing
17 changed files
with
399 additions
and
6 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
34 changes: 34 additions & 0 deletions
34
...cks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LdapOptionsModel.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,34 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; | ||
|
||
public class LdapOptionsModel | ||
{ | ||
public string ServerAddress { get; set; } | ||
|
||
public int ServerPort { get; set; } | ||
|
||
public int ServerPortSsl { get; set; } | ||
|
||
public string BaseDn { get; set; } | ||
|
||
public string UserSearchBaseDn { get; set; } | ||
|
||
public string GroupSearchBaseDn { get; set; } | ||
|
||
public string RootUserDn { get; set; } | ||
|
||
public string RootUserPassword { get; set; } | ||
|
||
public LdapOptionsModel(string serverAddress, int serverPort, string baseDn, string userSearchBaseDn, string groupSearchBaseDn, string rootUserDn, string rootUserPassword) | ||
{ | ||
ServerAddress = serverAddress; | ||
ServerPort = serverPort; | ||
BaseDn = baseDn; | ||
UserSearchBaseDn = userSearchBaseDn; | ||
GroupSearchBaseDn = groupSearchBaseDn; | ||
RootUserDn = rootUserDn; | ||
RootUserPassword = rootUserPassword; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...cks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LoginByLdapModel.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,17 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; | ||
|
||
public class LoginByLdapModel | ||
{ | ||
public string ClientId { get; set; } = ""; | ||
|
||
public string ClientSecret { get; set; } = ""; | ||
|
||
public List<string> Scope { get; set; } = new() { "openid", "profile" }; | ||
|
||
public string UserName { get; set; } | ||
|
||
public string Scheme { get; set; } = "Ldap"; | ||
} |
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
...nnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiResourceCacheTest.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 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; | ||
|
||
[TestClass] | ||
public class ApiResourceCacheTest | ||
{ | ||
IApiResourceCache _cache; | ||
ApiResource _apiResource; | ||
|
||
[TestInitialize] | ||
public void Initialized() | ||
{ | ||
var options = new RedisConfigurationOptions() | ||
{ | ||
Servers = new List<RedisServerOptions> | ||
{ | ||
new RedisServerOptions | ||
{ | ||
Host = "127.0.0.1", | ||
Port = 6379 | ||
} | ||
} | ||
}; | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddOidcCache(options); | ||
_cache = serviceCollection.BuildServiceProvider().GetRequiredService<IApiResourceCache>(); | ||
_apiResource = new ApiResource("ApiResourceCache", "ApiResourceCache", "ApiResourceCache", "", default, default, default, default); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetAsync() | ||
{ | ||
await _cache.SetAsync(_apiResource); | ||
var apiResources = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiResources.Any(item => item.Name == _apiResource.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetRangeAsync() | ||
{ | ||
var input = new[] { _apiResource }; | ||
await _cache.SetRangeAsync(input); | ||
var apiResources = await _cache.GetListAsync(); | ||
Assert.IsTrue(input.All(item => apiResources.Any(item2 => item2.Name == item.Name))); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestGetListAsync() | ||
{ | ||
await _cache.SetAsync(_apiResource); | ||
var apiResources = await _cache.GetListAsync(new[] { _apiResource.Name }); | ||
Assert.IsTrue(apiResources.All(item => item.Name == _apiResource.Name)); | ||
apiResources = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiResources.Any(item => item.Name == _apiResource.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestRemoveAsync() | ||
{ | ||
await _cache.SetAsync(_apiResource); | ||
await _cache.RemoveAsync(_apiResource); | ||
var apiResources = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiResources.All(item => item.Name != _apiResource.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestResetAsync() | ||
{ | ||
var input = new[] { _apiResource }; | ||
await _cache.ResetAsync(input); | ||
var apiResources = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiResources.Select(item => item.Name).Except(input.Select(item => item.Name)).Any() is false); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...dConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiScopeCacheTest.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 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; | ||
|
||
[TestClass] | ||
public class ApiScopeCacheTest | ||
{ | ||
IApiScopeCache _cache; | ||
ApiScope _apiScope; | ||
|
||
[TestInitialize] | ||
public void Initialized() | ||
{ | ||
var options = new RedisConfigurationOptions() | ||
{ | ||
Servers = new List<RedisServerOptions> | ||
{ | ||
new RedisServerOptions | ||
{ | ||
Host = "127.0.0.1", | ||
Port = 6379 | ||
} | ||
} | ||
}; | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddOidcCache(options); | ||
_cache = serviceCollection.BuildServiceProvider().GetRequiredService<IApiScopeCache>(); | ||
_apiScope = new ApiScope("ApiScope"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetAsync() | ||
{ | ||
await _cache.SetAsync(_apiScope); | ||
var apiScopes = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiScopes.Any(item => item.Name == _apiScope.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetRangeAsync() | ||
{ | ||
var input = new[] { _apiScope }; | ||
await _cache.SetRangeAsync(input); | ||
var apiScopes = await _cache.GetListAsync(); | ||
Assert.IsTrue(input.All(item => apiScopes.Any(item2 => item2.Name == item.Name))); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestGetListAsync() | ||
{ | ||
await _cache.SetAsync(_apiScope); | ||
var apiScopes = await _cache.GetListAsync(new[] { _apiScope.Name }); | ||
Assert.IsTrue(apiScopes.All(item => item.Name == _apiScope.Name)); | ||
apiScopes = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiScopes.Any(item => item.Name == _apiScope.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestRemoveAsync() | ||
{ | ||
await _cache.SetAsync(_apiScope); | ||
await _cache.RemoveAsync(_apiScope); | ||
var apiScopes = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiScopes.All(item => item.Name != _apiScope.Name)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestResetAsync() | ||
{ | ||
var input = new[] { _apiScope }; | ||
await _cache.ResetAsync(input); | ||
var apiScopes = await _cache.GetListAsync(); | ||
Assert.IsTrue(apiScopes.Select(item => item.Name).Except(input.Select(item => item.Name)).Any() is false); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...nIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ClientCacheTest.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 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; | ||
|
||
[TestClass] | ||
public class ClientCacheTest | ||
{ | ||
IClientCache _cache; | ||
Client _client; | ||
|
||
[TestInitialize] | ||
public void Initialized() | ||
{ | ||
var options = new RedisConfigurationOptions() | ||
{ | ||
Servers = new List<RedisServerOptions> | ||
{ | ||
new RedisServerOptions | ||
{ | ||
Host = "127.0.0.1", | ||
Port = 6379 | ||
} | ||
} | ||
}; | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddOidcCache(options); | ||
_cache = serviceCollection.BuildServiceProvider().GetRequiredService<IClientCache>(); | ||
_client = new Client(ClientTypes.Web, "Client", "Client"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetAsync() | ||
{ | ||
await _cache.SetAsync(_client); | ||
var clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(clients.Any(item => item.ClientName == _client.ClientName)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestSetRangeAsync() | ||
{ | ||
var input = new[] { _client }; | ||
await _cache.SetRangeAsync(input); | ||
var clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(input.All(item => clients.Any(item2 => item2.ClientName == item.ClientName))); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestGetListAsync() | ||
{ | ||
await _cache.SetAsync(_client); | ||
var clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(clients.All(item => item.ClientName == _client.ClientName)); | ||
clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(clients.Any(item => item.ClientName == _client.ClientName)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestRemoveAsync() | ||
{ | ||
await _cache.SetAsync(_client); | ||
await _cache.RemoveAsync(_client); | ||
var clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(clients.All(item => item.ClientName != _client.ClientName)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestResetAsync() | ||
{ | ||
var input = new[] { _client }; | ||
await _cache.ResetAsync(input); | ||
var clients = await _cache.GetListAsync(new[] { _client.ClientName }); | ||
Assert.IsTrue(clients.Select(item => item.ClientName).Except(input.Select(item => item.ClientName)).Any() is false); | ||
} | ||
} |
Oops, something went wrong.