From aa425452a902e1d5834f2ffafbad6a395948f053 Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Sun, 3 Nov 2024 07:45:33 +0300 Subject: [PATCH 1/4] set cond for validate password, fix swagger --- src/Argon.Api/Controllers/MetadataController.cs | 3 +-- src/Argon.Api/Grains/UserManager.cs | 2 +- src/Argon.Api/Properties/launchSettings.json | 12 +----------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Argon.Api/Controllers/MetadataController.cs b/src/Argon.Api/Controllers/MetadataController.cs index 12822c14..b05ae025 100644 --- a/src/Argon.Api/Controllers/MetadataController.cs +++ b/src/Argon.Api/Controllers/MetadataController.cs @@ -3,10 +3,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -[ApiController] public class MetadataController : ControllerBase { - [Route("/cfg.json")] + [HttpGet("/cfg.json")] [AllowAnonymous] public ValueTask GetHead() => new(new HeadRoutingConfig( diff --git a/src/Argon.Api/Grains/UserManager.cs b/src/Argon.Api/Grains/UserManager.cs index 0ec76647..caa481cc 100644 --- a/src/Argon.Api/Grains/UserManager.cs +++ b/src/Argon.Api/Grains/UserManager.cs @@ -21,7 +21,7 @@ public async Task Create(string password) { var username = this.GetPrimaryKeyString(); await EnsureUnique(); - await managerService.Validate(username, password); + managerService.Validate(username, password); userStore.State.Id = Guid.NewGuid(); userStore.State.Username = username; diff --git a/src/Argon.Api/Properties/launchSettings.json b/src/Argon.Api/Properties/launchSettings.json index 8f8432fd..306c4327 100644 --- a/src/Argon.Api/Properties/launchSettings.json +++ b/src/Argon.Api/Properties/launchSettings.json @@ -14,17 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": false, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5100", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": false, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7206;http://localhost:5100", + "applicationUrl": "https://localhost:5100", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } From 49ed193a3302992530f5468e873e67412b1d3feb Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Sun, 3 Nov 2024 12:37:31 +0300 Subject: [PATCH 2/4] fix --- src/Argon.Contracts/IUserAuthorization.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Argon.Contracts/IUserAuthorization.cs b/src/Argon.Contracts/IUserAuthorization.cs index 0404cf4d..d3efcc4c 100644 --- a/src/Argon.Contracts/IUserAuthorization.cs +++ b/src/Argon.Contracts/IUserAuthorization.cs @@ -27,7 +27,10 @@ public sealed partial record AuthorizeRequest( [property: Key(2)] string machineKey); -public sealed record AuthorizeResponse( +[DataContract] +[MemoryPackable(GenerateType.VersionTolerant)] +[MessagePackObject] +public sealed partial record AuthorizeResponse( [property: DataMember(Order = 0)] [property: MemoryPackOrder(0)] [property: Key(0)] From bb2079ba3664517b2fcf208a6999c9bf4a69cf95 Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Sun, 3 Nov 2024 12:47:35 +0300 Subject: [PATCH 3/4] fix --- src/Argon.Api/Services/UserManagerService.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Argon.Api/Services/UserManagerService.cs b/src/Argon.Api/Services/UserManagerService.cs index adff1efc..bb21da26 100644 --- a/src/Argon.Api/Services/UserManagerService.cs +++ b/src/Argon.Api/Services/UserManagerService.cs @@ -1,5 +1,6 @@ namespace Argon.Api.Services; +using System.Diagnostics; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; @@ -42,14 +43,15 @@ public Task GenerateJwt(string username, Guid id) return Task.FromResult(jwtToken); } - public async Task Validate(string username, string password) + [Conditional("RELEASE")] + public void Validate(string username, string password) { - await ValidateLength(username, nameof(username), 3, 50); - await ValidateLength(password, nameof(password), 8, 32); - await ValidatePasswordStrength(password); + ValidateLength(username, nameof(username), 3, 50); + ValidateLength(password, nameof(password), 8, 32); + ValidatePasswordStrength(password); } - private Task ValidatePasswordStrength(string password) + private void ValidatePasswordStrength(string password) { if (!password.Any(char.IsDigit)) throw new Exception( @@ -62,15 +64,11 @@ private Task ValidatePasswordStrength(string password) if (!password.Any(char.IsLower)) throw new Exception( "Password must contain at least one lowercase letter"); // TODO: Come up with application specific errors - - return Task.CompletedTask; } - private Task ValidateLength(string str, string obj, int min, int max) + private void ValidateLength(string str, string obj, int min, int max) { if (str.Length < min || str.Length > max) throw new Exception($"{obj}: Invalid length"); // TODO: Come up with application specific errors - - return Task.CompletedTask; } } \ No newline at end of file From 81a8e855fd4a9fa7df4878d5d6e910859276386a Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Sun, 3 Nov 2024 12:47:56 +0300 Subject: [PATCH 4/4] fix missed ApiController --- src/Argon.Api/Controllers/MetadataController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Argon.Api/Controllers/MetadataController.cs b/src/Argon.Api/Controllers/MetadataController.cs index b05ae025..a209a852 100644 --- a/src/Argon.Api/Controllers/MetadataController.cs +++ b/src/Argon.Api/Controllers/MetadataController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +[ApiController] public class MetadataController : ControllerBase { [HttpGet("/cfg.json")]