public void CannotRemoveAdminRole() { // arrange var httpClient = new RolesHttpClient(this.Authority, this.Handler); var role = "admin"; // act Func <Task> func = async() => await httpClient.RemoveRoleAsync(role).ConfigureAwait(false); // assert func.Should().Throw <HttpException>().And.StatusCode.Should().Be(HttpStatusCode.BadRequest); }
public async Task CannotAddDuplicateRole() { // arrange var httpClient = new RolesHttpClient(this.Authority, this.Handler); var role = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); await httpClient.AddRoleAsync(role).ConfigureAwait(false); // act Func <Task> func = async() => await httpClient.AddRoleAsync(role).ConfigureAwait(false); // assert func.Should().Throw <HttpException>().And.StatusCode.Should().Be(HttpStatusCode.Conflict); }
public async Task CanAddRole() { // arrange var httpClient = new RolesHttpClient(this.Authority, this.Handler); var role = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); // act await httpClient.AddRoleAsync(role).ConfigureAwait(false); // assert var roleExists = await httpClient.RoleExistsAsync(role).ConfigureAwait(false); roleExists.Should().BeTrue(); }
public async Task CanGetRoleSummaries() { // arrange var httpClient = new RolesHttpClient(this.Authority, this.Handler); var role = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); await httpClient.AddRoleAsync(role).ConfigureAwait(false); // act var roles = await httpClient.GetRolesAsync().ConfigureAwait(false); // assert roles.Should().NotBeNull(); roles.Should().Contain(role); }
public async Task CanGetRoleSummariesWithQuery() { // arrange var httpClient = new RolesHttpClient(this.Authority, this.Handler); var role1 = "query"; var role2 = "query_test_02"; var role3 = "query_test_03"; await httpClient.AddRoleAsync(role1).ConfigureAwait(false); await httpClient.AddRoleAsync(role2).ConfigureAwait(false); await httpClient.AddRoleAsync(role3).ConfigureAwait(false); // act var roles = await httpClient.GetRolesAsync("query_").ConfigureAwait(false); // assert roles.Should().NotBeNull(); roles.Should().HaveCount(2); roles.Should().Contain(new[] { role2, role3 }); }
public async Task <int> TryRunAsync(string[] args) { CommandLineOptions options; try { options = CommandLineOptions.Parse(args, this.console); } catch (CommandParsingException ex) { new ConsoleReporter(this.console).Warn(ex.Message); return(1); } if (options == null) { return(1); } if (options.Help.HasValue()) { return(2); } if (options.Command == null) { return(3); } var repository = new CommandDataRepository(this.provider); if (options.Command is LoginCommand.Reset) { await options.Command.ExecuteAsync(new CommandContext(this.console, null, null, null, null, null, null, repository)).ConfigureAwait(false); return(0); } var data = repository.GetCommandData() ?? new CommandData { Authority = LoginCommand.ProductionAuthority, }; var authority = data.Authority; if (options.Command is LoginCommand loginCommand) { authority = loginCommand.Authority; } else { this.console.Write("Executing command against "); this.console.ForegroundColor = ConsoleColor.White; this.console.Write(authority); this.console.ResetColor(); this.console.WriteLine("..."); } var discoveryResponse = default(DiscoveryResponse); using (var discoveryClient = new DiscoveryClient(authority)) { discoveryResponse = await discoveryClient.GetAsync().ConfigureAwait(false); if (discoveryResponse.IsError) { await this.console.Error.WriteLineAsync(discoveryResponse.Error).ConfigureAwait(false); return(500); } } using (var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, "auth_console")) using (var refreshTokenHandler = new RefreshTokenHandler(tokenClient, data.RefreshToken, data.AccessToken)) using (var clientsClient = new ClientsHttpClient(authority, refreshTokenHandler)) using (var apiResourcesClient = new ApiResourcesHttpClient(authority, refreshTokenHandler)) using (var identityResourcesClient = new IdentityResourcesHttpClient(authority, refreshTokenHandler)) using (var rolesClient = new RolesHttpClient(authority, refreshTokenHandler)) using (var usersClient = new UsersHttpClient(authority, refreshTokenHandler)) { refreshTokenHandler.TokenRefreshed += (sender, e) => { repository.SetCommandData( new CommandData { Authority = authority, AccessToken = e.AccessToken, RefreshToken = e.RefreshToken, }); }; var reporter = new ConsoleReporter(this.console, options.Verbose.HasValue(), false); var context = new CommandContext(this.console, reporter, clientsClient, apiResourcesClient, identityResourcesClient, rolesClient, usersClient, repository); try { await options.Command.ExecuteAsync(context).ConfigureAwait(false); } catch (Exception ex) { reporter.Error(ex.Message); return(500); } finally { this.console.ResetColor(); } return(0); } }