Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit aa0b325

Browse files
committed
#243. Generate a one-time password for new users (invite link).
1 parent f6a3491 commit aa0b325

78 files changed

Lines changed: 2431 additions & 253 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ LICENSE
2525
README.md
2626
**/*.db
2727
**/*.db-shm
28-
**/*.db-wal
28+
**/*.db-wal
29+
**/dist

Pyro.Api/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageVersion Include="JWT" Version="10.1.1" />
1212
<PackageVersion Include="JWT.Extensions.AspNetCore" Version="10.1.1" />
1313
<PackageVersion Include="LibGit2Sharp" Version="0.30.0" />
14+
<PackageVersion Include="MailKit" Version="4.8.0" />
1415
<PackageVersion Include="MediatR" Version="12.4.1" />
1516
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="8.0.10" />
1617
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="8.0.10" />

Pyro.Api/Pyro.ApiTests/Clients/BaseClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public async Task Login(string username, string password)
192192
}
193193

194194
public Task Login()
195-
=> Login("pyro", "pyro");
195+
=> Login("pyro@localhost.local", "pyro");
196196

197197
public async Task Logout()
198198
{

Pyro.Api/Pyro.ApiTests/Tests/LockUserTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ public async Task SetUp()
2424
identityClient = pyroClient.Share<IdentityClient>();
2525
await pyroClient.Login();
2626

27-
login = faker.Random.Hash(32);
27+
login = faker.Internet.Email();
2828
password = faker.Random.Hash();
2929

30-
var createUserRequest = new CreateUserRequest(login, password, ["User"]);
30+
// TODO: password/activate
31+
var createUserRequest = new CreateUserRequest(login, ["User"]);
3132
var user = await identityClient.CreateUser(createUserRequest);
3233
Assert.That(user, Is.Not.Null);
3334
}

Pyro.Api/Pyro.ApiTests/Tests/ProfileTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
22
// Licensed under the GPL-3.0 license. See LICENSE file in the project root for full license information.
33

4+
using Bogus;
45
using Pyro.ApiTests.Clients;
56
using Pyro.Contracts.Requests;
67
using Pyro.Contracts.Requests.Identity;
@@ -9,12 +10,14 @@ namespace Pyro.ApiTests.Tests;
910

1011
public class ProfileTests
1112
{
13+
private Faker faker;
1214
private PyroClient client;
1315
private IdentityClient identityClient;
1416

1517
[OneTimeSetUp]
1618
public async Task SetUp()
1719
{
20+
faker = new Faker();
1821
client = new PyroClient(Api.BaseAddress);
1922
identityClient = client.Share<IdentityClient>();
2023
await client.Login();
@@ -49,14 +52,16 @@ public async Task UpdateGetProfile()
4952
[Test]
5053
public async Task GetProfileOfNewlyCreatedUser()
5154
{
55+
// TODO: password/activate
5256
var request = new CreateUserRequest(
53-
Guid.NewGuid().ToString().Replace("-", string.Empty),
54-
Guid.NewGuid().ToString(),
57+
faker.Internet.Email(),
5558
["Admin"]);
5659
await identityClient.CreateUser(request);
5760

5861
using var newUserClient = new PyroClient(Api.BaseAddress);
59-
await newUserClient.Login(request.Login, request.Password);
62+
63+
// TODO: password/activate
64+
await newUserClient.Login(request.Login, string.Empty);
6065

6166
var profile = await newUserClient.GetProfile();
6267

Pyro.Api/Pyro.ApiTests/Tests/UserTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
22
// Licensed under the GPL-3.0 license. See LICENSE file in the project root for full license information.
33

4+
using Bogus;
45
using Pyro.ApiTests.Clients;
56
using Pyro.Contracts.Requests.Identity;
67

78
namespace Pyro.ApiTests.Tests;
89

910
public class UserTests
1011
{
12+
private Faker faker;
1113
private IdentityClient client;
1214

1315
[OneTimeSetUp]
1416
public async Task SetUp()
1517
{
18+
faker = new Faker();
1619
client = new IdentityClient(Api.BaseAddress);
1720
await client.Login();
1821
}
@@ -35,7 +38,7 @@ public async Task GetUsers()
3538
[Test]
3639
public async Task GetUserByLogin()
3740
{
38-
const string login = "pyro";
41+
const string login = "pyro@localhost.local";
3942
var result = await client.GetUser(login);
4043

4144
Assert.That(result, Is.Not.Null);
@@ -54,9 +57,9 @@ public async Task GetMissingUserByLogin()
5457
[Test]
5558
public async Task CreateGetUpdateUser()
5659
{
60+
// TODO: password/activate
5761
var createRequest = new CreateUserRequest(
58-
Guid.NewGuid().ToString().Replace("-", string.Empty),
59-
"password",
62+
faker.Internet.Email(),
6063
["Admin"]);
6164
await client.CreateUser(createRequest);
6265

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
2+
// Licensed under the GPL-3.0 license. See LICENSE file in the project root for full license information.
3+
4+
namespace Pyro.Contracts.Requests.Identity;
5+
6+
public record ActivateUserRequest(string Token, string Password);

Pyro.Api/Pyro.Contracts/Requests/Identity/CreateUserRequest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ namespace Pyro.Contracts.Requests.Identity;
55

66
public record CreateUserRequest(
77
string Login,
8-
string Password,
98
IEnumerable<string> Roles);

Pyro.Api/Pyro.Contracts/Responses/UserProfileResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
namespace Pyro.Contracts.Responses;
55

6-
public record UserProfileResponse(string Name, string? Email, string? Status);
6+
public record UserProfileResponse(string Name, string? Status);

Pyro.Api/Pyro.Domain.Identity.UnitTests/Commands/CreateUserHandlerTests.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CreateUserHandlerTests
1313
[Test]
1414
public async Task CreateValidUser()
1515
{
16-
var command = new CreateUser("test", "password", ["admin"]);
16+
var command = new CreateUser("test", ["admin"]);
1717

1818
var repository = Substitute.For<IUserRepository>();
1919
repository
@@ -22,7 +22,10 @@ public async Task CreateValidUser()
2222

2323
var passwordService = Substitute.For<IPasswordService>();
2424
passwordService
25-
.GeneratePasswordHash(command.Password)
25+
.GeneratePassword()
26+
.Returns(string.Empty);
27+
passwordService
28+
.GeneratePasswordHash(string.Empty)
2629
.Returns((new byte[64], new byte[16]));
2730

2831
var handler = new CreateUserHandler(repository, passwordService);
@@ -34,13 +37,14 @@ public async Task CreateValidUser()
3437
Assert.That(user.Login, Is.EqualTo(command.Login));
3538
Assert.That(user.Roles, Has.Count.EqualTo(1));
3639
Assert.That(user.Roles[0].Name, Is.EqualTo("admin"));
40+
Assert.That(user.IsLocked, Is.True);
3741
});
3842
}
3943

4044
[Test]
4145
public void CreateUserWithInvalidRole()
4246
{
43-
var command = new CreateUser("test", "password", ["user"]);
47+
var command = new CreateUser("test", ["user"]);
4448

4549
var repository = Substitute.For<IUserRepository>();
4650
repository
@@ -49,7 +53,10 @@ public void CreateUserWithInvalidRole()
4953

5054
var passwordService = Substitute.For<IPasswordService>();
5155
passwordService
52-
.GeneratePasswordHash(command.Password)
56+
.GeneratePassword()
57+
.Returns(string.Empty);
58+
passwordService
59+
.GeneratePasswordHash(string.Empty)
5360
.Returns((new byte[64], new byte[16]));
5461

5562
var handler = new CreateUserHandler(repository, passwordService);

0 commit comments

Comments
 (0)