Search in sources :

Example 1 with DebugRoleAuthority

use of com.yahoo.athenz.common.server.debug.DebugRoleAuthority in project athenz by yahoo.

the class DebugRoleAuthorityTest method testRoleAuthority.

@Test
public void testRoleAuthority() {
    Authority roleAuthority = new com.yahoo.athenz.common.server.debug.DebugRoleAuthority();
    assertNotNull(roleAuthority);
    roleAuthority.initialize();
    ((DebugRoleAuthority) roleAuthority).setKeyStore(null);
    assertNull(roleAuthority.getDomain());
    assertEquals(roleAuthority.getHeader(), "Athenz-Role-Auth");
    // invalid authenticate values
    assertNull(roleAuthority.authenticate(null, "10.11.12.13", "GET", null));
    assertNull(roleAuthority.authenticate("abc", "10.11.12.13", "GET", null));
    assertNull(roleAuthority.authenticate("v=Z1;d=coretech;s=signature", "10.11.12.13", "GET", null));
    assertNull(roleAuthority.authenticate("v=Z1;r=role1,role2,role3;s=signature", "10.11.12.13", "GET", null));
    assertNull(roleAuthority.authenticate("v=U1;d=coretech;r=role1,role2,role3;s=signature", "10.11.12.13", "GET", null));
    // valid values
    String token = "v=Z1;d=coretech;r=role1,role2,role3;s=signature";
    Principal p = roleAuthority.authenticate(token, "10.11.12.13", "GET", null);
    assertNotNull(p);
    assertEquals(p.getDomain(), "coretech");
    assertEquals(p.getCredentials(), token);
    assertNull(p.getName());
    List<String> roles = p.getRoles();
    assertEquals(roles.size(), 3);
    assertTrue(roles.contains("role1"));
    assertTrue(roles.contains("role2"));
    assertTrue(roles.contains("role3"));
}
Also used : DebugRoleAuthority(com.yahoo.athenz.common.server.debug.DebugRoleAuthority) Authority(com.yahoo.athenz.auth.Authority) DebugRoleAuthority(com.yahoo.athenz.common.server.debug.DebugRoleAuthority) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Aggregations

Authority (com.yahoo.athenz.auth.Authority)1 Principal (com.yahoo.athenz.auth.Principal)1 DebugRoleAuthority (com.yahoo.athenz.common.server.debug.DebugRoleAuthority)1 Test (org.testng.annotations.Test)1