Search in sources :

Example 6 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class AddActionTest method addSecretCanAssignGroup.

@Test
public void addSecretCanAssignGroup() throws Exception {
    addActionConfig.addType = Arrays.asList("secret");
    addActionConfig.name = secret.getDisplayName();
    addActionConfig.group = group.getName();
    byte[] content = base64Decoder.decode(secret.getSecret());
    addAction.stream = new ByteArrayInputStream(content);
    when(keywhizClient.getGroupByName(group.getName())).thenReturn(group);
    when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
    new NotFoundException());
    when(keywhizClient.createSecret(secret.getName(), "", content, secret.getMetadata(), 0)).thenReturn(secretDetailResponse);
    addAction.run();
    verify(keywhizClient).grantSecretToGroupByIds(secret.getId(), group.getId());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Example 7 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class AddActionTest method addThrowsIfMetadataHasBadKeys.

@Test(expected = IllegalArgumentException.class)
public void addThrowsIfMetadataHasBadKeys() throws Exception {
    addActionConfig.addType = Arrays.asList("secret");
    addActionConfig.name = secret.getDisplayName();
    addActionConfig.json = "{\"ThisIsABadKey\":\"doh\"}";
    addAction.stream = new ByteArrayInputStream(base64Decoder.decode(secret.getSecret()));
    when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
    new NotFoundException());
    addAction.run();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Example 8 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class AddActionTest method addCreatesWithoutVersionByDefault.

@Test
public void addCreatesWithoutVersionByDefault() throws Exception {
    addActionConfig.addType = Arrays.asList("secret");
    // Name without version
    addActionConfig.name = secret.getName();
    byte[] content = base64Decoder.decode(secret.getSecret());
    addAction.stream = new ByteArrayInputStream(content);
    when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
    new NotFoundException());
    when(keywhizClient.createSecret(secret.getName(), "", content, secret.getMetadata(), 0)).thenReturn(secretDetailResponse);
    addAction.run();
    verify(keywhizClient, times(1)).createSecret(secret.getName(), "", content, secret.getMetadata(), 0);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Example 9 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class DeleteActionTest method deleteThrowsIfDeleteSecretFails.

@Test(expected = AssertionError.class)
public void deleteThrowsIfDeleteSecretFails() throws Exception {
    deleteActionConfig.deleteType = Arrays.asList("secret");
    deleteActionConfig.name = secret.getDisplayName();
    when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(new NotFoundException());
    deleteAction.run();
}
Also used : NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Example 10 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class DescribeActionTest method describeThrowsIfGroupDoesNotExist.

@Test(expected = AssertionError.class)
public void describeThrowsIfGroupDoesNotExist() throws Exception {
    describeActionConfig.describeType = Arrays.asList("group");
    describeActionConfig.name = "nonexistent-group-name";
    when(keywhizClient.getGroupByName(anyString())).thenThrow(new NotFoundException());
    describeAction.run();
}
Also used : NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (keywhiz.client.KeywhizClient.NotFoundException)23 Test (org.junit.Test)18 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)5 SanitizedSecret (keywhiz.api.model.SanitizedSecret)5 Client (keywhiz.api.model.Client)4 KeywhizClient (keywhiz.client.KeywhizClient)4 Group (keywhiz.api.model.Group)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2