diff --git a/SecurityService.Client/ISecurityServiceClient.cs b/SecurityService.Client/ISecurityServiceClient.cs index 62d4d970..25589c1d 100644 --- a/SecurityService.Client/ISecurityServiceClient.cs +++ b/SecurityService.Client/ISecurityServiceClient.cs @@ -12,56 +12,41 @@ namespace SecurityService.Client /// /// public interface ISecurityServiceClient - { - #region Methods + { + Task CreateApiResource(String accessToken, CreateApiResourceRequest createApiResourceRequest, CancellationToken cancellationToken); + Task CreateApiScope(String accessToken, CreateApiScopeRequest createApiScopeRequest,CancellationToken cancellationToken); - void SetAccessToken(String accessToken); + Task CreateClient(String accessToken, CreateClientRequest createClientRequest,CancellationToken cancellationToken); - Task CreateApiResource(CreateApiResourceRequest createApiResourceRequest, - CancellationToken cancellationToken); - Task CreateApiScope(CreateApiScopeRequest createApiScopeRequest, - CancellationToken cancellationToken); + Task CreateIdentityResource(String accessToken, CreateIdentityResourceRequest createIdentityResourceRequest,CancellationToken cancellationToken); + Task CreateRole(String accessToken, CreateRoleRequest createRoleRequest,CancellationToken cancellationToken); - Task CreateClient(CreateClientRequest createClientRequest, - CancellationToken cancellationToken); + Task CreateUser(String accessToken, CreateUserRequest createUserRequest, CancellationToken cancellationToken); - Task CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, - CancellationToken cancellationToken); - Task CreateRole(CreateRoleRequest createRoleRequest, - CancellationToken cancellationToken); - - Task CreateUser(CreateUserRequest createUserRequest, - CancellationToken cancellationToken); + Task RequireUserMfa(String accessToken, String userId, CancellationToken cancellationToken); + Task RemoveUserMfa(String accessToken, String userId, CancellationToken cancellationToken); + Task RequireRoleMfa(String accessToken, String roleId, CancellationToken cancellationToken); + Task RemoveRoleMfa(String accessToken, String roleId, CancellationToken cancellationToken); - Task RequireUserMfa(String userId, CancellationToken cancellationToken); - Task RemoveUserMfa(String userId, CancellationToken cancellationToken); - Task RequireRoleMfa(String roleId, CancellationToken cancellationToken); - Task RemoveRoleMfa(String roleId, CancellationToken cancellationToken); + Task> GetApiResource(String accessToken, String apiResourceName,CancellationToken cancellationToken); - Task> GetApiResource(String apiResourceName, - CancellationToken cancellationToken); + Task> GetApiScope(String accessToken, String apiScopeName,CancellationToken cancellationToken); - Task> GetApiScope(String apiScopeName, - CancellationToken cancellationToken); + Task>> GetApiResources(String accessToken, CancellationToken cancellationToken); - Task>> GetApiResources(CancellationToken cancellationToken); + Task>> GetApiScopes(String accessToken, CancellationToken cancellationToken); - Task>> GetApiScopes(CancellationToken cancellationToken); + Task> GetClient(String accessToken, String clientId,CancellationToken cancellationToken); - Task> GetClient(String clientId, - CancellationToken cancellationToken); + Task>> GetClients(String accessToken, CancellationToken cancellationToken); - Task>> GetClients(CancellationToken cancellationToken); + Task> GetIdentityResource(String accessToken, String identityResourceName,CancellationToken cancellationToken); - Task> GetIdentityResource(String identityResourceName, - CancellationToken cancellationToken); + Task>> GetIdentityResources(String accessToken, CancellationToken cancellationToken); - Task>> GetIdentityResources(CancellationToken cancellationToken); + Task> GetRole(String accessToken, String roleId,CancellationToken cancellationToken); - Task> GetRole(String roleId, - CancellationToken cancellationToken); - - Task>> GetRoles(CancellationToken cancellationToken); + Task>> GetRoles(String accessToken, CancellationToken cancellationToken); Task> GetToken(String username, String password, @@ -78,11 +63,7 @@ Task> GetToken(String clientId, String refreshToken, CancellationToken cancellationToken); - Task> GetUser(String userId, - CancellationToken cancellationToken); - Task>> GetUsers(String userName, - CancellationToken cancellationToken); - - #endregion + Task> GetUser(String accessToken, String userId,CancellationToken cancellationToken); + Task>> GetUsers(String accessToken, String userName,CancellationToken cancellationToken); } } diff --git a/SecurityService.Client/SecurityServiceClient.cs b/SecurityService.Client/SecurityServiceClient.cs index ce86d922..6a0a227a 100644 --- a/SecurityService.Client/SecurityServiceClient.cs +++ b/SecurityService.Client/SecurityServiceClient.cs @@ -56,21 +56,22 @@ public SecurityServiceClient(Func baseAddressResolver, #endregion - public void SetAccessToken(String accessToken) - { - this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); - } + //public void SetAccessToken(String accessToken) + //{ + // this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + //} #region Methods - public async Task CreateApiResource(CreateApiResourceRequest createApiResourceRequest, + public async Task CreateApiResource(String accessToken, + CreateApiResourceRequest createApiResourceRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/apiresources"); try { - Result result = await this.Post(requestUri, createApiResourceRequest, cancellationToken); + Result result = await this.Post(requestUri, createApiResourceRequest, accessToken, cancellationToken); if(result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -86,14 +87,14 @@ public async Task CreateApiResource(CreateApiResourceRequest createApiRe } } - public async Task CreateApiScope(CreateApiScopeRequest createApiScopeRequest, + public async Task CreateApiScope(String accessToken, CreateApiScopeRequest createApiScopeRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/apiscopes"); try { - Result result = await this.Post(requestUri, createApiScopeRequest, cancellationToken); + Result result = await this.Post(requestUri, createApiScopeRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -109,14 +110,14 @@ public async Task CreateApiScope(CreateApiScopeRequest createApiScopeReq } } - public async Task CreateClient(CreateClientRequest createClientRequest, + public async Task CreateClient(String accessToken, CreateClientRequest createClientRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/clients"); try { - Result result = await this.Post(requestUri, createClientRequest, cancellationToken); + Result result = await this.Post(requestUri, createClientRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -132,14 +133,14 @@ public async Task CreateClient(CreateClientRequest createClientRequest, } } - public async Task CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, + public async Task CreateIdentityResource(String accessToken, CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/identityresources"); try { - Result result = await this.Post(requestUri, createIdentityResourceRequest, cancellationToken); + Result result = await this.Post(requestUri, createIdentityResourceRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -155,14 +156,14 @@ public async Task CreateIdentityResource(CreateIdentityResourceRequest c } } - public async Task CreateRole(CreateRoleRequest createRoleRequest, + public async Task CreateRole(String accessToken, CreateRoleRequest createRoleRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/roles"); try { - Result result = await this.Post(requestUri, createRoleRequest, cancellationToken); + Result result = await this.Post(requestUri, createRoleRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -184,14 +185,14 @@ public async Task CreateRole(CreateRoleRequest createRoleRequest, /// The create user request. /// The cancellation token. /// - public async Task CreateUser(CreateUserRequest createUserRequest, + public async Task CreateUser(String accessToken, CreateUserRequest createUserRequest, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/users"); try { - Result result = await this.Post(requestUri, createUserRequest, cancellationToken); + Result result = await this.Post(requestUri, createUserRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -207,33 +208,33 @@ public async Task CreateUser(CreateUserRequest createUserRequest, } } - public async Task RequireUserMfa(String userId, CancellationToken cancellationToken) + public async Task RequireUserMfa(String accessToken, String userId, CancellationToken cancellationToken) { - return await this.Put(this.BuildRequestUrl($"/api/users/{userId}/mfa-policy"), new { }, cancellationToken); + return await this.Put(this.BuildRequestUrl($"/api/users/{userId}/mfa-policy"), new { }, accessToken, cancellationToken); } - public async Task RemoveUserMfa(String userId, CancellationToken cancellationToken) + public async Task RemoveUserMfa(String accessToken, String userId, CancellationToken cancellationToken) { - return await this.Delete(this.BuildRequestUrl($"/api/users/{userId}/mfa-policy"), cancellationToken); + return await this.Delete(this.BuildRequestUrl($"/api/users/{userId}/mfa-policy"), accessToken, cancellationToken); } - public async Task RequireRoleMfa(String roleId, CancellationToken cancellationToken) + public async Task RequireRoleMfa(String accessToken, String roleId, CancellationToken cancellationToken) { - return await this.Put(this.BuildRequestUrl($"/api/roles/{roleId}/mfa-policy"), new { }, cancellationToken); + return await this.Put(this.BuildRequestUrl($"/api/roles/{roleId}/mfa-policy"), new { }, accessToken, cancellationToken); } - public async Task RemoveRoleMfa(String roleId, CancellationToken cancellationToken) + public async Task RemoveRoleMfa(String accessToken, String roleId, CancellationToken cancellationToken) { - return await this.Delete(this.BuildRequestUrl($"/api/roles/{roleId}/mfa-policy"), cancellationToken); + return await this.Delete(this.BuildRequestUrl($"/api/roles/{roleId}/mfa-policy"), accessToken, cancellationToken); } - public async Task> GetApiResource(String apiResourceName, + public async Task> GetApiResource(String accessToken, String apiResourceName, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/apiresources/{apiResourceName}"); try { - Result result = await this.Get(requestUri, cancellationToken); + Result result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -249,13 +250,13 @@ public async Task> GetApiResource(String apiResource } } - public async Task>> GetApiResources(CancellationToken cancellationToken) + public async Task>> GetApiResources(String accessToken, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/apiresources"); try { - Result> result = await this.Get>(requestUri, cancellationToken); + Result> result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -271,14 +272,14 @@ public async Task>> GetApiResources(Cancellatio } } - public async Task> GetApiScope(String apiScopeName, + public async Task> GetApiScope(String accessToken, String apiScopeName, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/apiscopes/{apiScopeName}"); try { - var result = await this.Get(requestUri, cancellationToken); + var result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -294,13 +295,13 @@ public async Task> GetApiScope(String apiScopeName, } } - public async Task>> GetApiScopes(CancellationToken cancellationToken) + public async Task>> GetApiScopes(String accessToken, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/apiscopes"); try { - var result = await this.Get>(requestUri, cancellationToken); + var result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -316,14 +317,14 @@ public async Task>> GetApiScopes(CancellationToken } } - public async Task> GetClient(String clientId, + public async Task> GetClient(String accessToken, String clientId, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/clients/{clientId}"); try { - var result = await this.Get(requestUri, cancellationToken); + var result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -339,13 +340,13 @@ public async Task> GetClient(String clientId, } } - public async Task>> GetClients(CancellationToken cancellationToken) + public async Task>> GetClients(String accessToken, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/clients"); try { - var result = await this.Get>(requestUri, cancellationToken); + var result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -361,14 +362,14 @@ public async Task>> GetClients(CancellationToken can } } - public async Task> GetIdentityResource(String identityResourceName, + public async Task> GetIdentityResource(String accessToken, String identityResourceName, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/identityresources/{identityResourceName}"); try { - var result = await this.Get(requestUri, cancellationToken); + var result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -384,13 +385,13 @@ public async Task> GetIdentityResource(String i } } - public async Task>> GetIdentityResources(CancellationToken cancellationToken) + public async Task>> GetIdentityResources(String accessToken, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/identityresources"); try { - var result = await this.Get>(requestUri, cancellationToken); + var result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -406,14 +407,14 @@ public async Task>> GetIdentityResources(C } } - public async Task> GetRole(String roleId, + public async Task> GetRole(String accessToken, String roleId, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/roles/{roleId}"); try { - var result = await this.Get(requestUri, cancellationToken); + var result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -429,13 +430,13 @@ public async Task> GetRole(String roleId, } } - public async Task>> GetRoles(CancellationToken cancellationToken) + public async Task>> GetRoles(String accessToken, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/roles"); try { - var result = await this.Get>(requestUri, cancellationToken); + var result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -496,14 +497,14 @@ public async Task> GetToken(String clientId, return await this.GetToken(queryString.ToString(), cancellationToken); } - public async Task> GetUser(String userId, + public async Task> GetUser(String accessToken, String userId, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl($"/api/users/{userId}"); try { - Result result = await this.Get(requestUri, cancellationToken); + Result result = await this.Get(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -519,7 +520,7 @@ public async Task> GetUser(String userId, } } - public async Task>> GetUsers(String userName, + public async Task>> GetUsers(String accessToken, String userName, CancellationToken cancellationToken) { String requestUri = this.BuildRequestUrl("/api/users"); @@ -531,7 +532,7 @@ public async Task>> GetUsers(String userName, requestUri = $"{requestUri}?username={userName}"; } - var result = await this.Get>(requestUri, cancellationToken); + var result = await this.Get>(requestUri, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); diff --git a/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs b/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs index 229b853a..49b8d86a 100644 --- a/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs +++ b/SecurityService.IntegrationTesting.Helpers/SecurityServiceSteps.cs @@ -12,21 +12,22 @@ namespace SecurityService.IntegrationTesting.Helpers; public class SecurityServiceSteps{ private readonly ISecurityServiceClient SecurityServiceClient; + private readonly string AccessToken; - public SecurityServiceSteps(ISecurityServiceClient securityServiceClient){ + public SecurityServiceSteps(ISecurityServiceClient securityServiceClient, String accessToken){ this.SecurityServiceClient = securityServiceClient; + this.AccessToken = accessToken; } - private async Task CreateApiScope(CreateApiScopeRequest createApiScopeRequest, + private async Task CreateApiScope(String accessToken, CreateApiScopeRequest createApiScopeRequest, CancellationToken cancellationToken){ - Result? result = await this.SecurityServiceClient - .CreateApiScope(createApiScopeRequest, cancellationToken).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateApiScope(this.AccessToken, createApiScopeRequest, cancellationToken).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); } public async Task GivenICreateTheFollowingApiScopes(List createApiScopeRequests){ foreach (CreateApiScopeRequest createApiScopeRequest in createApiScopeRequests){ - await this.CreateApiScope(createApiScopeRequest, CancellationToken.None).ConfigureAwait(false); + await this.CreateApiScope(this.AccessToken, createApiScopeRequest, CancellationToken.None).ConfigureAwait(false); // TODO: can do a get in here to verify really created... } @@ -54,7 +55,7 @@ public async Task GivenTheFollowingApiResourcesExist(DataTable table){ splitScopes.ForEach(a => { createApiResourceRequest.Scopes.Add(a.Trim()); }); splitUserClaims.ForEach(a => { createApiResourceRequest.UserClaims.Add(a.Trim()); }); - Result? result = await this.SecurityServiceClient.CreateApiResource(createApiResourceRequest, CancellationToken.None).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateApiResource(this.AccessToken, createApiResourceRequest, CancellationToken.None).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); } } @@ -62,7 +63,7 @@ public async Task GivenTheFollowingApiResourcesExist(DataTable table){ public async Task allowedGrantTypes)>> GivenTheFollowingClientsExist(List createClientRequests){ List<(String clientId, String secret, List allowedGrantTypes)> clients = new List<(String clientId, String secret, List allowedGrantTypes)>(); foreach (CreateClientRequest createClientRequest in createClientRequests){ - Result? result = await this.SecurityServiceClient.CreateClient(createClientRequest, CancellationToken.None).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateClient(this.AccessToken, createClientRequest, CancellationToken.None).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); // TODO: What do i do here.... @@ -74,7 +75,7 @@ public async Task GivenTheFollowingApiResourcesExist(DataTable table){ public async Task GivenTheFollowingApiResourcesExist(List requests){ foreach (CreateApiResourceRequest createApiResourceRequest in requests){ - Result? result = await this.SecurityServiceClient.CreateApiResource(createApiResourceRequest, CancellationToken.None).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateApiResource(this.AccessToken, createApiResourceRequest, CancellationToken.None).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); } } @@ -97,7 +98,7 @@ public Task> RequestPasswordToken(String clientId, String this.SecurityServiceClient.GetToken(userName, password, clientId, secret, cancellationToken); public async Task WhenIGetTheApiResourcesApiResourceDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken){ - Result>? apiResourceDetailsListResult = await this.SecurityServiceClient.GetApiResources(cancellationToken).ConfigureAwait(false); + Result>? apiResourceDetailsListResult = await this.SecurityServiceClient.GetApiResources(this.AccessToken, cancellationToken).ConfigureAwait(false); apiResourceDetailsListResult.IsSuccess.ShouldBeTrue(); List apiResourceDetailsList = apiResourceDetailsListResult.Data; foreach (ApiResourceResponse apiResourceDetails in expectedDetails){ @@ -116,7 +117,7 @@ public async Task WhenIGetTheApiResourcesApiResourceDetailsAreReturnedAsFollows( } public async Task WhenIGetTheApiResourceWithNameTheApiResourceDetailsAreReturnedAsFollows(List expectedDetails, String apiResourceName, CancellationToken cancellationToken){ - Result? apiResourceDetailsResult = await this.SecurityServiceClient.GetApiResource(apiResourceName, cancellationToken).ConfigureAwait(false); + Result? apiResourceDetailsResult = await this.SecurityServiceClient.GetApiResource(this.AccessToken, apiResourceName, cancellationToken).ConfigureAwait(false); apiResourceDetailsResult.IsSuccess.ShouldBeTrue(); ApiResourceResponse? apiResourceDetails = apiResourceDetailsResult.Data; @@ -135,7 +136,7 @@ public async Task WhenIGetTheApiResourceWithNameTheApiResourceDetailsAreReturned } public async Task WhenIGetTheApiScopesApiScopeDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken){ - Result>? apiScopeDetailsListResult = await this.SecurityServiceClient.GetApiScopes(cancellationToken).ConfigureAwait(false); + Result>? apiScopeDetailsListResult = await this.SecurityServiceClient.GetApiScopes(this.AccessToken, cancellationToken).ConfigureAwait(false); apiScopeDetailsListResult.IsSuccess.ShouldBeTrue(); List? apiScopeDetailsList = apiScopeDetailsListResult.Data; @@ -148,7 +149,7 @@ public async Task WhenIGetTheApiScopesApiScopeDetailsAreReturnedAsFollows(List expectedDetails, String apiScopeName, CancellationToken cancellationToken){ - Result? apiScopeDetailsResult = await this.SecurityServiceClient.GetApiScope(apiScopeName, cancellationToken).ConfigureAwait(false); + Result? apiScopeDetailsResult = await this.SecurityServiceClient.GetApiScope(this.AccessToken, apiScopeName, cancellationToken).ConfigureAwait(false); apiScopeDetailsResult.IsSuccess.ShouldBeTrue(); ApiScopeResponse? apiScopeDetails = apiScopeDetailsResult.Data; @@ -160,7 +161,7 @@ public async Task WhenIGetTheApiScopeWithNameTheApiScopeDetailsAreReturnedAsFoll } public async Task WhenIGetTheClientWithClientIdTheClientDetailsAreReturnedAsFollows(List expectedDetails, String clientId, CancellationToken cancellationToken){ - Result? clientDetailsResult = await this.SecurityServiceClient.GetClient(clientId, CancellationToken.None).ConfigureAwait(false); + Result? clientDetailsResult = await this.SecurityServiceClient.GetClient(this.AccessToken, clientId, CancellationToken.None).ConfigureAwait(false); clientDetailsResult.IsSuccess.ShouldBeTrue(); ClientResponse clientDetails = clientDetailsResult.Data; ClientResponse expectedRecord = expectedDetails.Single(); @@ -179,7 +180,7 @@ public async Task WhenIGetTheClientWithClientIdTheClientDetailsAreReturnedAsFoll } public async Task WhenIGetTheClientsClientsDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken){ - Result>? clientDetailsListResult = await this.SecurityServiceClient.GetClients(CancellationToken.None).ConfigureAwait(false); + Result>? clientDetailsListResult = await this.SecurityServiceClient.GetClients(this.AccessToken, CancellationToken.None).ConfigureAwait(false); clientDetailsListResult.IsSuccess.ShouldBeTrue(); List? clientDetailsList = clientDetailsListResult.Data; foreach (ClientResponse expectedRecord in expectedDetails){ @@ -201,14 +202,14 @@ public async Task WhenIGetTheClientsClientsDetailsAreReturnedAsFollows(List requests, CancellationToken cancellationToken){ foreach (CreateIdentityResourceRequest createIdentityResourceRequest in requests){ - Result? result = await this.SecurityServiceClient.CreateIdentityResource(createIdentityResourceRequest, cancellationToken).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateIdentityResource(this.AccessToken, createIdentityResourceRequest, cancellationToken).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); } } public async Task WhenIGetTheIdentityResourceWithNameTheIdentityResourceDetailsAreReturnedAsFollows(List expectedDetails, String identityResourceName, CancellationToken cancellationToken) { - Result? identityResourceDetailsResult = await this.SecurityServiceClient.GetIdentityResource(identityResourceName, cancellationToken).ConfigureAwait(false); + Result? identityResourceDetailsResult = await this.SecurityServiceClient.GetIdentityResource(this.AccessToken, identityResourceName, cancellationToken).ConfigureAwait(false); identityResourceDetailsResult.IsSuccess.ShouldBeTrue(); IdentityResourceResponse identityResourceDetails = identityResourceDetailsResult.Data; IdentityResourceResponse expectedRecord = expectedDetails.Single(); @@ -223,7 +224,7 @@ public async Task WhenIGetTheIdentityResourceWithNameTheIdentityResourceDetailsA } public async Task WhenIGetTheIdentityResourcesIdentityResourceDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken){ - Result>? getIdentityResourcesResult = await this.SecurityServiceClient.GetIdentityResources(CancellationToken.None).ConfigureAwait(false); + Result>? getIdentityResourcesResult = await this.SecurityServiceClient.GetIdentityResources(this.AccessToken, CancellationToken.None).ConfigureAwait(false); getIdentityResourcesResult.IsSuccess.ShouldBeTrue(); List? identityResourceDetailsList = getIdentityResourcesResult.Data; foreach (IdentityResourceResponse expectedRecord in expectedDetails){ @@ -244,11 +245,11 @@ public async Task WhenIGetTheIdentityResourcesIdentityResourceDetailsAreReturned public async Task> GivenICreateTheFollowingRoles(List requests, CancellationToken cancellationToken) { List<(String, String)> roleList = new List<(String, String)>(); foreach (CreateRoleRequest request in requests){ - Result? result = await this.SecurityServiceClient.CreateRole(request, cancellationToken).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateRole(this.AccessToken, request, cancellationToken).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(result.Message); } - Result>? roles = await this.SecurityServiceClient.GetRoles(cancellationToken); + Result>? roles = await this.SecurityServiceClient.GetRoles(this.AccessToken, cancellationToken); roles.IsSuccess.ShouldBeTrue(roles.Message); foreach (CreateRoleRequest request in requests) { @@ -261,7 +262,7 @@ public async Task WhenIGetTheIdentityResourcesIdentityResourceDetailsAreReturned public async Task WhenIGetTheRoleWithNameTheRoleDetailsAreReturnedAsFollows(List expectedDetails, String roleId, CancellationToken cancellationToken) { - Result? getRoleResult = await this.SecurityServiceClient.GetRole(roleId, cancellationToken).ConfigureAwait(false); + Result? getRoleResult = await this.SecurityServiceClient.GetRole(this.AccessToken, roleId, cancellationToken).ConfigureAwait(false); getRoleResult.IsSuccess.ShouldBeTrue(); RoleResponse roleDetails =getRoleResult.Data; RoleResponse expectedRecord = expectedDetails.Single(); @@ -271,7 +272,7 @@ public async Task WhenIGetTheRoleWithNameTheRoleDetailsAreReturnedAsFollows(List public async Task WhenIGetTheRolesRolesDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken) { - Result>? getRolesResult = await this.SecurityServiceClient.GetRoles(CancellationToken.None).ConfigureAwait(false); + Result>? getRolesResult = await this.SecurityServiceClient.GetRoles(this.AccessToken, CancellationToken.None).ConfigureAwait(false); getRolesResult.IsSuccess.ShouldBeTrue(); List? rolesList = getRolesResult.Data; foreach (RoleResponse expectedRecord in expectedDetails) @@ -285,10 +286,10 @@ public async Task WhenIGetTheRolesRolesDetailsAreReturnedAsFollows(List> GivenICreateTheFollowingUsers(List requests, CancellationToken cancellationToken){ List<(String, String)> results = new List<(String, String)>(); foreach (CreateUserRequest createUserRequest in requests){ - Result? result = await this.SecurityServiceClient.CreateUser(createUserRequest, cancellationToken).ConfigureAwait(false); + Result? result = await this.SecurityServiceClient.CreateUser(this.AccessToken, createUserRequest, cancellationToken).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); - Result>? user = await this.SecurityServiceClient.GetUsers(createUserRequest.EmailAddress, cancellationToken); + Result>? user = await this.SecurityServiceClient.GetUsers(this.AccessToken, createUserRequest.EmailAddress, cancellationToken); user.IsSuccess.ShouldBeTrue(); String userKey = String.IsNullOrWhiteSpace(createUserRequest.UserName) @@ -300,20 +301,20 @@ public async Task WhenIGetTheRolesRolesDetailsAreReturnedAsFollows(List RequireUserMfa(String userId, CancellationToken cancellationToken) => - this.SecurityServiceClient.RequireUserMfa(userId, cancellationToken); + this.SecurityServiceClient.RequireUserMfa(this.AccessToken, userId, cancellationToken); public Task RemoveUserMfa(String userId, CancellationToken cancellationToken) => - this.SecurityServiceClient.RemoveUserMfa(userId, cancellationToken); + this.SecurityServiceClient.RemoveUserMfa(this.AccessToken, userId, cancellationToken); public Task RequireRoleMfa(String roleId, CancellationToken cancellationToken) => - this.SecurityServiceClient.RequireRoleMfa(roleId, cancellationToken); + this.SecurityServiceClient.RequireRoleMfa(this.AccessToken, roleId, cancellationToken); public Task RemoveRoleMfa(String roleId, CancellationToken cancellationToken) => - this.SecurityServiceClient.RemoveRoleMfa(roleId, cancellationToken); + this.SecurityServiceClient.RemoveRoleMfa(this.AccessToken, roleId, cancellationToken); public async Task WhenIGetTheUsersUsersDetailsAreReturnedAsFollows(List expectedDetails, CancellationToken cancellationToken) { - Result>? getUsersResult = await this.SecurityServiceClient.GetUsers(String.Empty, CancellationToken.None).ConfigureAwait(false); + Result>? getUsersResult = await this.SecurityServiceClient.GetUsers(this.AccessToken, String.Empty, CancellationToken.None).ConfigureAwait(false); getUsersResult.IsSuccess.ShouldBeTrue(); List? usersList = getUsersResult.Data; foreach (UserResponse expectedRecord in expectedDetails) @@ -337,7 +338,7 @@ public async Task WhenIGetTheUsersUsersDetailsAreReturnedAsFollows(List expectedDetails, String userId, CancellationToken cancellationToken){ - var userDetails = await this.SecurityServiceClient.GetUser(userId, CancellationToken.None).ConfigureAwait(false); + var userDetails = await this.SecurityServiceClient.GetUser(this.AccessToken, userId, CancellationToken.None).ConfigureAwait(false); var expectedRecord = expectedDetails.Single(); userDetails.IsSuccess.ShouldBeTrue(); diff --git a/SecurityService.IntegrationTests/ApiResource/ApiResourceSteps.cs b/SecurityService.IntegrationTests/ApiResource/ApiResourceSteps.cs index b96938ec..3d5c8894 100644 --- a/SecurityService.IntegrationTests/ApiResource/ApiResourceSteps.cs +++ b/SecurityService.IntegrationTests/ApiResource/ApiResourceSteps.cs @@ -42,7 +42,7 @@ public class ApiResourceSteps public ApiResourceSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion diff --git a/SecurityService.IntegrationTests/ApiScopes/ApiScopeSteps.cs b/SecurityService.IntegrationTests/ApiScopes/ApiScopeSteps.cs index b6f0ac4c..52a9fc90 100644 --- a/SecurityService.IntegrationTests/ApiScopes/ApiScopeSteps.cs +++ b/SecurityService.IntegrationTests/ApiScopes/ApiScopeSteps.cs @@ -39,7 +39,7 @@ public class ApiScopeSteps public ApiScopeSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion diff --git a/SecurityService.IntegrationTests/Clients/ClientsSteps.cs b/SecurityService.IntegrationTests/Clients/ClientsSteps.cs index b441a52a..45c8e7c2 100644 --- a/SecurityService.IntegrationTests/Clients/ClientsSteps.cs +++ b/SecurityService.IntegrationTests/Clients/ClientsSteps.cs @@ -39,7 +39,7 @@ public class ClientsSteps public ClientsSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion diff --git a/SecurityService.IntegrationTests/Common/DockerHelper.cs b/SecurityService.IntegrationTests/Common/DockerHelper.cs index 5e3c3b8c..8a1636fb 100644 --- a/SecurityService.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.IntegrationTests/Common/DockerHelper.cs @@ -6,6 +6,7 @@ namespace SecurityService.IntergrationTests.Common { using Client; + using NLog.Config; using SecurityService.IntegrationTesting.Helpers; using Shared.IntegrationTesting; using System; @@ -30,6 +31,7 @@ Object Deserialise(String arg, Type type) { return StringSerialiser.DeserializeObject(arg, type, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); } + public String AccessToken; public override async Task StartContainersForScenarioRun(String scenarioName, DockerServices dockerServices) { @@ -48,8 +50,7 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do { throw new InvalidOperationException("Unable to obtain the integration-test management bootstrap token."); } - - this.SecurityServiceClient.SetAccessToken(bootstrapToken.Data.AccessToken); + this.AccessToken = bootstrapToken.Data.AccessToken; ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; } diff --git a/SecurityService.IntegrationTests/IdentityResource/IdentityResourceSteps.cs b/SecurityService.IntegrationTests/IdentityResource/IdentityResourceSteps.cs index 528b930c..aae6f4fb 100644 --- a/SecurityService.IntegrationTests/IdentityResource/IdentityResourceSteps.cs +++ b/SecurityService.IntegrationTests/IdentityResource/IdentityResourceSteps.cs @@ -37,7 +37,7 @@ public class IdentityResourceSteps public IdentityResourceSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion diff --git a/SecurityService.IntegrationTests/Roles/Roles.feature b/SecurityService.IntegrationTests/Roles/Roles.feature index 4506baa7..22bc1a9c 100644 --- a/SecurityService.IntegrationTests/Roles/Roles.feature +++ b/SecurityService.IntegrationTests/Roles/Roles.feature @@ -11,12 +11,17 @@ Scenario: Get Roles @mfa Scenario: Require and remove MFA for a role + Given I create the following roles + | Role Name | + | TestRole1 | + | TestRole2 | + | TestRole3 | When I require MFA for role 'TestRole1' - Then the MFA policy operation succeeds + Then the role MFA policy operation succeeds When I require MFA for role 'TestRole1' - Then the MFA policy operation succeeds + Then the role MFA policy operation succeeds When I remove MFA for role 'TestRole1' - Then the MFA policy operation succeeds + Then the role MFA policy operation succeeds When I get the role with name 'TestRole1' the role details are returned as follows | Role Name | | TestRole1 | diff --git a/SecurityService.IntegrationTests/Roles/Roles.feature.cs b/SecurityService.IntegrationTests/Roles/Roles.feature.cs index bf89d4e1..0a0174d7 100644 --- a/SecurityService.IntegrationTests/Roles/Roles.feature.cs +++ b/SecurityService.IntegrationTests/Roles/Roles.feature.cs @@ -134,16 +134,16 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa else { await this.ScenarioStartAsync(); - global::Reqnroll.Table table1 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table17 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table1.AddRow(new string[] { + table17.AddRow(new string[] { "TestRole1"}); - table1.AddRow(new string[] { + table17.AddRow(new string[] { "TestRole2"}); - table1.AddRow(new string[] { + table17.AddRow(new string[] { "TestRole3"}); #line 6 - await testRunner.GivenAsync("I create the following roles", ((string)(null)), table1, "Given "); + await testRunner.GivenAsync("I create the following roles", ((string)(null)), table17, "Given "); #line hidden } await this.ScenarioCleanupAsync(); @@ -171,55 +171,66 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa else { await this.ScenarioStartAsync(); + global::Reqnroll.Table table18 = new global::Reqnroll.Table(new string[] { + "Role Name"}); + table18.AddRow(new string[] { + "TestRole1"}); + table18.AddRow(new string[] { + "TestRole2"}); + table18.AddRow(new string[] { + "TestRole3"}); #line 14 + await testRunner.GivenAsync("I create the following roles", ((string)(null)), table18, "Given "); +#line hidden +#line 19 await testRunner.WhenAsync("I require MFA for role \'TestRole1\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 15 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 20 + await testRunner.ThenAsync("the role MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden -#line 16 +#line 21 await testRunner.WhenAsync("I require MFA for role \'TestRole1\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 17 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 22 + await testRunner.ThenAsync("the role MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden -#line 18 +#line 23 await testRunner.WhenAsync("I remove MFA for role \'TestRole1\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 19 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 24 + await testRunner.ThenAsync("the role MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden - global::Reqnroll.Table table2 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table19 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table2.AddRow(new string[] { + table19.AddRow(new string[] { "TestRole1"}); -#line 20 - await testRunner.WhenAsync("I get the role with name \'TestRole1\' the role details are returned as follows", ((string)(null)), table2, "When "); +#line 25 + await testRunner.WhenAsync("I get the role with name \'TestRole1\' the role details are returned as follows", ((string)(null)), table19, "When "); #line hidden - global::Reqnroll.Table table3 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table20 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table3.AddRow(new string[] { + table20.AddRow(new string[] { "TestRole2"}); -#line 23 - await testRunner.WhenAsync("I get the role with name \'TestRole2\' the role details are returned as follows", ((string)(null)), table3, "When "); +#line 28 + await testRunner.WhenAsync("I get the role with name \'TestRole2\' the role details are returned as follows", ((string)(null)), table20, "When "); #line hidden - global::Reqnroll.Table table4 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table21 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table4.AddRow(new string[] { + table21.AddRow(new string[] { "TestRole3"}); -#line 26 - await testRunner.WhenAsync("I get the role with name \'TestRole3\' the role details are returned as follows", ((string)(null)), table4, "When "); +#line 31 + await testRunner.WhenAsync("I get the role with name \'TestRole3\' the role details are returned as follows", ((string)(null)), table21, "When "); #line hidden - global::Reqnroll.Table table5 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table22 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table5.AddRow(new string[] { + table22.AddRow(new string[] { "TestRole1"}); - table5.AddRow(new string[] { + table22.AddRow(new string[] { "TestRole2"}); - table5.AddRow(new string[] { + table22.AddRow(new string[] { "TestRole3"}); -#line 29 - await testRunner.WhenAsync("I get the roles 3 roles details are returned as follows", ((string)(null)), table5, "When "); +#line 34 + await testRunner.WhenAsync("I get the roles 3 roles details are returned as follows", ((string)(null)), table22, "When "); #line hidden } await this.ScenarioCleanupAsync(); diff --git a/SecurityService.IntegrationTests/Roles/RolesSteps.cs b/SecurityService.IntegrationTests/Roles/RolesSteps.cs index cc6100c7..f48441bc 100644 --- a/SecurityService.IntegrationTests/Roles/RolesSteps.cs +++ b/SecurityService.IntegrationTests/Roles/RolesSteps.cs @@ -36,7 +36,7 @@ public class RolesSteps public RolesSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion @@ -80,7 +80,7 @@ public async Task WhenIRemoveMfaForRole(String roleName) this.TestingContext.LastMfaPolicyResult = await this.SecurityServiceSteps.RemoveRoleMfa(roleId, CancellationToken.None); } - [Then(@"the MFA policy operation succeeds")] + [Then(@"the role MFA policy operation succeeds")] public void ThenTheMfaPolicyOperationSucceeds() { this.TestingContext.LastMfaPolicyResult.ShouldNotBeNull(); diff --git a/SecurityService.IntegrationTests/Token/Token.feature b/SecurityService.IntegrationTests/Token/Token.feature index 59b613ca..7f4172a5 100644 --- a/SecurityService.IntegrationTests/Token/Token.feature +++ b/SecurityService.IntegrationTests/Token/Token.feature @@ -39,11 +39,13 @@ Scenario: Get Tokens @mfa Scenario: Password token is rejected when MFA is required When I require MFA for user 'merchantuser' - Then the MFA policy operation succeeds + Then the user MFA policy operation succeeds When I request a password token with the following values | ClientId | ClientSecret | Username | Password | | merchantClient | Secret1 | merchantuser | 123456 | Then the password token request fails + When I remove MFA for user 'merchantuser' + Then the user MFA policy operation succeeds When I request a password token with the following values | ClientId | ClientSecret | Username | Password | | merchantClient | Secret1 | merchantuser | 123456 | diff --git a/SecurityService.IntegrationTests/Token/Token.feature.cs b/SecurityService.IntegrationTests/Token/Token.feature.cs index 6582145b..2c656c0c 100644 --- a/SecurityService.IntegrationTests/Token/Token.feature.cs +++ b/SecurityService.IntegrationTests/Token/Token.feature.cs @@ -297,7 +297,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa await testRunner.WhenAsync("I require MFA for user \'merchantuser\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden #line 42 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); + await testRunner.ThenAsync("the user MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden global::Reqnroll.Table table7 = new global::Reqnroll.Table(new string[] { "ClientId", @@ -314,6 +314,12 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa #line hidden #line 46 await testRunner.ThenAsync("the password token request fails", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line hidden +#line 47 + await testRunner.WhenAsync("I remove MFA for user \'merchantuser\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); +#line hidden +#line 48 + await testRunner.ThenAsync("the user MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden global::Reqnroll.Table table8 = new global::Reqnroll.Table(new string[] { "ClientId", @@ -325,10 +331,10 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa "Secret1", "merchantuser", "123456"}); -#line 47 +#line 49 await testRunner.WhenAsync("I request a password token with the following values", ((string)(null)), table8, "When "); #line hidden -#line 50 +#line 52 await testRunner.ThenAsync("my token is returned", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden } diff --git a/SecurityService.IntegrationTests/Token/TokenSteps.cs b/SecurityService.IntegrationTests/Token/TokenSteps.cs index 9a586e2b..ccd3d162 100644 --- a/SecurityService.IntegrationTests/Token/TokenSteps.cs +++ b/SecurityService.IntegrationTests/Token/TokenSteps.cs @@ -23,7 +23,7 @@ public class TokenSteps public TokenSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } [When(@"I request a client token with the following values")] diff --git a/SecurityService.IntegrationTests/Users/Users.feature b/SecurityService.IntegrationTests/Users/Users.feature index 139fc75a..0bdabc01 100644 --- a/SecurityService.IntegrationTests/Users/Users.feature +++ b/SecurityService.IntegrationTests/Users/Users.feature @@ -29,13 +29,16 @@ Scenario: Get Users Scenario: Require and remove MFA for a user Given I create the following users | Email Address | Phone Number | Given Name | Middle Name | Family Name | Claims | Roles | + | testuser1@testing.co.uk | 123456789 | Test | | User 1 | | TestRole1 | + | testuser2@testing.co.uk | 123456789 | Test | | User 2 | | TestRole2 | + | testuser3@testing.co.uk | 123456789 | Test | | User 3 | | TestRole3 | | mfauser@testing.co.uk | 123456789 | MFA | | User | | TestRole1 | When I require MFA for user 'mfauser@testing.co.uk' - Then the MFA policy operation succeeds + Then the user MFA policy operation succeeds When I require MFA for user 'mfauser@testing.co.uk' - Then the MFA policy operation succeeds + Then the user MFA policy operation succeeds When I remove MFA for user 'mfauser@testing.co.uk' - Then the MFA policy operation succeeds + Then the user MFA policy operation succeeds When I get the users 3 users details are returned as follows | Email Address | Phone Number | Given Name | Middle Name | Family Name | Claims | Roles |RegistrationDate | | testuser1@testing.co.uk | 123456789 | Test | | User 1 | emailaddress:testuser1@testing.co.uk, givenname:Test, surname:User 1 | TestRole1 |Today | diff --git a/SecurityService.IntegrationTests/Users/Users.feature.cs b/SecurityService.IntegrationTests/Users/Users.feature.cs index 9814c9b6..12263e10 100644 --- a/SecurityService.IntegrationTests/Users/Users.feature.cs +++ b/SecurityService.IntegrationTests/Users/Users.feature.cs @@ -294,6 +294,30 @@ await testRunner.WhenAsync("I get the user with user name \'testuser3@testing.co "Family Name", "Claims", "Roles"}); + table6.AddRow(new string[] { + "testuser1@testing.co.uk", + "123456789", + "Test", + "", + "User 1", + "", + "TestRole1"}); + table6.AddRow(new string[] { + "testuser2@testing.co.uk", + "123456789", + "Test", + "", + "User 2", + "", + "TestRole2"}); + table6.AddRow(new string[] { + "testuser3@testing.co.uk", + "123456789", + "Test", + "", + "User 3", + "", + "TestRole3"}); table6.AddRow(new string[] { "mfauser@testing.co.uk", "123456789", @@ -305,23 +329,23 @@ await testRunner.WhenAsync("I get the user with user name \'testuser3@testing.co #line 30 await testRunner.GivenAsync("I create the following users", ((string)(null)), table6, "Given "); #line hidden -#line 33 +#line 36 await testRunner.WhenAsync("I require MFA for user \'mfauser@testing.co.uk\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 34 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 37 + await testRunner.ThenAsync("the user MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden -#line 35 +#line 38 await testRunner.WhenAsync("I require MFA for user \'mfauser@testing.co.uk\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 36 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 39 + await testRunner.ThenAsync("the user MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden -#line 37 +#line 40 await testRunner.WhenAsync("I remove MFA for user \'mfauser@testing.co.uk\'", ((string)(null)), ((global::Reqnroll.Table)(null)), "When "); #line hidden -#line 38 - await testRunner.ThenAsync("the MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); +#line 41 + await testRunner.ThenAsync("the user MFA policy operation succeeds", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); #line hidden global::Reqnroll.Table table7 = new global::Reqnroll.Table(new string[] { "Email Address", @@ -359,7 +383,7 @@ await testRunner.WhenAsync("I get the user with user name \'testuser3@testing.co "emailaddress:testuser3@testing.co.uk, givenname:Test, surname:User 3", "TestRole3", "Today"}); -#line 39 +#line 42 await testRunner.WhenAsync("I get the users 3 users details are returned as follows", ((string)(null)), table7, "When "); #line hidden } diff --git a/SecurityService.IntegrationTests/Users/UsersSteps.cs b/SecurityService.IntegrationTests/Users/UsersSteps.cs index d17f0419..fcb33d64 100644 --- a/SecurityService.IntegrationTests/Users/UsersSteps.cs +++ b/SecurityService.IntegrationTests/Users/UsersSteps.cs @@ -40,7 +40,7 @@ public class UsersSteps public UsersSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, this.TestingContext.DockerHelper.AccessToken); } #endregion @@ -99,8 +99,8 @@ public async Task WhenIRemoveMfaForUser(String userName) this.TestingContext.LastMfaPolicyResult = await this.SecurityServiceSteps.RemoveUserMfa(userId, CancellationToken.None); } - [Then(@"the MFA policy operation succeeds")] - public void ThenTheMfaPolicyOperationSucceeds() + [Then(@"the user MFA policy operation succeeds")] + public void ThenTheUserMfaPolicyOperationSucceeds() { this.TestingContext.LastMfaPolicyResult.ShouldNotBeNull(); this.TestingContext.LastMfaPolicyResult.IsSuccess.ShouldBeTrue(this.TestingContext.LastMfaPolicyResult.Message); diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs index d308550c..9460d763 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs @@ -40,7 +40,7 @@ public class DockerHelper : Shared.IntegrationTesting.TestContainers.DockerHelpe public ISecurityServiceClient SecurityServiceClient; public HttpClient httpClient = new HttpClient(); private IntegrationTestCertificate? _integrationTestCertificate; - + public String AccessToken; /// /// The security service test UI container name /// @@ -119,7 +119,7 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do throw new InvalidOperationException("Unable to obtain the integration-test management bootstrap token."); } - this.SecurityServiceClient.SetAccessToken(bootstrapToken.Data.AccessToken); + this.AccessToken = bootstrapToken.Data.AccessToken; DockerHelper.AddEntryToHostsFile("127.0.0.1", SecurityServiceContainerName); DockerHelper.AddEntryToHostsFile("localhost", SecurityServiceContainerName); diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/SharedSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/SharedSteps.cs index 09a40bc4..6fd64626 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/SharedSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/SharedSteps.cs @@ -25,7 +25,8 @@ public class SharedSteps public SharedSteps(TestingContext testingContext) { this.TestingContext = testingContext; - this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient); + this.SecurityServiceSteps = new SecurityServiceSteps(this.TestingContext.DockerHelper.SecurityServiceClient, + this.TestingContext.DockerHelper.AccessToken); } [Given(@"I create the following roles")] @@ -74,11 +75,11 @@ public async Task GivenICreateTheFollowingApiResources(DataTable table) private async Task CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { - Result> identityResourceListResult = await this.TestingContext.DockerHelper.SecurityServiceClient.GetIdentityResources(cancellationToken); + Result> identityResourceListResult = await this.TestingContext.DockerHelper.SecurityServiceClient.GetIdentityResources(this.TestingContext.DockerHelper.AccessToken,cancellationToken); identityResourceListResult.IsSuccess.ShouldBeTrue(); List identityResourceList = identityResourceListResult.Data; if (identityResourceList == null || identityResourceList.Any() == false) { - Result result = await this.TestingContext.DockerHelper.SecurityServiceClient.CreateIdentityResource(createIdentityResourceRequest, cancellationToken).ConfigureAwait(false); + Result result = await this.TestingContext.DockerHelper.SecurityServiceClient.CreateIdentityResource(this.TestingContext.DockerHelper.AccessToken,createIdentityResourceRequest, cancellationToken).ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); this.TestingContext.IdentityResources.Add(createIdentityResourceRequest.Name); @@ -92,7 +93,7 @@ private async Task CreateIdentityResource(CreateIdentityResourceRequest createId Result result = await this .TestingContext.DockerHelper.SecurityServiceClient - .CreateIdentityResource(createIdentityResourceRequest, cancellationToken) + .CreateIdentityResource(this.TestingContext.DockerHelper.AccessToken,createIdentityResourceRequest, cancellationToken) .ConfigureAwait(false); result.IsSuccess.ShouldBeTrue(); diff --git a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature.cs b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature.cs index f5637ca7..362b875e 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature.cs @@ -113,52 +113,52 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa { #line 4 #line hidden - global::Reqnroll.Table table1 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table11 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table1.AddRow(new string[] { + table11.AddRow(new string[] { "Estate"}); #line 6 - await testRunner.GivenAsync("I create the following roles", ((string)(null)), table1, "Given "); + await testRunner.GivenAsync("I create the following roles", ((string)(null)), table11, "Given "); #line hidden - global::Reqnroll.Table table2 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table12 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Secret", "Scopes", "UserClaims"}); - table2.AddRow(new string[] { + table12.AddRow(new string[] { "transactionProcessor", "Transaction Processor REST", "Secret1", "transactionProcessor", "MerchantId,EstateId,role"}); #line 10 - await testRunner.GivenAsync("I create the following api resources", ((string)(null)), table2, "Given "); + await testRunner.GivenAsync("I create the following api resources", ((string)(null)), table12, "Given "); #line hidden - global::Reqnroll.Table table3 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table13 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Description", "UserClaims"}); - table3.AddRow(new string[] { + table13.AddRow(new string[] { "openid", "Your user identifier", "", "sub"}); - table3.AddRow(new string[] { + table13.AddRow(new string[] { "profile", "User profile", "Your user profile information (first name, last name, etc.)", "name,role,email,given_name,middle_name,family_name,EstateId,MerchantId"}); - table3.AddRow(new string[] { + table13.AddRow(new string[] { "email", "Email", "Email and Email Verified Flags", "email_verified,email"}); #line 14 - await testRunner.GivenAsync("I create the following identity resources", ((string)(null)), table3, "Given "); + await testRunner.GivenAsync("I create the following identity resources", ((string)(null)), table13, "Given "); #line hidden - global::Reqnroll.Table table4 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table14 = new global::Reqnroll.Table(new string[] { "ClientId", "Name", "Secret", @@ -169,7 +169,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa "RequireConsent", "AllowOfflineAccess", "ClientUri"}); - table4.AddRow(new string[] { + table14.AddRow(new string[] { "estateUIClient", "Merchant Client", "Secret1", @@ -181,7 +181,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa "true", "https://[url]:[port]"}); #line 20 - await testRunner.GivenAsync("I create the following clients", ((string)(null)), table4, "Given "); + await testRunner.GivenAsync("I create the following clients", ((string)(null)), table14, "Given "); #line hidden } @@ -215,7 +215,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa #line 4 await this.FeatureBackgroundAsync(); #line hidden - global::Reqnroll.Table table5 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table15 = new global::Reqnroll.Table(new string[] { "Email Address", "Phone Number", "Given Name", @@ -223,7 +223,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa "Family Name", "Claims", "Roles"}); - table5.AddRow(new string[] { + table15.AddRow(new string[] { "estateuser@testestate1.co.uk", "123456789", "Test", @@ -232,7 +232,7 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa "EstateId:1", "Estate"}); #line 26 - await testRunner.GivenAsync("I create the following users", ((string)(null)), table5, "Given "); + await testRunner.GivenAsync("I create the following users", ((string)(null)), table15, "Given "); #line hidden #line 29 await testRunner.ThenAsync("I get an email with a confirm email address link", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); @@ -291,7 +291,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c #line 4 await this.FeatureBackgroundAsync(); #line hidden - global::Reqnroll.Table table6 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table16 = new global::Reqnroll.Table(new string[] { "Email Address", "Phone Number", "Given Name", @@ -299,7 +299,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c "Family Name", "Claims", "Roles"}); - table6.AddRow(new string[] { + table16.AddRow(new string[] { "mfauser@testestate1.co.uk", "123456789", "Test", @@ -308,7 +308,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c "EstateId:1", "Estate"}); #line 41 - await testRunner.GivenAsync("I create the following users", ((string)(null)), table6, "Given "); + await testRunner.GivenAsync("I create the following users", ((string)(null)), table16, "Given "); #line hidden #line 44 await testRunner.ThenAsync("I get an email with a confirm email address link", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then "); @@ -405,7 +405,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c #line 4 await this.FeatureBackgroundAsync(); #line hidden - global::Reqnroll.Table table7 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table17 = new global::Reqnroll.Table(new string[] { "Email Address", "Phone Number", "Given Name", @@ -413,7 +413,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c "Family Name", "Claims", "Roles"}); - table7.AddRow(new string[] { + table17.AddRow(new string[] { "recoveryuser@testestate1.co.uk", "123456789", "Test", @@ -422,7 +422,7 @@ await testRunner.WhenAsync("I login with the username \'estateuser@testestate1.c "EstateId:1", "Estate"}); #line 69 - await testRunner.GivenAsync("I create the following users", ((string)(null)), table7, "Given "); + await testRunner.GivenAsync("I create the following users", ((string)(null)), table17, "Given "); #line hidden #line 72 await testRunner.ThenAsync("I get an email with a confirm email address link", ((string)(null)), ((global::Reqnroll.Table)(null)), "Then ");