use of keywhiz.api.model.Secret in project keywhiz by square.
the class BatchSecretDeliveryResourceIntegrationTest method setUp.
// For declaration of these passwords see file server/src/main/java/keywhiz/commands/DbSeedCommand.java
// DbSeedCommand is invoked via MigrationRule
// TODO(michael): refactor how we test
@Before
public void setUp() throws Exception {
client = TestClients.mutualSslClient();
keywhizClient = TestClients.keywhizClient();
generalPassword = new Secret(0, "General_Password", null, null, () -> "YXNkZGFz", "", ApiDate.parse("2011-09-29T15:46:00Z"), null, ApiDate.parse("2011-09-29T15:46:00Z"), null, null, "upload", null, 0, 1L, ApiDate.parse("2011-09-29T15:46:00Z"), null);
databasePassword = new Secret(1, "Database_Password", null, null, () -> "MTIzNDU=", "", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, null, null, null, 0, 2L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null);
}
use of keywhiz.api.model.Secret in project keywhiz by square.
the class SecretDeliveryResourceTest method returnsSecretWhenAllowed.
@Test
public void returnsSecretWhenAllowed() throws Exception {
Secret secret = new Secret(0, "secret_name", null, null, () -> "unused_secret", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L, NOW, null);
SanitizedSecret sanitizedSecret = SanitizedSecret.fromSecret(secret);
String name = sanitizedSecret.name();
when(aclDAO.getSanitizedSecretFor(client, name)).thenReturn(Optional.of(sanitizedSecret));
when(secretController.getSecretByName(name)).thenReturn(Optional.of(secret));
SecretDeliveryResponse response = secretDeliveryResource.getSecret(sanitizedSecret.name(), client);
assertThat(response).isEqualTo(SecretDeliveryResponse.fromSecret(secret));
}
use of keywhiz.api.model.Secret in project keywhiz by square.
the class SecretDeliveryResourceTest method returnsVersionedSecretWhenAllowed.
@Test
public void returnsVersionedSecretWhenAllowed() throws Exception {
String name = "secret_name";
Secret versionedSecret = new Secret(2, name, null, null, () -> "U3BpZGVybWFu", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L, NOW, null);
when(aclDAO.getSanitizedSecretFor(client, name)).thenReturn(Optional.of(SanitizedSecret.fromSecret(versionedSecret)));
when(secretController.getSecretByName(name)).thenReturn(Optional.of(versionedSecret));
String displayName = versionedSecret.getDisplayName();
SecretDeliveryResponse response = secretDeliveryResource.getSecret(displayName, client);
assertThat(response).isEqualTo(SecretDeliveryResponse.fromSecret(versionedSecret));
}
use of keywhiz.api.model.Secret in project keywhiz by square.
the class SecretsDeliveryResourceIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
client = TestClients.mutualSslClient();
noSecretsClient = TestClients.noSecretsClient();
clientNoClientCert = TestClients.unauthenticatedClient();
generalPassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(0, "General_Password", null, null, () -> "YXNkZGFz", "checksum", ApiDate.parse("2011-09-29T15:46:00.312Z"), null, ApiDate.parse("2011-09-29T15:46:00.312Z"), null, null, null, null, 0, 1L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
databasePassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(1, "Database_Password", null, null, () -> "MTIzNDU=", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, null, null, null, 0, 2L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
nobodyPgPassPassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(2, "Nobody_PgPass", null, null, () -> "c29tZWhvc3Quc29tZXBsYWNlLmNvbTo1NDMyOnNvbWVkYXRhYmFzZTptaXN0ZXJhd2Vzb21lOmhlbGwwTWNGbHkK", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ImmutableMap.of("owner", "nobody", "mode", "0400"), null, null, 0, 3L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
nonExistentOwnerPass = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(3, "NonexistentOwner_Pass", null, null, () -> "MTIzNDU=", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ImmutableMap.of("owner", "NonExistent", "mode", "0400"), null, null, 0, 4L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
}
use of keywhiz.api.model.Secret in project keywhiz by square.
the class ClientsResourceTest method includesAssociations.
@Test
public void includesAssociations() {
Group group1 = new Group(0, "group1", null, null, null, null, null, null);
Group group2 = new Group(0, "group2", null, null, null, null, null, null);
Secret secret = new Secret(15, "secret", null, null, () -> "supersecretdata", "checksum", now, "creator", now, "updater", null, null, null, 0, 1L, now, "updater");
when(clientDAO.getClientById(1)).thenReturn(Optional.of(client));
when(aclDAO.getGroupsFor(client)).thenReturn(Sets.newHashSet(group1, group2));
when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of(SanitizedSecret.fromSecret(secret)));
ClientDetailResponse response = resource.getClient(user, new LongParam("1"));
assertThat(response.groups).containsOnly(group1, group2);
assertThat(response.secrets).containsOnly(SanitizedSecret.fromSecret(secret));
}
Aggregations