use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSClientTest method testPrefetchInterval.
@Test
public void testPrefetchInterval() {
Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
ZTSClient client = new ZTSClient("http://localhost:4080", principal);
client.setPrefetchInterval(10L);
assertEquals(client.getPrefetchInterval(), 10l);
client.close();
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSClientTest method testGetRoleTokenCacheKeyMultipleRoles.
@Test
public void testGetRoleTokenCacheKeyMultipleRoles() {
Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
ZTSClient client = new ZTSClient("http://localhost:4080/", principal);
assertEquals(client.getRoleTokenCacheKey("coretech", "writers,admin,readers", "proxyuser"), "p=user_domain.user;d=coretech;r=admin,readers,writers;u=proxyuser");
client.close();
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSClientTest method testHostnamVerifierDnsMatchNone.
@Test
public void testHostnamVerifierDnsMatchNone() {
ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock();
Principal principal = SimplePrincipal.create("user_domain", "user", "v=S1;d=user_domain;n=user;s=sig", PRINCIPAL_AUTHORITY);
ZTSClient client = new ZTSClient("http://localhost:4080", principal);
client.setZTSRDLGeneratedClient(ztsClientMock);
ZTSClient.AWSHostNameVerifier hostnameVerifier = client.new AWSHostNameVerifier("host1");
ArrayList<List<?>> altNames = new ArrayList<>();
ArrayList<Object> rfcName = new ArrayList<>();
rfcName.add(Integer.valueOf(1));
rfcName.add("rfcname");
altNames.add(rfcName);
ArrayList<Object> dnsName = new ArrayList<>();
dnsName.add(Integer.valueOf(3));
dnsName.add("host1");
altNames.add(dnsName);
assertFalse(hostnameVerifier.matchDnsHostname(altNames));
client.close();
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZTSClientTest method testPostInstanceRefreshRequest.
@Test
public void testPostInstanceRefreshRequest() {
Principal principal = SimplePrincipal.create("user_domain", "user", "auth_creds", PRINCIPAL_AUTHORITY);
ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock();
ZTSClient client = new ZTSClient("http://localhost:4080", principal);
client.setZTSRDLGeneratedClient(ztsClientMock);
InstanceRefreshRequest req = new InstanceRefreshRequest().setExpiryTime(600);
Identity identity = client.postInstanceRefreshRequest("coretech", "unit", req);
assertNotNull(identity);
assertNotNull(identity.getServiceToken());
client.close();
}
use of com.yahoo.athenz.auth.Principal in project athenz by yahoo.
the class ZMSAuthorizerTest method testAuthorizerResourceWithDomain.
@Test
public void testAuthorizerResourceWithDomain() {
ZMSClient client = getClient(systemAdminUser);
String domain = "AuthorizerDom4";
ZMSAuthorizer authorizer = new ZMSAuthorizer(zmsUrl, domain);
assertNotNull(authorizer);
// create 3 user client objects
Principal p1 = createPrincipal("user1");
Principal p2 = createPrincipal("user2");
Principal p3 = createPrincipal("user3");
ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
client.setZMSRDLGeneratedClient(c);
Domain domainMock = Mockito.mock(Domain.class);
Mockito.when(c.postTopLevelDomain(Mockito.<String>any(), Mockito.any(TopLevelDomain.class))).thenReturn(domainMock);
setupAccess(client, domain);
// only user1 and user3 have access to UPDATE/resource1
ZMSClient mockZMSClient = Mockito.mock(ZMSClient.class);
authorizer.setZMSClient(mockZMSClient);
Access accessMock = Mockito.mock(Access.class);
Mockito.when(mockZMSClient.getAccess("UPDATE", "AuthorizerDom4:resource1", "AuthorizerDom4")).thenReturn(accessMock);
Mockito.when(accessMock.getGranted()).thenReturn(true, false, true);
Mockito.when(c.getAccess("UPDATE", "AuthorizerDom4:resource1", "AuthorizerDom4", null)).thenReturn(accessMock);
boolean access = authorizer.access("UPDATE", domain + ":resource1", p1, domain);
assertTrue(access);
access = authorizer.access("UPDATE", domain + ":resource1", p2, domain);
assertFalse(access);
access = authorizer.access("UPDATE", domain + ":resource1", p3, domain);
assertTrue(access);
TopLevelDomain topLevelDomainMock = Mockito.mock(TopLevelDomain.class);
Mockito.when(c.deleteTopLevelDomain(domain, AUDIT_REF)).thenReturn(topLevelDomainMock);
cleanUpAccess(domain);
}
Aggregations