Search in sources :

Example 6 with SecureKeyCreateRequest

use of io.cdap.cdap.proto.security.SecureKeyCreateRequest in project cdap by caskdata.

the class SecureStoreClientTest method testSecureKeys.

@Test
public void testSecureKeys() throws Exception {
    // no secure keys to begin with
    List<SecureStoreMetadata> secureKeys = client.listKeys(NamespaceId.DEFAULT);
    Assert.assertTrue(secureKeys.isEmpty());
    // create a key
    String key = "securekey";
    String desc = "SomeDesc";
    String data = "secureData";
    Map<String, String> properties = ImmutableMap.of("k1", "v1");
    long creationTime = System.currentTimeMillis();
    SecureKeyId secureKeyId = new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), key);
    client.createKey(secureKeyId, new SecureKeyCreateRequest(desc, data, properties));
    Assert.assertEquals(data, client.getData(secureKeyId));
    Assert.assertEquals(1, client.listKeys(NamespaceId.DEFAULT).size());
    SecureStoreMetadata metadata = client.getKeyMetadata(secureKeyId);
    Assert.assertEquals(desc, metadata.getDescription());
    Assert.assertTrue(metadata.getLastModifiedTime() >= creationTime);
    Assert.assertEquals(properties, metadata.getProperties());
    client.createKey(secureKeyId, new SecureKeyCreateRequest(desc, "updatedSecureData", properties));
    Assert.assertEquals("updatedSecureData", client.getData(secureKeyId));
    Assert.assertEquals(1, client.listKeys(NamespaceId.DEFAULT).size());
    metadata = client.getKeyMetadata(secureKeyId);
    Assert.assertEquals(desc, metadata.getDescription());
    Assert.assertTrue(metadata.getLastModifiedTime() >= creationTime);
    Assert.assertEquals(properties, metadata.getProperties());
    // delete the key
    client.deleteKey(secureKeyId);
    Assert.assertTrue(client.listKeys(NamespaceId.DEFAULT).isEmpty());
}
Also used : SecureKeyCreateRequest(io.cdap.cdap.proto.security.SecureKeyCreateRequest) SecureKeyId(io.cdap.cdap.proto.id.SecureKeyId) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) Test(org.junit.Test)

Aggregations

SecureKeyCreateRequest (io.cdap.cdap.proto.security.SecureKeyCreateRequest)6 Test (org.junit.Test)4 SecureKeyId (io.cdap.cdap.proto.id.SecureKeyId)3 HttpResponse (io.cdap.common.http.HttpResponse)3 SecureStoreMetadata (io.cdap.cdap.api.security.store.SecureStoreMetadata)2 BadRequestException (io.cdap.cdap.common.BadRequestException)1 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)1 SecureKeyNotFoundException (io.cdap.cdap.common.SecureKeyNotFoundException)1 AuditPolicy (io.cdap.cdap.common.security.AuditPolicy)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 HttpRequest (io.cdap.common.http.HttpRequest)1 IOException (java.io.IOException)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1