Exemple #1
0
        public async Task ApplyClientDefninition_NoPostLogoutRedirectUrisDefined_ReturnsClientWithEmptyPostLogoutRredirectUris()
        {
            var clientRespository = Substitute.For <IIdentityClientRepository>();

            // The service will look for an existing client by it's ID, return null to trigger the client creation flow.
            clientRespository.GetByClientIdAsync(Arg.Any <string>()).Returns(mockedClientEntity);
            clientRespository.UpdateAsync(Arg.Any <Client>()).Returns(mockedClientEntity);

            var oauthClientSubmitMock = oauth2ClientSubmit;

            // Set the allowed CORS orgin array member to an empty string field. This should throw a v
            oauthClientSubmitMock.PostLogoutRedirectUris = null;

            var clientService        = new SecurityContractClientService(clientRespository, mapper);
            var updateClientResource = await clientService.ApplyClientDefinitionAsync(oauthClientSubmitMock, false, new SecurityContractDryRunResult());


            Assert.True(updateClientResource.Name == oauth2ClientSubmit.Name, $"Retrieved name: {updateClientResource.Name} not the same as the expected name: {oauth2ClientSubmit.Name}");
            Assert.True(updateClientResource.ClientId == oauth2ClientSubmit.ClientId, $"Retrieved clientId: {updateClientResource.ClientId} not the same as the expected name: {oauth2ClientSubmit.ClientId}");
            Assert.True(updateClientResource.AllowedOfflineAccess == true, $"Retrieved allowedOfflineAccess: {updateClientResource.AllowedOfflineAccess} not the expeced value: true");
            Assert.True(updateClientResource.AllowedGrantTypes.First() == oauth2ClientSubmit.AllowedGrantTypes.First(), $"Retrieved allowedGrantTypes first element: {updateClientResource.AllowedGrantTypes.First()} not the expected value: {oauth2ClientSubmit.AllowedGrantTypes.First()}");
            Assert.True(updateClientResource.AllowedCorsOrigins.First() == oauth2ClientSubmit.AllowedCorsOrigins.First(), $"Retrieved allowedCorsOrigins first element: {updateClientResource.AllowedCorsOrigins.First()} not the expected value: {oauth2ClientSubmit.AllowedCorsOrigins.First()}");
            Assert.True(!updateClientResource.PostLogoutRedirectUris.Any(), $"Retrieved PostLogoutRedirectUris is expected to be empty, but it is not.");
            Assert.True(updateClientResource.AllowedScopes.First() == oauth2ClientSubmit.AllowedScopes.First(), $"Retrieved AllowedScopes first element: {updateClientResource.AllowedScopes.First()} not the expected value: {oauth2ClientSubmit.AllowedScopes.First()}");
            Assert.True(updateClientResource.RedirectUris.First() == oauth2ClientSubmit.RedirectUris.First(), $"Retrieved RedirectUris first element: {updateClientResource.RedirectUris.First()} not the expected value: {oauth2ClientSubmit.RedirectUris.First()}");
        }
Exemple #2
0
        public void RollbackTransaction_Executed_ExecutesWithNoException()
        {
            var clientRespository = Substitute.For <IIdentityClientRepository>();
            var clientService     = new SecurityContractClientService(clientRespository, mapper);

            Exception caughtException = null;

            try
            {
                clientService.RollbackTransaction();
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.True(caughtException == null, "RollbackTransaction must not throw an exception.");
        }
Exemple #3
0
        public async Task ApplyClientDefninition_IsExistingClient_ReturnsUpdatedClient()
        {
            var clientRespository = Substitute.For <IIdentityClientRepository>();

            // The service will look for an existing client by it's ID, return null to trigger the client creation flow.
            clientRespository.GetByClientIdAsync(Arg.Any <string>()).Returns(mockedClientEntity);
            clientRespository.UpdateAsync(Arg.Any <Client>()).Returns(mockedClientEntity);

            var clientService        = new SecurityContractClientService(clientRespository, mapper);
            var updateClientResource = await clientService.ApplyClientDefinitionAsync(oauth2ClientSubmit, false, new SecurityContractDryRunResult());

            Assert.True(updateClientResource.Name == oauth2ClientSubmit.Name, $"Retrieved name: {updateClientResource.Name} not the same as the expected name: {oauth2ClientSubmit.Name}");
            Assert.True(updateClientResource.ClientId == oauth2ClientSubmit.ClientId, $"Retrieved clientId: {updateClientResource.ClientId} not the same as the expected name: {oauth2ClientSubmit.ClientId}");
            Assert.True(updateClientResource.AllowedOfflineAccess == true, $"Retrieved allowedOfflineAccess: {updateClientResource.AllowedOfflineAccess} not the expeced value: true");
            Assert.True(updateClientResource.AllowedGrantTypes.First() == oauth2ClientSubmit.AllowedGrantTypes.First(), $"Retrieved allowedGrantTypes first element: {updateClientResource.AllowedGrantTypes.First()} not the expected value: {oauth2ClientSubmit.AllowedGrantTypes.First()}");
            Assert.True(updateClientResource.AllowedCorsOrigins.First() == oauth2ClientSubmit.AllowedCorsOrigins.First(), $"Retrieved allowedCorsOrigins first element: {updateClientResource.AllowedCorsOrigins.First()} not the expected value: {oauth2ClientSubmit.AllowedCorsOrigins.First()}");
            Assert.True(updateClientResource.PostLogoutRedirectUris.First() == oauth2ClientSubmit.PostLogoutRedirectUris.First(), $"Retrieved PostLogoutRedirectUris first element: {updateClientResource.PostLogoutRedirectUris.First()} not the expected value: {oauth2ClientSubmit.PostLogoutRedirectUris.First()}");
            Assert.True(updateClientResource.AllowedScopes.First() == oauth2ClientSubmit.AllowedScopes.First(), $"Retrieved AllowedScopes first element: {updateClientResource.AllowedScopes.First()} not the expected value: {oauth2ClientSubmit.AllowedScopes.First()}");
            Assert.True(updateClientResource.RedirectUris.First() == oauth2ClientSubmit.RedirectUris.First(), $"Retrieved RedirectUris first element: {updateClientResource.RedirectUris.First()} not the expected value: {oauth2ClientSubmit.RedirectUris.First()}");
        }
Exemple #4
0
        public async Task ApplyClientDefninition_WhitespaceAllowedCorsOriginArrayMember_ReturnsInvalidFormatException()
        {
            var clientRespository = Substitute.For <IIdentityClientRepository>();

            // The service will look for an existing client by it's ID, return null to trigger the client creation flow.
            clientRespository.GetByClientIdAsync(Arg.Any <string>()).Returns(mockedClientEntity);
            clientRespository.UpdateAsync(Arg.Any <Client>()).Returns(mockedClientEntity);

            var clientService         = new SecurityContractClientService(clientRespository, mapper);
            var oauthClientSubmitMock = oauth2ClientSubmit;

            // Set the allowed CORS orgin array member to an empty string field. This should throw a v
            oauthClientSubmitMock.AllowedCorsOrigins = new List <string> {
                "    "
            };
            try
            {
                var updateClientResource = await clientService.ApplyClientDefinitionAsync(oauth2ClientSubmit, false, new SecurityContractDryRunResult());
            }
            catch (Exception e)
            {
                Assert.True(e is InvalidFormatException);
            }
        }