Search in sources :

Example 6 with SanitizedSecret

use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.

the class AclDAOTest method getSanitizedSecretsForClient.

@Test
public void getSanitizedSecretsForClient() {
    assertThat(aclDAO.getSanitizedSecretsFor(client2)).isEmpty();
    aclDAO.enrollClient(jooqContext.configuration(), client2.getId(), group2.getId());
    aclDAO.allowAccess(jooqContext.configuration(), secret2.getId(), group2.getId());
    Set<SanitizedSecret> secrets = aclDAO.getSanitizedSecretsFor(client2);
    assertThat(Iterables.getOnlyElement(secrets)).isEqualToIgnoringGivenFields(SanitizedSecret.fromSecret(secret2), "id", "version");
    aclDAO.allowAccess(jooqContext.configuration(), secret1.getId(), group2.getId());
    secrets = aclDAO.getSanitizedSecretsFor(client2);
    assertThat(secrets).hasSize(2).doesNotHaveDuplicates();
    for (SanitizedSecret secret : secrets) {
        if (secret.name().equals(secret1.getName())) {
            assertThat(secret).isEqualToIgnoringGivenFields(SanitizedSecret.fromSecret(secret1), "id", "version");
        } else {
            assertThat(secret).isEqualToIgnoringGivenFields(SanitizedSecret.fromSecret(secret2), "id", "version");
        }
    }
    aclDAO.evictClient(jooqContext.configuration(), client2.getId(), group2.getId());
    assertThat(aclDAO.getSanitizedSecretsFor(client2)).isEmpty();
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) Test(org.junit.Test)

Example 7 with SanitizedSecret

use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.

the class AclDAOTest method getsSanitizedSecretsForGroup.

@Test
public void getsSanitizedSecretsForGroup() {
    SanitizedSecret sanitizedSecret1 = SanitizedSecret.fromSecret(secret1);
    SanitizedSecret sanitizedSecret2 = SanitizedSecret.fromSecret(secret2);
    aclDAO.allowAccess(jooqContext.configuration(), secret2.getId(), group1.getId());
    Set<SanitizedSecret> secrets = aclDAO.getSanitizedSecretsFor(group1);
    assertThat(Iterables.getOnlyElement(secrets)).isEqualToIgnoringGivenFields(sanitizedSecret2, "id", "version");
    aclDAO.allowAccess(jooqContext.configuration(), secret1.getId(), group1.getId());
    secrets = aclDAO.getSanitizedSecretsFor(group1);
    assertThat(secrets).hasSize(2).doesNotHaveDuplicates();
    for (SanitizedSecret secret : secrets) {
        if (secret.name().equals(secret1.getName())) {
            assertThat(secret).isEqualToIgnoringGivenFields(sanitizedSecret1, "id", "version");
        } else {
            assertThat(secret).isEqualToIgnoringGivenFields(sanitizedSecret2, "id", "version");
        }
    }
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) Test(org.junit.Test)

Example 8 with SanitizedSecret

use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.

the class SecretResourceTest method secretListing_success.

// ---------------------------------------------------------------------------------------
// secretListing
// ---------------------------------------------------------------------------------------
@Test
public void secretListing_success() throws Exception {
    // Listing without secret16
    assertThat(listing()).doesNotContain("secret16");
    // Sample secret
    create(CreateSecretRequestV2.builder().name("secret16").description("test secret 16").content(encoder.encodeToString("supa secret16".getBytes(UTF_8))).build());
    // Listing with secret16
    assertThat(listing()).contains("secret16");
    List<SanitizedSecret> secrets = listingV2();
    boolean found = false;
    for (SanitizedSecret s : secrets) {
        if (s.name().equals("secret16")) {
            found = true;
            assertThat(s.description()).isEqualTo("test secret 16");
        }
    }
    assertThat(found).isTrue();
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) Test(org.junit.Test)

Example 9 with SanitizedSecret

use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.

the class AutomationGroupResourceTest method groupIncludesClientsAndSecrets.

@Test
public void groupIncludesClientsAndSecrets() {
    Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz"));
    Client groupClient = new Client(1, "firstClient", "Group client", null, now, "test", now, "test", null, null, true, true);
    SanitizedSecret firstGroupSecret = SanitizedSecret.of(1, "name1", null, "desc", "checksum", now, "test", now, "test", null, "", null, 1136214245, 125L, now, "test");
    SanitizedSecret secondGroupSecret = SanitizedSecret.of(2, "name2", null, "desc", "checksum", now, "test", now, "test", null, "", null, 1136214245, 250L, now, "test");
    when(groupDAO.getGroup("testGroup")).thenReturn(Optional.of(group));
    when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of(groupClient));
    when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of(firstGroupSecret, secondGroupSecret));
    GroupDetailResponse expectedResponse = GroupDetailResponse.fromGroup(group, ImmutableList.of(firstGroupSecret, secondGroupSecret), ImmutableList.of(groupClient));
    Response response = resource.getGroupByName(automation, Optional.of("testGroup"));
    assertThat(response.getEntity()).isEqualTo(expectedResponse);
}
Also used : Response(javax.ws.rs.core.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Group(keywhiz.api.model.Group) SanitizedSecret(keywhiz.api.model.SanitizedSecret) GroupDetailResponse(keywhiz.api.GroupDetailResponse) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) Test(org.junit.Test)

Example 10 with SanitizedSecret

use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.

the class SecretResourceTest method getSanitizedSecret_success.

@Test
public void getSanitizedSecret_success() throws Exception {
    // Sample secret
    create(CreateSecretRequestV2.builder().name("secret12455").content(encoder.encodeToString("supa secret12455".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build());
    SanitizedSecret response = lookupSanitizedSecret("secret12455");
    assertThat(response.name()).isEqualTo("secret12455");
    assertThat(response.createdBy()).isEqualTo("client");
    assertThat(response.updatedBy()).isEqualTo("client");
    assertThat(response.contentCreatedBy()).isEqualTo("client");
    assertThat(response.description()).isEqualTo("desc");
    assertThat(response.type()).isEqualTo(Optional.of("password"));
    assertThat(response.metadata()).isEqualTo(ImmutableMap.of("owner", "root", "mode", "0440"));
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) Test(org.junit.Test)

Aggregations

SanitizedSecret (keywhiz.api.model.SanitizedSecret)41 Test (org.junit.Test)20 Group (keywhiz.api.model.Group)13 Client (keywhiz.api.model.Client)12 NotFoundException (javax.ws.rs.NotFoundException)10 IOException (java.io.IOException)9 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)7 Timed (com.codahale.metrics.annotation.Timed)7 GET (javax.ws.rs.GET)6 Secret (keywhiz.api.model.Secret)5 KeywhizClient (keywhiz.client.KeywhizClient)5 ImmutableList (com.google.common.collect.ImmutableList)4 SecretDeliveryResponse (keywhiz.api.SecretDeliveryResponse)4 AutomationClient (keywhiz.api.model.AutomationClient)4 NotFoundException (keywhiz.client.KeywhizClient.NotFoundException)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 BatchSecretRequest (keywhiz.api.BatchSecretRequest)3 GroupDetailResponse (keywhiz.api.GroupDetailResponse)3