-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add S/R tests using JWT over basic auth
- Loading branch information
Showing
3 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Net.Http.Json; | ||
using LexBoxApi.Auth; | ||
using Shouldly; | ||
|
||
namespace Testing.Services; | ||
|
||
public class JwtHelper | ||
{ | ||
|
||
public static async Task<string> GetJwtForUser(SendReceiveAuth auth) | ||
{ | ||
var handler = new HttpClientHandler(); | ||
var client = new HttpClient(handler); | ||
var response = await client.PostAsJsonAsync( | ||
$"{TestingEnvironmentVariables.StandardHgBaseUrl}/api/login", | ||
new Dictionary<string, object> | ||
{ | ||
{ "password", auth.Password }, { "emailOrUsername", auth.Username }, { "preHashedPassword", false } | ||
}); | ||
response.EnsureSuccessStatusCode(); | ||
var cookieContainer = handler.CookieContainer; | ||
var authCookie = cookieContainer.GetAllCookies().FirstOrDefault(c => c.Name == AuthKernel.AuthCookieName); | ||
authCookie.ShouldNotBeNull(); | ||
var jwt = authCookie.Value; | ||
jwt.ShouldNotBeNullOrEmpty(); | ||
return jwt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters