-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified integration tests
- Loading branch information
Showing
22 changed files
with
196 additions
and
228 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
23 changes: 16 additions & 7 deletions
23
tests/Skoruba.IdentityServer4.Admin.IntegrationTests/Common/HttpClientExtensions.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 |
---|---|---|
@@ -1,17 +1,26 @@ | ||
using System.Net.Http; | ||
using Skoruba.IdentityServer4.Admin.Configuration.Constants; | ||
using System; | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Net.Http; | ||
using System.Security.Claims; | ||
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces; | ||
using Skoruba.IdentityServer4.Admin.Middlewares; | ||
|
||
namespace Skoruba.IdentityServer4.Admin.IntegrationTests.Common | ||
{ | ||
public static class HttpClientExtensions | ||
{ | ||
public static void SetAdminClaimsViaHeaders(this HttpClient client) | ||
public static void SetAdminClaimsViaHeaders(this HttpClient client, IAdminConfiguration adminConfiguration) | ||
{ | ||
client.DefaultRequestHeaders.Add($"{AuthenticatedTestRequestMiddleware.TestUserPrefixHeader}-{AuthenticatedTestRequestMiddleware.TestUserId}", "1"); | ||
client.DefaultRequestHeaders.Add($"{AuthenticatedTestRequestMiddleware.TestUserPrefixHeader}-{AuthenticatedTestRequestMiddleware.TestUserName}", "test"); | ||
client.DefaultRequestHeaders.Add($"{AuthenticatedTestRequestMiddleware.TestUserPrefixHeader}-{AuthenticatedTestRequestMiddleware.TestUserRoles}", AuthenticatedTestRequestMiddleware.TestAdministrationRole); | ||
} | ||
var claims = new[] | ||
{ | ||
new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()), | ||
new Claim(ClaimTypes.Name, Guid.NewGuid().ToString()), | ||
new Claim(ClaimTypes.Role, adminConfiguration.AdministrationRole) | ||
}; | ||
|
||
var token = new JwtSecurityToken(claims: claims); | ||
var t = new JwtSecurityTokenHandler().WriteToken(token); | ||
client.DefaultRequestHeaders.Add(AuthenticatedTestRequestMiddleware.TestAuthorizationHeader, t); | ||
} | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
tests/Skoruba.IdentityServer4.Admin.IntegrationTests/Common/TestFixture.cs
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
.../Skoruba.IdentityServer4.Admin.IntegrationTests/Common/WebApplicationFactoryExtensions.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,24 @@ | ||
using System.Net.Http; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.AspNetCore.TestHost; | ||
|
||
namespace Skoruba.IdentityServer4.Admin.IntegrationTests.Common | ||
{ | ||
public static class WebApplicationFactoryExtensions | ||
{ | ||
public static HttpClient SetupClient(this WebApplicationFactory<Startup> fixture) | ||
{ | ||
var options = new WebApplicationFactoryClientOptions | ||
{ | ||
AllowAutoRedirect = false | ||
}; | ||
|
||
return fixture.WithWebHostBuilder( | ||
builder => builder | ||
.UseEnvironment(EnvironmentName.Staging) | ||
.ConfigureTestServices(services => { }) | ||
).CreateClient(options); | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
tests/Skoruba.IdentityServer4.Admin.IntegrationTests/Tests/Base/BaseClassFixture.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,31 @@ | ||
using System.Net.Http; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Skoruba.IdentityServer4.Admin.Configuration.Interfaces; | ||
using Skoruba.IdentityServer4.Admin.IntegrationTests.Common; | ||
using Xunit; | ||
|
||
namespace Skoruba.IdentityServer4.Admin.IntegrationTests.Tests.Base | ||
{ | ||
public class BaseClassFixture : IClassFixture<WebApplicationFactory<Startup>> | ||
{ | ||
protected readonly WebApplicationFactory<Startup> Factory; | ||
protected readonly HttpClient Client; | ||
|
||
public BaseClassFixture(WebApplicationFactory<Startup> factory) | ||
{ | ||
Factory = factory; | ||
Client = factory.SetupClient(); | ||
Factory.CreateClient(); | ||
} | ||
|
||
protected virtual void SetupAdminClaimsViaHeaders() | ||
{ | ||
using (var scope = Factory.Server.Host.Services.CreateScope()) | ||
{ | ||
var configuration = scope.ServiceProvider.GetRequiredService<IRootConfiguration>(); | ||
Client.SetAdminClaimsViaHeaders(configuration.AdminConfiguration); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.