Search in sources :

Example 36 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreTest method testGetLocalDomainListHidden.

@Test
public void testGetLocalDomainListHidden() {
    ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
    ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    cstore.put("test1", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put(".test2", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put(".test3", JSON.bytes(data));
    List<String> ls = fstore.getLocalDomainList();
    assertEquals(ls.size(), 1);
    assertTrue(ls.contains("test1"));
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 37 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreTest method testGetLocalDomainListSingle.

@Test
public void testGetLocalDomainListSingle() throws IOException {
    File rootDir = new File(FSTORE_PATH);
    // noinspection ResultOfMethodCallIgnored
    rootDir.mkdirs();
    Struct lastModStruct = new Struct();
    lastModStruct.put("lastModTime", 1001);
    File file = new File(FSTORE_PATH, ".lastModTime");
    Path path = Paths.get(file.toURI());
    Files.write(path, JSON.bytes(lastModStruct));
    ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
    ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    cstore.put("test1", JSON.bytes(data));
    List<String> ls = fstore.getLocalDomainList();
    assertEquals(ls.size(), 1);
    assertTrue(ls.contains("test1"));
}
Also used : Path(java.nio.file.Path) File(java.io.File) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 38 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class AuthzHelperTest method testConvertEntityToAuthzDetailsEntity.

@Test
public void testConvertEntityToAuthzDetailsEntity() throws JsonProcessingException {
    Entity entity = new Entity();
    entity.setName("athenz:entity.zts.authorization_details_set1");
    final String jsonData = "{\"type\":\"message_access\",\"roles\":[{\"name\":\"msg-readers\"," + "\"optional\":true},{\"name\":\"msg-writers\",\"optional\":false},{\"name\":" + "\"msg-editors\"}],\"fields\":[{\"name\":\"location\",\"optional\":true}," + "{\"name\":\"identifier\",\"optional\":false},{\"name\":\"resource\"}]}";
    entity.setValue(new Struct().with("data", jsonData));
    AuthzDetailsEntity authzEntity = AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
    assertNotNull(authzEntity);
    assertEquals(authzEntity.getType(), "message_access");
    List<AuthzDetailsField> roles = authzEntity.getRoles();
    assertNotNull(roles);
    assertEquals(roles.size(), 3);
    assertEquals(roles.get(0).getName(), "msg-readers");
    assertTrue(roles.get(0).isOptional());
    assertEquals(roles.get(1).getName(), "msg-writers");
    assertFalse(roles.get(1).isOptional());
    assertEquals(roles.get(2).getName(), "msg-editors");
    assertFalse(roles.get(2).isOptional());
    List<AuthzDetailsField> fields = authzEntity.getFields();
    assertNotNull(fields);
    assertEquals(fields.size(), 3);
    assertEquals(fields.get(0).getName(), "location");
    assertTrue(fields.get(0).isOptional());
    assertEquals(fields.get(1).getName(), "identifier");
    assertFalse(fields.get(1).isOptional());
    assertEquals(fields.get(2).getName(), "resource");
    assertFalse(fields.get(2).isOptional());
}
Also used : AuthzDetailsEntity(com.yahoo.athenz.common.config.AuthzDetailsEntity) AuthzDetailsEntity(com.yahoo.athenz.common.config.AuthzDetailsEntity) AuthzDetailsField(com.yahoo.athenz.common.config.AuthzDetailsField) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 39 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class AuthzHelperTest method testConvertEntityToAuthzDetailsEntityInvalidDetails.

@Test
public void testConvertEntityToAuthzDetailsEntityInvalidDetails() {
    Entity entity = new Entity();
    entity.setName("athenz:entity.zts.authorization_details_set1");
    try {
        AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("Entity has no value"));
    }
    // without data field is also invalid
    entity.setValue(new Struct().with("key", "value"));
    try {
        AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("Entity has no data field"));
    }
    final String jsonData = "{\"type\":\"message_access\",\"policies\":[{\"name\":\"msg-readers\"," + "\"optional\":true},{\"name\":\"msg-writers\",\"optional\":false},{\"name\":" + "\"msg-editors\"}],\"fields\":[{\"name\":\"location\",\"optional\":true}," + "{\"name\":\"identifier\",\"optional\":false},{\"name\":\"resource\"}]}";
    entity.setValue(new Struct().with("data", jsonData));
    try {
        AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
        fail();
    } catch (Exception ignored) {
    }
}
Also used : AuthzDetailsEntity(com.yahoo.athenz.common.config.AuthzDetailsEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 40 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testDeleteException.

@Test
public void testDeleteException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    // create the file
    Struct data = new Struct();
    data.put("key", "val1");
    fstore.put("test1", JSON.bytes(data));
    // update the helper to be our mock
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.doThrow(new IOException("io exception")).when(helper).delete(any());
    fstore.filesHelper = helper;
    try {
        fstore.delete("test1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (com.yahoo.rdl.Struct)61 Test (org.testng.annotations.Test)30 Array (com.yahoo.rdl.Array)10 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)7 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)5 Path (java.nio.file.Path)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Assertion (com.yahoo.athenz.zms.Assertion)3 Policy (com.yahoo.athenz.zms.Policy)3 ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)3 File (java.io.File)3 AuthzDetailsField (com.yahoo.athenz.common.config.AuthzDetailsField)2 FilesHelper (com.yahoo.athenz.common.server.util.FilesHelper)2 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AthenzConfig (com.yahoo.athenz.common.config.AthenzConfig)1