Search in sources :

Example 26 with SecretSeriesAndContent

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

the class SecretDAOTest method createOrUpdateSecretWhenSecretExists.

@Test
public void createOrUpdateSecretWhenSecretExists() {
    String name = "newSecret";
    long firstId = secretDAO.createSecret(name, null, "content1", cryptographer.computeHmac("content1".getBytes(UTF_8), "hmackey"), "creator1", ImmutableMap.of("foo", "bar"), 1000, "description1", "type1", ImmutableMap.of());
    long secondId = secretDAO.createOrUpdateSecret(name, null, "content2", cryptographer.computeHmac("content2".getBytes(UTF_8), "hmackey"), "creator2", ImmutableMap.of("foo2", "bar2"), 2000, "description2", "type2", ImmutableMap.of());
    assertThat(secondId).isEqualTo(firstId);
    SecretSeriesAndContent newSecret = secretDAO.getSecretById(firstId).get();
    assertThat(newSecret.series().createdBy()).isEqualTo("creator1");
    assertThat(newSecret.series().updatedBy()).isEqualTo("creator2");
    assertThat(newSecret.series().description()).isEqualTo("description2");
    assertThat(newSecret.series().type().get()).isEqualTo("type2");
    assertThat(newSecret.content().createdBy()).isEqualTo("creator2");
    assertThat(newSecret.content().encryptedContent()).isEqualTo("content2");
    assertThat(newSecret.content().metadata()).isEqualTo(ImmutableMap.of("foo2", "bar2"));
}
Also used : SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Aggregations

SecretSeriesAndContent (keywhiz.api.model.SecretSeriesAndContent)26 Test (org.junit.Test)16 SecretContent (keywhiz.api.model.SecretContent)9 SecretSeries (keywhiz.api.model.SecretSeries)8 ImmutableList (com.google.common.collect.ImmutableList)5 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3 Timed (com.codahale.metrics.annotation.Timed)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 NotFoundException (javax.ws.rs.NotFoundException)2 Produces (javax.ws.rs.Produces)2 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 Secret (keywhiz.api.model.Secret)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ArrayList (java.util.ArrayList)1