use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnectionTest method testInsertPublicKeyEntryException.
@Test
public void testInsertPublicKeyEntryException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
PublicKeyEntry publicKey = new PublicKeyEntry().setId("zms1").setKey("Value1");
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.insertPublicKeyEntry("my-domain", "service1", publicKey);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class SignUtilsTest method testAsStructRoleService.
@Test
public void testAsStructRoleService() {
List<Role> roles = new ArrayList<Role>();
Role mRole = Mockito.mock(Role.class);
roles.add(mRole);
List<String> items = new ArrayList<String>();
String item = "check_item";
items.add(item);
List<ServiceIdentity> services = new ArrayList<ServiceIdentity>();
ServiceIdentity mService = Mockito.mock(ServiceIdentity.class);
services.add(mService);
List<PublicKeyEntry> publicKeys = new ArrayList<PublicKeyEntry>();
PublicKeyEntry mPublicKey = Mockito.mock(PublicKeyEntry.class);
publicKeys.add(mPublicKey);
SignedPolicies signedPolicies = Mockito.mock(SignedPolicies.class);
Mockito.when(mockDomain.getEnabled()).thenReturn(null);
Mockito.when(mockDomain.getAccount()).thenReturn("chk_string");
Mockito.when(mockDomain.getRoles()).thenReturn(roles);
Mockito.when(mRole.getMembers()).thenReturn(items);
Mockito.when(mockDomain.getServices()).thenReturn(services);
Mockito.when(mService.getHosts()).thenReturn(null);
Mockito.when(mService.getPublicKeys()).thenReturn(publicKeys);
Mockito.when(mockDomain.getPolicies()).thenReturn(signedPolicies);
Mockito.when(signedPolicies.getContents()).thenReturn(mockPolicies);
String check = SignUtils.asCanonicalString(mockDomain);
assertNotNull(check);
assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[{}]}],\"ypmId\":0}");
Mockito.when(mService.getPublicKeys()).thenReturn(null);
check = SignUtils.asCanonicalString(mockDomain);
assertNotNull(check);
assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[]}],\"ypmId\":0}");
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class FileConnection method getPublicKeyEntry.
@Override
public PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId, boolean domainStateCheck) {
DomainStruct domainStruct = getDomainStruct(domainName);
if (domainStruct == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "getPublicKeyEntry");
}
if (domainStateCheck && domainStruct.getMeta().getEnabled() == Boolean.FALSE) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain disabled", "getPublicKeyEntry");
}
ServiceIdentity service = getServiceObject(domainStruct, serviceName);
if (service == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "service not found", "getPublicKeyEntry");
}
List<PublicKeyEntry> publicKeys = service.getPublicKeys();
if (publicKeys == null) {
return null;
}
for (PublicKeyEntry keyEntry : publicKeys) {
if (keyId.equals(keyEntry.getId())) {
return keyEntry;
}
}
return null;
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class FilePublicKeyStore method loadPublicKeys.
void loadPublicKeys(ArrayList<PublicKeyEntry> publicKeys, Map<String, PublicKey> keyMap) {
if (publicKeys == null) {
return;
}
for (PublicKeyEntry publicKey : publicKeys) {
String id = publicKey.getId();
String key = publicKey.getKey();
if (key == null || id == null) {
continue;
}
PublicKey pubKey = null;
try {
pubKey = Crypto.loadPublicKey(Crypto.ybase64DecodeString(key));
} catch (Exception e) {
LOG.error("Invalid ZTS public key for id: " + id + " - " + e.getMessage());
continue;
}
keyMap.put(id, pubKey);
}
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class FileConnectionTest method testUpdatePublicKeyEntry.
@Test
public void testUpdatePublicKeyEntry() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
PublicKeyEntry keyEntry = new PublicKeyEntry();
try {
fileconnection.updatePublicKeyEntry("domain1", "service1", keyEntry);
} catch (Exception ex) {
assertTrue(true);
}
}
}
Aggregations