-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add password settings management (#15)
- Loading branch information
1 parent
9d81a36
commit f77ec86
Showing
9 changed files
with
216 additions
and
10 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Descope.Test/IntegrationTests/Management/PasswordSettingsTests.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,43 @@ | ||
using Xunit; | ||
|
||
namespace Descope.Test.Integration | ||
{ | ||
public class PasswordSettingsTests | ||
{ | ||
private readonly DescopeClient _descopeClient = IntegrationTestSetup.InitDescopeClient(); | ||
|
||
[Fact] | ||
public async Task PasswordSettings_GetAndUpdate() | ||
{ | ||
string? tenantId = null; | ||
try | ||
{ | ||
// Create a tenant | ||
tenantId = await _descopeClient.Management.Tenant.Create(new TenantOptions(Guid.NewGuid().ToString())); | ||
|
||
// update project level | ||
var settings = await _descopeClient.Management.Password.GetSettings(); | ||
settings.MinLength = 6; | ||
await _descopeClient.Management.Password.ConfigureSettings(settings); | ||
|
||
// update tenant level | ||
settings.MinLength = 7; | ||
await _descopeClient.Management.Password.ConfigureSettings(settings, tenantId); | ||
|
||
// make sure changes don't clash | ||
var projectSettings = await _descopeClient.Management.Password.GetSettings(); | ||
Assert.Equal(6, projectSettings.MinLength); | ||
var tenantSettings = await _descopeClient.Management.Password.GetSettings(tenantId); | ||
Assert.Equal(7, tenantSettings.MinLength); | ||
} | ||
finally | ||
{ | ||
if (!string.IsNullOrEmpty(tenantId)) | ||
{ | ||
try { await _descopeClient.Management.Tenant.Delete(tenantId); } | ||
catch { } | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Descope.Internal.Management | ||
{ | ||
internal class Password : IPasswordSettings | ||
{ | ||
private readonly IHttpClient _httpClient; | ||
private readonly string _managementKey; | ||
|
||
internal Password(IHttpClient httpClient, string managementKey) | ||
{ | ||
_httpClient = httpClient; | ||
_managementKey = managementKey; | ||
} | ||
|
||
public async Task<PasswordSettings> GetSettings(string? tenantId = null) | ||
{ | ||
return await _httpClient.Get<PasswordSettings>(Routes.PasswordSettings, _managementKey, queryParams: new Dictionary<string, string?> { { "tenantId", tenantId } }); | ||
} | ||
|
||
public async Task ConfigureSettings(PasswordSettings settings, string? tenantId = null) | ||
{ | ||
var body = new WrappedSettings | ||
{ | ||
TenantId = tenantId, | ||
Enabled = settings.Enabled, | ||
MinLength = settings.MinLength, | ||
Lowercase = settings.Lowercase, | ||
Uppercase = settings.Uppercase, | ||
Number = settings.Number, | ||
NonAlphanumeric = settings.NonAlphanumeric, | ||
Expiration = settings.Expiration, | ||
ExpirationWeeks = settings.ExpirationWeeks, | ||
Reuse = settings.Reuse, | ||
ReuseAmount = settings.ReuseAmount, | ||
Lock = settings.Lock, | ||
LockAttempts = settings.LockAttempts, | ||
}; | ||
await _httpClient.Post<object>(Routes.PasswordSettings, _managementKey, body); | ||
} | ||
|
||
} | ||
|
||
internal class WrappedSettings : PasswordSettings | ||
{ | ||
[JsonPropertyName("tenantId")] | ||
public string? TenantId { get; set; } | ||
} | ||
|
||
} |
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