aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-04-15 22:25:46 +0800
committerGitHub <noreply@github.com>2019-04-15 22:25:46 +0800
commit1cb92b8f2a98005b793c00e0191903c0792d540a (patch)
tree510628773fefe110de4d80eb268d5c5c3e17d998
parent56c51bdf844ce1e3642dcdc4099187e7e57008c7 (diff)
parent5e3e007c28fac571e5bcfa57f371b640342defb7 (diff)
downloadtimeline-1cb92b8f2a98005b793c00e0191903c0792d540a.tar.gz
timeline-1cb92b8f2a98005b793c00e0191903c0792d540a.tar.bz2
timeline-1cb92b8f2a98005b793c00e0191903c0792d540a.zip
Merge pull request #21 from crupest/verifytoken
Rename ValidateToken to VerifyToken.
-rw-r--r--Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs4
-rw-r--r--Timeline.Tests/JwtTokenUnitTest.cs16
-rw-r--r--Timeline/Controllers/UserController.cs6
-rw-r--r--Timeline/Entities/User.cs4
4 files changed, 12 insertions, 18 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
index 1949df9b..c0051c53 100644
--- a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
+++ b/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
@@ -15,11 +15,9 @@ namespace Timeline.Tests.Helpers.Authentication
public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, bool assertSuccess = true)
{
var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password });
-
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var result = JsonConvert.DeserializeObject<CreateTokenResponse>(await response.Content.ReadAsStringAsync());
-
if (assertSuccess)
Assert.True(result.Success);
@@ -33,9 +31,7 @@ namespace Timeline.Tests.Helpers.Authentication
RequestUri = new Uri(client.BaseAddress, path),
};
request.Headers.Add("Authorization", "Bearer " + token);
-
requestBuilder?.Invoke(request);
-
return await client.SendAsync(request);
}
}
diff --git a/Timeline.Tests/JwtTokenUnitTest.cs b/Timeline.Tests/JwtTokenUnitTest.cs
index 3c03dfc2..fa9c7628 100644
--- a/Timeline.Tests/JwtTokenUnitTest.cs
+++ b/Timeline.Tests/JwtTokenUnitTest.cs
@@ -13,7 +13,7 @@ namespace Timeline.Tests
public class JwtTokenUnitTest : IClassFixture<WebApplicationFactory<Startup>>
{
private const string CreateTokenUrl = "User/CreateToken";
- private const string ValidateTokenUrl = "User/ValidateToken";
+ private const string VerifyTokenUrl = "User/VerifyToken";
private readonly WebApplicationFactory<Startup> _factory;
@@ -51,32 +51,30 @@ namespace Timeline.Tests
}
[Fact]
- public async void ValidateTokenTest_BadToken()
+ public async void VerifyTokenTest_BadToken()
{
using (var client = _factory.CreateDefaultClient())
{
- var response = await client.PostAsJsonAsync(ValidateTokenUrl, new TokenValidationRequest { Token = "bad token hahaha" });
-
+ var response = await client.PostAsJsonAsync(VerifyTokenUrl, new VerifyTokenRequest { Token = "bad token hahaha" });
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- var validationInfo = JsonConvert.DeserializeObject<TokenValidationResponse>(await response.Content.ReadAsStringAsync());
-
+ var validationInfo = JsonConvert.DeserializeObject<VerifyTokenResponse>(await response.Content.ReadAsStringAsync());
Assert.False(validationInfo.IsValid);
Assert.Null(validationInfo.UserInfo);
}
}
[Fact]
- public async void ValidateTokenTest_GoodToken()
+ public async void VerifyTokenTest_GoodToken()
{
using (var client = _factory.CreateDefaultClient())
{
var createTokenResult = await client.CreateUserTokenAsync("admin", "admin");
- var response = await client.PostAsJsonAsync(ValidateTokenUrl, new TokenValidationRequest { Token = createTokenResult.Token });
+ var response = await client.PostAsJsonAsync(VerifyTokenUrl, new VerifyTokenRequest { Token = createTokenResult.Token });
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- var result = JsonConvert.DeserializeObject<TokenValidationResponse>(await response.Content.ReadAsStringAsync());
+ var result = JsonConvert.DeserializeObject<VerifyTokenResponse>(await response.Content.ReadAsStringAsync());
Assert.True(result.IsValid);
Assert.NotNull(result.UserInfo);
Assert.Equal(createTokenResult.UserInfo.Username, result.UserInfo.Username);
diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs
index 3b4e7b4f..147724c1 100644
--- a/Timeline/Controllers/UserController.cs
+++ b/Timeline/Controllers/UserController.cs
@@ -53,19 +53,19 @@ namespace Timeline.Controllers
[HttpPost("[action]")]
[AllowAnonymous]
- public async Task<ActionResult<TokenValidationResponse>> ValidateToken([FromBody] TokenValidationRequest request)
+ public async Task<ActionResult<VerifyTokenResponse>> VerifyToken([FromBody] VerifyTokenRequest request)
{
var result = await _userService.VerifyToken(request.Token);
if (result == null)
{
- return Ok(new TokenValidationResponse
+ return Ok(new VerifyTokenResponse
{
IsValid = false,
});
}
- return Ok(new TokenValidationResponse
+ return Ok(new VerifyTokenResponse
{
IsValid = true,
UserInfo = result
diff --git a/Timeline/Entities/User.cs b/Timeline/Entities/User.cs
index 1cb5a894..b5664bb0 100644
--- a/Timeline/Entities/User.cs
+++ b/Timeline/Entities/User.cs
@@ -13,12 +13,12 @@
public UserInfo UserInfo { get; set; }
}
- public class TokenValidationRequest
+ public class VerifyTokenRequest
{
public string Token { get; set; }
}
- public class TokenValidationResponse
+ public class VerifyTokenResponse
{
public bool IsValid { get; set; }
public UserInfo UserInfo { get; set; }