-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test with auth in Docker is working
- Loading branch information
Showing
8 changed files
with
2,171 additions
and
2,199 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
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
87 changes: 87 additions & 0 deletions
87
tests/Ubik.Accounting.Api.Tests.Integration/Auth/AuthHelper.cs
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,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ubik.Accounting.Api.Tests.Integration.Auth | ||
{ | ||
internal static class AuthHelper | ||
{ | ||
internal async static Task<string> GetAccessTokenReadOnly() | ||
{ | ||
using var client = new HttpClient(); | ||
var request = new HttpRequestMessage(HttpMethod.Post, Environment.GetEnvironmentVariable("Keycloack__TokenUrl")); | ||
|
||
var collection = new List<KeyValuePair<string, string>> | ||
{ | ||
new("grant_type", "password"), | ||
new("client_id", "ubik_accounting_api"), | ||
new("username", "testro"), | ||
new("password", "test"), | ||
new("client_secret", "GQEyHjeBUThKta1eItucb5LFGj5Hduwd") | ||
}; | ||
|
||
var content = new FormUrlEncodedContent(collection); | ||
request.Content = content; | ||
|
||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var result = await response.Content.ReadFromJsonAsync<TokenObjFromKeycloack>(); | ||
|
||
return result!.AccessToken; | ||
} | ||
|
||
internal async static Task<string> GetAccessTokenReadWrite() | ||
{ | ||
using var client = new HttpClient(); | ||
var request = new HttpRequestMessage(HttpMethod.Post, Environment.GetEnvironmentVariable("Keycloack__TokenUrl")); | ||
|
||
var collection = new List<KeyValuePair<string, string>> | ||
{ | ||
new("grant_type", "password"), | ||
new("client_id", "ubik_accounting_api"), | ||
new("username", "testrw"), | ||
new("password", "test"), | ||
new("client_secret", "GQEyHjeBUThKta1eItucb5LFGj5Hduwd") | ||
}; | ||
|
||
var content = new FormUrlEncodedContent(collection); | ||
request.Content = content; | ||
|
||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var result = await response.Content.ReadFromJsonAsync<TokenObjFromKeycloack>(); | ||
|
||
return result!.AccessToken; | ||
} | ||
|
||
internal async static Task<string> GetAccessTokenNoRole() | ||
{ | ||
using var client = new HttpClient(); | ||
var request = new HttpRequestMessage(HttpMethod.Post, Environment.GetEnvironmentVariable("Keycloack__TokenUrl")); | ||
|
||
var collection = new List<KeyValuePair<string, string>> | ||
{ | ||
new("grant_type", "password"), | ||
new("client_id", "ubik_accounting_api"), | ||
new("username", "testnorole"), | ||
new("password", "test"), | ||
new("client_secret", "GQEyHjeBUThKta1eItucb5LFGj5Hduwd") | ||
}; | ||
|
||
var content = new FormUrlEncodedContent(collection); | ||
request.Content = content; | ||
|
||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var result = await response.Content.ReadFromJsonAsync<TokenObjFromKeycloack>(); | ||
|
||
return result!.AccessToken; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/Ubik.Accounting.Api.Tests.Integration/Auth/AuthObjFromKeycloack.cs
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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ubik.Accounting.Api.Tests.Integration.Auth | ||
{ | ||
internal class TokenObjFromKeycloack | ||
{ | ||
[JsonPropertyName("access_token")] | ||
public string AccessToken { get; set; } = default!; | ||
[JsonPropertyName("Expires_in")] | ||
public int ExpiresIn { get; set; } | ||
[JsonPropertyName("refresh_expires_in")] | ||
public int RefreshExpiresIn { get; set; } | ||
[JsonPropertyName("refresh_token")] | ||
public string RefreshToken { get; set; } = default!; | ||
[JsonPropertyName("token_type")] | ||
public string TokenType { get; set; } = default!; | ||
[JsonPropertyName("not_before_policy")] | ||
public int NotBeforePolicy { get; set; } | ||
[JsonPropertyName("session_state")] | ||
public string SessionState { get; set; } = default!; | ||
[JsonPropertyName("scope")] | ||
public string Scope { get; set; } = default!; | ||
|
||
} | ||
} |
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
Oops, something went wrong.