aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests/TokenTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-30 21:15:18 +0800
committercrupest <crupest@outlook.com>2020-01-30 21:15:18 +0800
commita1a2eede6942aef7d8c20f9e7fb25f53b2b63d86 (patch)
treeaa4df76441a44448dad3ee5e7b0d26bf80383259 /Timeline.Tests/IntegratedTests/TokenTest.cs
parent52acf41e331ddbd66befed4692c804b754ba7d5c (diff)
downloadtimeline-a1a2eede6942aef7d8c20f9e7fb25f53b2b63d86.tar.gz
timeline-a1a2eede6942aef7d8c20f9e7fb25f53b2b63d86.tar.bz2
timeline-a1a2eede6942aef7d8c20f9e7fb25f53b2b63d86.zip
...
Diffstat (limited to 'Timeline.Tests/IntegratedTests/TokenTest.cs')
-rw-r--r--Timeline.Tests/IntegratedTests/TokenTest.cs36
1 files changed, 18 insertions, 18 deletions
diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs
index 8ee19999..ec7514ff 100644
--- a/Timeline.Tests/IntegratedTests/TokenTest.cs
+++ b/Timeline.Tests/IntegratedTests/TokenTest.cs
@@ -41,7 +41,7 @@ namespace Timeline.Tests.IntegratedTests
[MemberData(nameof(CreateToken_InvalidModel_Data))]
public async Task CreateToken_InvalidModel(string username, string password, int expire)
{
- using var client = await CreateClientWithNoAuth();
+ using var client = await CreateDefaultClient();
(await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest
{
Username = username,
@@ -53,14 +53,14 @@ namespace Timeline.Tests.IntegratedTests
public static IEnumerable<object[]> CreateToken_UserCredential_Data()
{
yield return new[] { "usernotexist", "p" };
- yield return new[] { MockUser.Ordinary.Username, "???" };
+ yield return new[] { "user1", "???" };
}
[Theory]
[MemberData(nameof(CreateToken_UserCredential_Data))]
public async void CreateToken_UserCredential(string username, string password)
{
- using var client = await CreateClientWithNoAuth();
+ using var client = await CreateDefaultClient();
var response = await client.PostAsJsonAsync(CreateTokenUrl,
new CreateTokenRequest { Username = username, Password = password });
response.Should().HaveStatusCode(400)
@@ -71,19 +71,19 @@ namespace Timeline.Tests.IntegratedTests
[Fact]
public async Task CreateToken_Success()
{
- using var client = await CreateClientWithNoAuth();
+ using var client = await CreateDefaultClient();
var response = await client.PostAsJsonAsync(CreateTokenUrl,
- new CreateTokenRequest { Username = MockUser.Ordinary.Username, Password = MockUser.Ordinary.Password });
+ new CreateTokenRequest { Username = "user1", Password = "user1pw" });
var body = response.Should().HaveStatusCode(200)
.And.HaveJsonBody<CreateTokenResponse>().Which;
body.Token.Should().NotBeNullOrWhiteSpace();
- body.User.Should().BeEquivalentTo(MockUser.Ordinary.Info);
+ body.User.Should().BeEquivalentTo(UserInfoForAdminList[1]);
}
[Fact]
public async Task VerifyToken_InvalidModel()
{
- using var client = await CreateClientWithNoAuth();
+ using var client = await CreateDefaultClient();
(await client.PostAsJsonAsync(VerifyTokenUrl,
new VerifyTokenRequest { Token = null })).Should().BeInvalidModel();
}
@@ -91,7 +91,7 @@ namespace Timeline.Tests.IntegratedTests
[Fact]
public async Task VerifyToken_BadFormat()
{
- using var client = await CreateClientWithNoAuth();
+ using var client = await CreateDefaultClient();
var response = await client.PostAsJsonAsync(VerifyTokenUrl,
new VerifyTokenRequest { Token = "bad token hahaha" });
response.Should().HaveStatusCode(400)
@@ -102,14 +102,14 @@ namespace Timeline.Tests.IntegratedTests
[Fact]
public async Task VerifyToken_OldVersion()
{
- using var client = await CreateClientWithNoAuth();
- var token = (await CreateUserTokenAsync(client, MockUser.Ordinary.Username, MockUser.Ordinary.Password)).Token;
+ using var client = await CreateDefaultClient();
+ var token = (await CreateUserTokenAsync(client, "user1", "user1pw")).Token;
- using (var scope = Factory.Server.Host.Services.CreateScope()) // UserService is scoped.
+ using (var scope = Factory.Services.CreateScope()) // UserService is scoped.
{
// create a user for test
var userService = scope.ServiceProvider.GetRequiredService<IUserService>();
- await userService.PatchUser(MockUser.Ordinary.Username, null, null);
+ await userService.ModifyUser("user1", new User { Password = "user1pw" });
}
(await client.PostAsJsonAsync(VerifyTokenUrl,
@@ -122,13 +122,13 @@ namespace Timeline.Tests.IntegratedTests
[Fact]
public async Task VerifyToken_UserNotExist()
{
- using var client = await CreateClientWithNoAuth();
- var token = (await CreateUserTokenAsync(client, MockUser.Ordinary.Username, MockUser.Ordinary.Password)).Token;
+ using var client = await CreateDefaultClient();
+ var token = (await CreateUserTokenAsync(client, "user1", "user1pw")).Token;
using (var scope = Factory.Server.Host.Services.CreateScope()) // UserService is scoped.
{
var userService = scope.ServiceProvider.GetRequiredService<IUserService>();
- await userService.DeleteUser(MockUser.Ordinary.Username);
+ await userService.DeleteUser("user1");
}
(await client.PostAsJsonAsync(VerifyTokenUrl,
@@ -159,13 +159,13 @@ namespace Timeline.Tests.IntegratedTests
[Fact]
public async Task VerifyToken_Success()
{
- using var client = await CreateClientWithNoAuth();
- var createTokenResult = await CreateUserTokenAsync(client, MockUser.Ordinary.Username, MockUser.Ordinary.Password);
+ using var client = await CreateDefaultClient();
+ var createTokenResult = await CreateUserTokenAsync(client, "user1", "user1pw");
var response = await client.PostAsJsonAsync(VerifyTokenUrl,
new VerifyTokenRequest { Token = createTokenResult.Token });
response.Should().HaveStatusCode(200)
.And.HaveJsonBody<VerifyTokenResponse>()
- .Which.User.Should().BeEquivalentTo(MockUser.Ordinary.Info);
+ .Which.User.Should().BeEquivalentTo(UserInfoForAdminList[1]);
}
}
}