Search in sources :

Example 1 with CreateClientRequest

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);
}
Also used : CreateClientRequest(keywhiz.api.CreateClientRequest)

Example 2 with CreateClientRequest

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);
}
Also used : ClientDetailResponse(keywhiz.api.ClientDetailResponse) Response(okhttp3.Response) CreateClientRequest(keywhiz.api.CreateClientRequest) Request(okhttp3.Request) CreateClientRequest(keywhiz.api.CreateClientRequest) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 3 with CreateClientRequest

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);
}
Also used : ClientDetailResponse(keywhiz.api.ClientDetailResponse) Response(okhttp3.Response) CreateClientRequest(keywhiz.api.CreateClientRequest) Request(okhttp3.Request) CreateClientRequest(keywhiz.api.CreateClientRequest) Test(org.junit.Test)

Example 4 with CreateClientRequest

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);
}
Also used : CreateClientRequest(keywhiz.api.CreateClientRequest) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) ClientDetailResponse(keywhiz.api.ClientDetailResponse) Test(org.junit.Test)

Example 5 with CreateClientRequest

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);
}
Also used : CreateClientRequest(keywhiz.api.CreateClientRequest) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) ClientDetailResponse(keywhiz.api.ClientDetailResponse) Test(org.junit.Test)

Aggregations

CreateClientRequest (keywhiz.api.CreateClientRequest)6 ClientDetailResponse (keywhiz.api.ClientDetailResponse)5 Test (org.junit.Test)5 Request (okhttp3.Request)3 Response (okhttp3.Response)3 AutomationClient (keywhiz.api.model.AutomationClient)2 Client (keywhiz.api.model.Client)2 RequestBody (okhttp3.RequestBody)1