Search in sources :

Example 6 with GroupDetailResponse

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

the class GroupsResourceIntegrationTest method createsGroup.

@Test
public void createsGroup() throws IOException {
    keywhizClient.login(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword.toCharArray());
    GroupDetailResponse groupDetails = keywhizClient.createGroup("NewGroup", "", ImmutableMap.of("app", "NewApp"));
    assertThat(groupDetails.getName()).isEqualTo("NewGroup");
    List<Group> groups = keywhizClient.allGroups();
    List<String> names = Lists.transform(groups, new Function<Group, String>() {

        @Override
        public String apply(@Nullable Group group) {
            return (group == null) ? null : group.getName();
        }
    });
    assertThat(names).contains("NewGroup");
}
Also used : Group(keywhiz.api.model.Group) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Test(org.junit.Test)

Example 7 with GroupDetailResponse

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

the class AutomationGroupResourceIntegrationTest method findGroup.

@Test
public void findGroup() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/automation/groups?name=Web")).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();
    Response response = mutualSslClient.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);
    GroupDetailResponse groupResponse = mapper.readValue(response.body().string(), GroupDetailResponse.class);
    assertThat(groupResponse.getId()).isEqualTo(918);
}
Also used : Response(okhttp3.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Request(okhttp3.Request) CreateGroupRequest(keywhiz.api.CreateGroupRequest) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Test(org.junit.Test)

Example 8 with GroupDetailResponse

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

the class AutomationGroupResourceIntegrationTest method findAllGroups.

@Test
public void findAllGroups() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/automation/groups")).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();
    Response response = mutualSslClient.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);
    List<GroupDetailResponse> groups = mapper.readValue(response.body().string(), new TypeReference<List<GroupDetailResponse>>() {
    });
    assertThat(groups).extracting("name").contains("Blackops", "Security", "Web", "iOS");
}
Also used : Response(okhttp3.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Request(okhttp3.Request) CreateGroupRequest(keywhiz.api.CreateGroupRequest) GroupDetailResponse(keywhiz.api.GroupDetailResponse) List(java.util.List) Test(org.junit.Test)

Example 9 with GroupDetailResponse

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

the class GroupsResourceIntegrationTest method getGroupInfo.

@Test
public void getGroupInfo() throws IOException {
    keywhizClient.login(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword.toCharArray());
    GroupDetailResponse groupDetail = keywhizClient.groupDetailsForId(916);
    assertThat(groupDetail.getName()).isEqualTo("Blackops");
}
Also used : GroupDetailResponse(keywhiz.api.GroupDetailResponse) Test(org.junit.Test)

Example 10 with GroupDetailResponse

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

the class GroupsResourceTest method getSpecificIncludesAllTheThings.

@Test
public void getSpecificIncludesAllTheThings() {
    when(groupDAO.getGroupById(4444)).thenReturn(Optional.of(group));
    SanitizedSecret secret = SanitizedSecret.of(1, "name", "checksum", null, now, "creator", now, "creator", null, null, null, 1136214245, 125L);
    when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of(secret));
    Client client = new Client(1, "client", "desc", now, "creator", now, "creator", null, true, false);
    when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of(client));
    GroupDetailResponse response = resource.getGroup(user, new LongParam("4444"));
    assertThat(response.getId()).isEqualTo(group.getId());
    assertThat(response.getName()).isEqualTo(group.getName());
    assertThat(response.getDescription()).isEqualTo(group.getDescription());
    assertThat(response.getCreationDate()).isEqualTo(group.getCreatedAt());
    assertThat(response.getCreatedBy()).isEqualTo(group.getCreatedBy());
    assertThat(response.getUpdateDate()).isEqualTo(group.getUpdatedAt());
    assertThat(response.getUpdatedBy()).isEqualTo(group.getUpdatedBy());
    assertThat(response.getSecrets()).containsExactly(secret);
    assertThat(response.getClients()).containsExactly(client);
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) GroupDetailResponse(keywhiz.api.GroupDetailResponse) LongParam(io.dropwizard.jersey.params.LongParam) Client(keywhiz.api.model.Client) Test(org.junit.Test)

Aggregations

GroupDetailResponse (keywhiz.api.GroupDetailResponse)10 Test (org.junit.Test)8 Group (keywhiz.api.model.Group)5 Client (keywhiz.api.model.Client)4 SanitizedSecret (keywhiz.api.model.SanitizedSecret)4 LongParam (io.dropwizard.jersey.params.LongParam)3 Response (javax.ws.rs.core.Response)3 CreateGroupRequest (keywhiz.api.CreateGroupRequest)3 List (java.util.List)2 AutomationClient (keywhiz.api.model.AutomationClient)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 Auth (io.dropwizard.auth.Auth)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1