use of keywhiz.api.CreateClientRequest in project keywhiz by square.
the class KeywhizClient method createClient.
public ClientDetailResponse createClient(String name) throws IOException {
checkArgument(!name.isEmpty());
String response = httpPost(baseUrl.resolve("/admin/clients"), new CreateClientRequest(name));
return mapper.readValue(response, ClientDetailResponse.class);
}
use of keywhiz.api.CreateClientRequest in project keywhiz by square.
the class AutomationClientResourceIntegrationTest method addClients.
@Test
public void addClients() throws Exception {
CreateClientRequest request = new CreateClientRequest("User1");
String requestJSON = mapper.writeValueAsString(request);
RequestBody body = RequestBody.create(KeywhizClient.JSON, requestJSON);
Request post = new Request.Builder().post(body).url(testUrl("/automation/clients")).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(200);
}
use of keywhiz.api.CreateClientRequest in project keywhiz by square.
the class AutomationClientResourceIntegrationTest method addClientRedundant.
@Test
public void addClientRedundant() throws Exception {
CreateClientRequest request = new CreateClientRequest("CN=User1");
String json = mapper.writeValueAsString(request);
Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, json)).url(testUrl("/automation/clients")).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(409);
}
use of keywhiz.api.CreateClientRequest in project keywhiz by square.
the class AutomationClientResourceTest method createNewClient.
@Test
public void createNewClient() {
Client client = new Client(543L, "client", "2nd client", null, now, "test", now, "test", null, null, true, false);
CreateClientRequest request = new CreateClientRequest("client");
when(clientDAO.getClientByName("client")).thenReturn(Optional.empty());
when(clientDAO.createClient("client", automation.getName(), "", null)).thenReturn(543L);
when(clientDAO.getClientById(543L)).thenReturn(Optional.of(client));
when(aclDAO.getGroupsFor(client)).thenReturn(ImmutableSet.of());
ClientDetailResponse response = ClientDetailResponse.fromClient(client, ImmutableList.of(), ImmutableList.of());
ClientDetailResponse response1 = resource.createClient(automation, request);
assertThat(response.name).isEqualTo(response1.name);
}
use of keywhiz.api.CreateClientRequest in project keywhiz by square.
the class AutomationClientResourceTest method createNewClientAlreadyExists.
@Test
public void createNewClientAlreadyExists() {
Client client = new Client(543L, "client", "2nd client", null, now, "test", now, "test", null, null, true, false);
CreateClientRequest request = new CreateClientRequest("client");
when(clientDAO.getClientByName("client")).thenReturn(Optional.empty());
when(clientDAO.createClient("client", automation.getName(), "", null)).thenReturn(543L);
when(clientDAO.getClientById(543L)).thenReturn(Optional.of(client));
ClientDetailResponse response = ClientDetailResponse.fromClient(client, ImmutableList.of(), ImmutableList.of());
ClientDetailResponse response1 = resource.createClient(automation, request);
assertThat(response.name).isEqualTo(response1.name);
}
Aggregations