Example #1
0
        public async Task ShouldDeleteClientSecret()
        {
            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> >();


            httpResponse = await _client.DeleteAsync($"/clients/{newClient.ClientId}/secrets?type={secrets.First().Type.UrlEncode()}&value={Uri.EscapeDataString(secrets.First().Value.UrlEncode())}");

            try { httpResponse.EnsureSuccessStatusCode(); } catch { _output.WriteLine(await httpResponse.Content.ReadAsStringAsync()); throw; };
        }
Example #2
0
        public async Task Should_Not_Add_New_ClientSecret_When_Client_Doesnt_Exist()
        {
            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());
        }
Example #3
0
        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();
        }
Example #4
0
        public async Task ShouldAddNewClientSecret()
        {
            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");
        }
Example #5
0
        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();
        }