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);
}
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);
}
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)));
}
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);
}
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");
}
Aggregations