use of com.yahoo.athenz.zts.cert.X509CertRecord in project athenz by yahoo.
the class ZTSImplTest method testPostOSTKInstanceRefreshRequestSerialMisMatch.
@Test
public void testPostOSTKInstanceRefreshRequestSerialMisMatch() throws IOException {
Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
OSTKInstanceRefreshRequest req = new OSTKInstanceRefreshRequest().setCsr(certCsr);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1,d=athenz;n=production;s=sig", 0, new CertificateAuthority());
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
principal.setX509Certificate(cert);
ResourceContext context = createResourceContext(principal, servletRequest);
X509CertRecord certRecord = new X509CertRecord();
certRecord.setService("athenz.production");
certRecord.setProvider("ostk");
certRecord.setInstanceId("1001");
certRecord.setCurrentSerial("12341324334");
certRecord.setPrevSerial("2342134323");
CertRecordStore certStore = Mockito.mock(CertRecordStore.class);
CertRecordStoreConnection certConnection = Mockito.mock(CertRecordStoreConnection.class);
Mockito.when(certStore.getConnection()).thenReturn(certConnection);
Mockito.when(certConnection.getX509CertRecord("ostk", "1001")).thenReturn(certRecord);
Mockito.when(certConnection.updateX509CertRecord(ArgumentMatchers.isA(X509CertRecord.class))).thenReturn(true);
zts.instanceCertManager.setCertStore(certStore);
try {
zts.postOSTKInstanceRefreshRequest(context, "athenz", "production", req);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
assertTrue(ex.getMessage().contains("Certificate revoked"));
}
}
use of com.yahoo.athenz.zts.cert.X509CertRecord in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationSSHMatchPrevSerial.
@Test
public void testPostInstanceRefreshInformationSSHMatchPrevSerial() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
SignedDomain providerDomain = signedAuthorizedProviderDomain();
store.processDomain(providerDomain, false);
SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
store.processDomain(tenantDomain, false);
InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
X509CertRecord certRecord = new X509CertRecord();
certRecord.setInstanceId("1001");
certRecord.setProvider("athenz.provider");
certRecord.setService("athenz.production");
certRecord.setCurrentSerial("123413");
certRecord.setPrevSerial("16503746516960996918");
Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001")).thenReturn(certRecord);
Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
InstanceIdentity identity = new InstanceIdentity().setName("athenz.production");
Mockito.when(instanceManager.generateSshIdentity(identity, "ssh-csr", null)).thenReturn(true);
ztsImpl.instanceCertManager = instanceManager;
InstanceRefreshInformation info = new InstanceRefreshInformation().setSsh("ssh-csr");
CertificateAuthority certAuthority = new CertificateAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
Path path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
principal.setX509Certificate(cert);
ResourceContext context = createResourceContext(principal);
InstanceIdentity instanceIdentity = ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
assertNotNull(instanceIdentity);
}
use of com.yahoo.athenz.zts.cert.X509CertRecord in project athenz by yahoo.
the class ZTSImplTest method testPostOSTKInstanceRefreshRequestPreviousSerialMatch.
@Test
public void testPostOSTKInstanceRefreshRequestPreviousSerialMatch() throws IOException {
Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
OSTKInstanceRefreshRequest req = new OSTKInstanceRefreshRequest().setCsr(certCsr);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1,d=athenz;n=production;s=sig", 0, new CertificateAuthority());
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
principal.setX509Certificate(cert);
ResourceContext context = createResourceContext(principal, servletRequest);
X509CertRecord certRecord = new X509CertRecord();
certRecord.setService("athenz.production");
certRecord.setProvider("ostk");
certRecord.setInstanceId("1001");
certRecord.setCurrentSerial("12341324334");
certRecord.setPrevSerial("16503746516960996918");
CertRecordStore certStore = Mockito.mock(CertRecordStore.class);
CertRecordStoreConnection certConnection = Mockito.mock(CertRecordStoreConnection.class);
Mockito.when(certStore.getConnection()).thenReturn(certConnection);
Mockito.when(certConnection.getX509CertRecord("ostk", "1001")).thenReturn(certRecord);
Mockito.when(certConnection.updateX509CertRecord(ArgumentMatchers.isA(X509CertRecord.class))).thenReturn(true);
zts.instanceCertManager.setCertStore(certStore);
Identity identity = zts.postOSTKInstanceRefreshRequest(context, "athenz", "production", req);
assertNotNull(identity);
X509Certificate x509Cert = Crypto.loadX509Certificate(identity.getCertificate());
assertNotNull(x509Cert);
}
use of com.yahoo.athenz.zts.cert.X509CertRecord in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationSSHIdentityFailure.
@Test
public void testPostInstanceRefreshInformationSSHIdentityFailure() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
SignedDomain providerDomain = signedAuthorizedProviderDomain();
store.processDomain(providerDomain, false);
SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
store.processDomain(tenantDomain, false);
InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
X509CertRecord certRecord = new X509CertRecord();
certRecord.setInstanceId("1001");
certRecord.setProvider("athenz.provider");
certRecord.setService("athenz.production");
certRecord.setCurrentSerial("16503746516960996918");
certRecord.setPrevSerial("16503746516960996918");
Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001")).thenReturn(certRecord);
Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
InstanceIdentity identity = new InstanceIdentity().setName("athenz.production");
Mockito.when(instanceManager.generateSshIdentity(identity, "ssh-csr", "user")).thenReturn(false);
ztsImpl.instanceCertManager = instanceManager;
InstanceRefreshInformation info = new InstanceRefreshInformation().setSsh("ssh-csr");
CertificateAuthority certAuthority = new CertificateAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
Path path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
principal.setX509Certificate(cert);
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 500);
}
}
use of com.yahoo.athenz.zts.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testInsertX509Record.
@Test
public void testInsertX509Record() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
X509CertRecord certRecord = new X509CertRecord();
Date now = new Date();
certRecord.setService("cn");
certRecord.setProvider("ostk");
certRecord.setInstanceId("instance-id");
certRecord.setCurrentIP("current-ip");
certRecord.setCurrentSerial("current-serial");
certRecord.setCurrentTime(now);
certRecord.setPrevIP("prev-ip");
certRecord.setPrevSerial("prev-serial");
certRecord.setPrevTime(now);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "ostk");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "instance-id");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "cn");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "current-serial");
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(5, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(6, "current-ip");
Mockito.verify(mockPrepStmt, times(1)).setString(7, "prev-serial");
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(8, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(9, "prev-ip");
jdbcConn.close();
}
Aggregations