diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-04 21:35:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-04 21:35:04 +0800 |
commit | 52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24 (patch) | |
tree | d1c9c7b51353b67b47bb4cd89aa82754ef0a1234 /Timeline.Tests/Helpers/Authentication | |
parent | c07297373df08bd605f5bec96020192bb6dec151 (diff) | |
parent | d1ebb882e8484c80eca86cac80602fb4c1401834 (diff) | |
download | timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.tar.gz timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.tar.bz2 timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.zip |
Merge pull request #34 from crupest/token-time
Set token expired time and write unit tests.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication')
-rw-r--r-- | Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs index f4e2e45a..27362ac3 100644 --- a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs +++ b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; -using System; using System.Net.Http; using System.Threading.Tasks; using Timeline.Entities.Http; @@ -11,9 +10,9 @@ namespace Timeline.Tests.Helpers.Authentication { private const string CreateTokenUrl = "/token/create"; - public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password) + public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, double? expireOffset = null) { - var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password }); + var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password, ExpireOffset = expireOffset }); var result = JsonConvert.DeserializeObject<CreateTokenResponse>(await response.Content.ReadAsStringAsync()); return result; } @@ -25,16 +24,5 @@ namespace Timeline.Tests.Helpers.Authentication client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); return client; } - - public static async Task<HttpResponseMessage> SendWithAuthenticationAsync(this HttpClient client, string token, string path, Action<HttpRequestMessage> requestBuilder = null) - { - var request = new HttpRequestMessage - { - RequestUri = new Uri(client.BaseAddress, path), - }; - request.Headers.Add("Authorization", "Bearer " + token); - requestBuilder?.Invoke(request); - return await client.SendAsync(request); - } } } |