public async Task ShouldDeleteClientProperties() { await Login(); var newClient = await AddClient(); var newProperty = ClientViewModelFaker.GenerateSaveProperty(newClient.ClientId).Generate(); // Create one var httpResponse = await _client.PostAsync($"/clients/{newClient.ClientId}/properties", new StringContent(newProperty.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/properties"); httpResponse = await _client.GetAsync($"/clients/{newClient.ClientId}/properties"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var properties = stringResponse.FromJson <IEnumerable <ClientPropertyViewModel> >(); httpResponse = await _client.DeleteAsync($"/clients/{newClient.ClientId}/properties/{properties.First().Key}"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; }
public async Task Should_Update_Client() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientPostLogoutRedirectUris.Any().Should().BeTrue(); InMemoryData.DetachAll(); var updateCommand = ClientFaker.GenerateClient().Generate(); await _clientAppService.Update(command.ClientId, updateCommand); var updatedClient = await _clientAppService.GetClientDetails(updateCommand.ClientId); updatedClient.AllowedCorsOrigins.Should().Contain(s => updateCommand.AllowedCorsOrigins.Contains(s)); updatedClient.AllowedCorsOrigins.Count.Should().Be(updatedClient.AllowedCorsOrigins.Count); updatedClient.ClientSecrets.Should().Contain(s => updateCommand.ClientSecrets.Contains(s)); updatedClient.ClientSecrets.Count.Should().Be(updatedClient.ClientSecrets.Count); updatedClient.AllowedScopes.Should().Contain(s => updateCommand.AllowedScopes.Contains(s)); updatedClient.AllowedScopes.Count.Should().Be(updatedClient.AllowedScopes.Count); }
public async Task ShouldDeleteClientClaims() { await Login(); var newClient = await AddClient(); var claim = ClientViewModelFaker.GenerateSaveClaim(newClient.ClientId).Generate(); // Create one var httpResponse = await _client.PostAsync($"/clients/{newClient.ClientId}/claims", new StringContent(claim.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/claims"); httpResponse = await _client.GetAsync($"/clients/{newClient.ClientId}/claims"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var claims = stringResponse.FromJson <IEnumerable <ClaimViewModel> >(); claims.Should().HaveCountGreaterThan(0); httpResponse = await _client.DeleteAsync($"/clients/{newClient.ClientId}/claims?type={claims.First().Type.UrlEncode()}&value={claims.First().Value.UrlEncode()}"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; }
public async Task ShouldListClientSecret() { await Login(); var newClient = await AddClient(); var newSecret = ClientViewModelFaker.GenerateSaveClientSecret(newClient.ClientId).Generate(); // Create one var httpResponse = await _client.PostAsync($"/clients/{newClient.ClientId}/secrets", new StringContent(newSecret.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/secrets"); httpResponse = await _client.GetAsync($"/clients/{newClient.ClientId}/secrets"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var secrets = stringResponse.FromJson <IEnumerable <Secret> >(); secrets.Should().HaveCountGreaterThan(0); }
public async Task Should_Not_Save_Client_With_ClientUri_With_TrailingSlash() { var command = ClientViewModelFaker.GenerateSaveClient(clientUri: $"{_faker.Internet.Url()}/").Generate(); await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().BeNull(); }
public async Task Should_Not_Add_New_ClientClaim_When_Client_Doesnt_Exist() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); var property = ClientViewModelFaker.GenerateSaveClaim(command.ClientId).Generate(); var result = await _clientAppService.SaveClaim(property); _database.ClientClaims.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); result.Should().BeFalse(becauseArgs: _notifications.GetNotificationsByKey()); }
public async Task ShouldNotAddNewClientSecretWhenClientDoesntExist() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); var secret = ClientViewModelFaker.GenerateSaveClientSecret(command.ClientId); var result = await _clientAppService.SaveSecret(secret); _database.ClientSecrets.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); result.Should().BeFalse(becauseArgs: _notifications.GetNotificationsByKey()); }
public async Task Should_Add_Cors(ClientType clientType) { var command = ClientViewModelFaker.GenerateSaveClient(clientType: clientType).Generate(); await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); client.AllowedCorsOrigins.Should().Contain(origin => origin.Origin.Equals(command.ClientUri)); }
private async Task <SaveClientViewModel> AddClient() { var newClient = ClientViewModelFaker.GenerateSaveClient().Generate(); // Create one var httpResponse = await _client.PostAsync("/clients", new StringContent(newClient.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/clients"); return(newClient); }
public async Task Should_Not_Add_Another_Client_With_Same_ClientId() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); var firstCall = await _clientAppService.Save(command); var result = await _clientAppService.Save(command); firstCall.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); result.Should().BeFalse(becauseArgs: _notifications.GetNotificationsByKey()); }
public async Task Should_Add_New_Client() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); _database.ClientPostLogoutRedirectUris.Include(w => w.Client).Where(w => w.Client.ClientId == command.ClientId).Should().NotBeNull(); }
public async Task Should_Add_New_ClientProperty() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var property = ClientViewModelFaker.GenerateSaveProperty(command.ClientId).Generate(); await _clientAppService.SaveProperty(property); _database.Clients.Include(s => s.Properties).FirstOrDefault(s => s.ClientId == command.ClientId)?.Properties.Should().HaveCountGreaterOrEqualTo(1); }
public async Task ShouldAddNewClientClaim() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var property = ClientViewModelFaker.GenerateSaveClaim().Generate(); await _clientAppService.SaveClaim(property); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientClaims.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); }
public async Task Should_Remove_Client() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientPostLogoutRedirectUris.Any().Should().BeTrue(); await _clientAppService.Remove(new RemoveClientViewModel(command.ClientId)); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().BeNull(); }
public async Task Should_Add_Default_LogoutUri_If_Null(ClientType clientType) { var command = ClientViewModelFaker.GenerateSaveClient(clientType: clientType).Generate(); command.LogoutUri = null; await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); client.PostLogoutRedirectUris.Should().Contain(origin => origin.PostLogoutRedirectUri.Equals(command.ClientUri)); }
public async Task Should_Not_Add_New_ClientProperty_When_Client_Doesnt_Exist() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); var property = ClientViewModelFaker.GenerateSaveProperty(command.ClientId).Generate(); var result = await _clientAppService.SaveProperty(property); _notifications.GetNotifications().Select(s => s.Value).ToList().ForEach(_output.WriteLine); _database.ClientProperties.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); result.Should().BeFalse(becauseArgs: _notifications.GetNotificationsByKey()); }
public async Task ShouldAddAlwaysIncludeUserClaimsInIdTokenWhenImplicity(ClientType clientType) { var command = ClientViewModelFaker.GenerateSaveClient(clientType: clientType).Generate(); command.LogoutUri = null; await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); client.AlwaysIncludeUserClaimsInIdToken.Should().BeTrue(); }
public async Task Should_Be_ClientCredentials_Flow(ClientType clientType) { var command = ClientViewModelFaker.GenerateSaveClient(clientType: clientType).Generate(); command.LogoutUri = null; await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); client.AllowedGrantTypes.Select(s => s.GrantType).Should().Contain("client_credentials"); }
public async Task Should_Add_New_ClientSecret() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var secret = ClientViewModelFaker.GenerateSaveClientSecret(command.ClientId).Generate(); await _clientAppService.SaveSecret(secret); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientSecrets.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); }
public async Task ShouldAddNewClientWithoutPostLogoutUri() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); command.LogoutUri = null; await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); _database.Clients.Include(w => w.PostLogoutRedirectUris).FirstOrDefault(w => w.ClientId == command.ClientId) .PostLogoutRedirectUris.Should().BeEmpty(); }
public async Task ShouldAddNewClientClaim() { await Login(); var newClient = await AddClient(); var claim = ClientViewModelFaker.GenerateSaveClaim(newClient.ClientId).Generate(); // Create one var httpResponse = await _client.PostAsync($"/clients/{newClient.ClientId}/claims", new StringContent(claim.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/claims"); }
public async Task Should_Get_ClientClaim() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var property = ClientViewModelFaker.GenerateSaveClaim(command.ClientId).Generate(); await _clientAppService.SaveClaim(property); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); var clams = await _clientAppService.GetClaims(command.ClientId); clams.Should().HaveCountGreaterOrEqualTo(1); }
public async Task Should_Add_Default_Scopes(ClientType clientType, string[] scopeName) { var command = ClientViewModelFaker.GenerateSaveClient(clientType: clientType).Generate(); await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); foreach (var s in scopeName) { client?.AllowedScopes.Should().Contain(scope => scope.Scope.Equals(s)); } }
public async Task ShouldUpdateClient() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientPostLogoutRedirectUris.Any().Should().BeTrue(); InMemoryData.DetachAll(); var updateCommand = ClientFaker.GenerateClient().Generate(); await _clientAppService.Update(command.ClientId, updateCommand); _database.Clients.FirstOrDefault(f => f.ClientId == updateCommand.ClientId).Should().NotBeNull(); }
public async Task Should_Add_ClientServer() { var command = ClientViewModelFaker.GenerateSaveClient(clientType: ClientType.Machine).Generate(); command.ClientUri = null; command.LogoUri = null; command.LogoutUri = null; await _clientAppService.Save(command); var client = _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId); client.Should().NotBeNull(); client.RedirectUris.Should().BeEmpty(); client.RequireConsent.Should().BeFalse(); }
public async Task Should_Remove_ClientSecret() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var secret = ClientViewModelFaker.GenerateSaveClientSecret(command.ClientId).Generate(); await _clientAppService.SaveSecret(secret); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); _database.ClientSecrets.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId).Should().NotBeNull(); var dbSecret = _database.ClientSecrets.Include(c => c.Client).FirstOrDefault(s => s.Client.ClientId == command.ClientId); var commandRemoveSecret = new RemoveClientSecretViewModel(command.ClientId, secret.Type, dbSecret.Value); var result = await _clientAppService.RemoveSecret(commandRemoveSecret); result.Should().BeTrue(); }
public async Task ShouldUpdateClientId() { await Login(); var newClient = ClientViewModelFaker.GenerateSaveClient().Generate(); // Create one var httpResponse = await _client.PostAsync("/clients", new StringContent(newClient.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/clients"); var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var client = stringResponse.FromJson <Client>(); // Update it var oldClientId = client.ClientId; client.AllowedGrantTypes = new[] { GrantType.ClientCredentials }; client.ClientId = "newclient"; httpResponse = await _client.PutAsync($"/clients/{oldClientId}", new StringContent(client.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Get updated httpResponse = await _client.GetAsync($"/clients/{client.ClientId}"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Deserialize and examine results. stringResponse = await httpResponse.Content.ReadAsStringAsync(); var clients = stringResponse.FromJson <Client>(); clients.Should().NotBeNull(); clients.ClientId.Should().Be(client.ClientId); }
public async Task Should_Remove_ClientClaim() { var command = ClientViewModelFaker.GenerateSaveClient().Generate(); await _clientAppService.Save(command); var property = ClientViewModelFaker.GenerateSaveClaim(command.ClientId).Generate(); await _clientAppService.SaveClaim(property); _database.Clients.FirstOrDefault(s => s.ClientId == command.ClientId).Should().NotBeNull(); var clams = _database.ClientClaims.Include(i => i.Client).Where(f => f.Client.ClientId == command.ClientId); clams.Should().HaveCountGreaterOrEqualTo(1); var removeClaim = new RemoveClientClaimViewModel(command.ClientId, property.Type, property.Value); await _clientAppService.RemoveClaim(removeClaim); var clientDb = await _database.Clients.Include(s => s.Claims).FirstOrDefaultAsync(s => s.ClientId == command.ClientId); clientDb.Claims.Should().BeEmpty(); }
public async Task ShouldGetClient() { await Login(); var client = ClientViewModelFaker.GenerateSaveClient().Generate(); var httpResponse = await _client.PostAsync("/clients", new StringContent(client.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; throw; }; httpResponse.Headers.Location.Should().NotBeNull(); httpResponse.Headers.Location.PathAndQuery.Should().Contain("/clients"); httpResponse = await _client.GetAsync($"/clients/{client.ClientId}"); try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; }; // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var clients = stringResponse.FromJson <Client>(); clients.Should().NotBeNull(); }