use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnectionTest method testInsertPublicKeyEntryInvalidService.
@Test
public void testInsertPublicKeyEntryInvalidService() 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);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
false);
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 JDBCConnectionTest method testUpdatePublicKeyEntryInvalidService.
@Test
public void testUpdatePublicKeyEntryInvalidService() 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);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
false);
try {
jdbcConn.updatePublicKeyEntry("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 JDBCConnectionTest method testInsertPublicKeyEntry.
@Test
public void testInsertPublicKeyEntry() 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.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertPublicKeyEntry("my-domain", "service1", publicKey);
assertTrue(requestSuccess);
// getting domain and service ids
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
// public key entry statement
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 7);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "zms1");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "Value1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnection method listPublicKeys.
@Override
public List<PublicKeyEntry> listPublicKeys(String domainName, String serviceName) {
final String caller = "listPublicKeys";
int domainId = getDomainId(domainName);
if (domainId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
}
int serviceId = getServiceId(domainId, serviceName);
if (serviceId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_SERVICE, ZMSUtils.serviceResourceName(domainName, serviceName));
}
List<PublicKeyEntry> publicKeys = new ArrayList<>();
try (PreparedStatement ps = con.prepareStatement(SQL_LIST_PUBLIC_KEY)) {
ps.setInt(1, serviceId);
try (ResultSet rs = executeQuery(ps, caller)) {
while (rs.next()) {
PublicKeyEntry publicKey = new PublicKeyEntry().setId(rs.getString(ZMSConsts.DB_COLUMN_KEY_ID)).setKey(rs.getString(ZMSConsts.DB_COLUMN_KEY_VALUE));
publicKeys.add(publicKey);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
return publicKeys;
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnection method getPublicKeyEntry.
@Override
public PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId, boolean domainStateCheck) {
final String caller = "getPublicKeyEntry";
int domainId = getDomainId(domainName, domainStateCheck);
if (domainId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
}
int serviceId = getServiceId(domainId, serviceName);
if (serviceId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_SERVICE, ZMSUtils.serviceResourceName(domainName, serviceName));
}
try (PreparedStatement ps = con.prepareStatement(SQL_GET_PUBLIC_KEY)) {
ps.setInt(1, serviceId);
ps.setString(2, keyId);
try (ResultSet rs = executeQuery(ps, caller)) {
if (rs.next()) {
PublicKeyEntry publicKey = new PublicKeyEntry().setId(keyId).setKey(rs.getString(ZMSConsts.DB_COLUMN_KEY_VALUE));
return publicKey;
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
return null;
}
Aggregations