Search in sources :

Example 6 with ClientDetailResponse

use of keywhiz.api.ClientDetailResponse in project keywhiz by square.

the class AutomationClientResourceTest method createNewClientAlreadyExists.

@Test
public void createNewClientAlreadyExists() {
    Client client = new Client(543L, "client", "2nd client", now, "test", now, "test", null, true, false);
    CreateClientRequest request = new CreateClientRequest("client");
    when(clientDAO.getClient("client")).thenReturn(Optional.empty());
    when(clientDAO.createClient("client", automation.getName(), "")).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)

Example 7 with ClientDetailResponse

use of keywhiz.api.ClientDetailResponse in project keywhiz by square.

the class AutomationClientResourceTest method createNewClient.

@Test
public void createNewClient() {
    Client client = new Client(543L, "client", "2nd client", now, "test", now, "test", null, true, false);
    CreateClientRequest request = new CreateClientRequest("client");
    when(clientDAO.getClient("client")).thenReturn(Optional.empty());
    when(clientDAO.createClient("client", automation.getName(), "")).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 8 with ClientDetailResponse

use of keywhiz.api.ClientDetailResponse in project keywhiz by square.

the class Printing method printClientWithDetails.

public void printClientWithDetails(Client client) {
    System.out.println(client.getName());
    ClientDetailResponse clientDetails;
    try {
        clientDetails = keywhizClient.clientDetailsForId(client.getId());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    if (clientDetails.lastSeen == null) {
        System.out.println("\tLast Seen: never");
    } else {
        String lastSeen = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date(clientDetails.lastSeen.toEpochSecond() * 1000));
        System.out.printf("\tLast Seen: %s%n", lastSeen);
    }
    System.out.println("\tGroups:");
    clientDetails.groups.stream().sorted(Comparator.comparing(Group::getName)).forEach(g -> System.out.println(INDENT + g.getName()));
    System.out.println("\tSecrets:");
    clientDetails.secrets.stream().sorted(Comparator.comparing(SanitizedSecret::name)).forEach(s -> System.out.println(INDENT + SanitizedSecret.displayName(s)));
}
Also used : Group(keywhiz.api.model.Group) SanitizedSecret(keywhiz.api.model.SanitizedSecret) IOException(java.io.IOException) ClientDetailResponse(keywhiz.api.ClientDetailResponse) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with ClientDetailResponse

use of keywhiz.api.ClientDetailResponse in project keywhiz by square.

the class AutomationClientResourceTest method findClientByName.

@Test
public void findClientByName() {
    Client client = new Client(2, "client", "2nd client", now, "test", now, "test", null, true, false);
    Group firstGroup = new Group(1, "first Group", "testing group", now, "client", now, "client", ImmutableMap.of("app", "keywhiz"));
    Group secondGroup = new Group(2, "second Group", "testing group", now, "client", now, "client", ImmutableMap.of("app", "keywhiz"));
    ClientDetailResponse expectedClient = ClientDetailResponse.fromClient(client, ImmutableList.of(firstGroup, secondGroup), ImmutableList.of());
    when(clientDAO.getClient("client")).thenReturn(Optional.of(client));
    when(aclDAO.getGroupsFor(client)).thenReturn(ImmutableSet.of(firstGroup, secondGroup));
    Response response = resource.findClient(automation, Optional.of("client"));
    assertThat(response.getEntity()).hasSameClassAs(expectedClient);
    ClientDetailResponse actualResponse = (ClientDetailResponse) response.getEntity();
    assertThat(actualResponse).isEqualToComparingFieldByField(expectedClient);
}
Also used : ClientDetailResponse(keywhiz.api.ClientDetailResponse) Response(javax.ws.rs.core.Response) Group(keywhiz.api.model.Group) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) ClientDetailResponse(keywhiz.api.ClientDetailResponse) Test(org.junit.Test)

Example 10 with ClientDetailResponse

use of keywhiz.api.ClientDetailResponse in project keywhiz by square.

the class ClientsResourceIntegrationTest method createsClient.

@Test
public void createsClient() throws IOException {
    keywhizClient.login(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword.toCharArray());
    assertThat(clientsToNames(keywhizClient.allClients())).doesNotContain("kingpin");
    ClientDetailResponse clientDetails = keywhizClient.createClient("kingpin");
    assertThat(clientDetails.name).isEqualTo("kingpin");
    assertThat(clientsToNames(keywhizClient.allClients())).contains("kingpin");
}
Also used : ClientDetailResponse(keywhiz.api.ClientDetailResponse) Test(org.junit.Test)

Aggregations

ClientDetailResponse (keywhiz.api.ClientDetailResponse)10 Test (org.junit.Test)8 LongParam (io.dropwizard.jersey.params.LongParam)4 AutomationClient (keywhiz.api.model.AutomationClient)4 Client (keywhiz.api.model.Client)4 Group (keywhiz.api.model.Group)4 CreateClientRequest (keywhiz.api.CreateClientRequest)3 Response (javax.ws.rs.core.Response)2 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 Auth (io.dropwizard.auth.Auth)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1