use of com.yahoo.athenz.auth.impl.CertificateAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequestByServiceCert.
@Test
public void testPostInstanceRefreshRequestByServiceCert() 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);
Path path = Paths.get("src/test/resources/valid_provider_refresh.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr).setKeyId("v0");
path = Paths.get("src/test/resources/valid_provider_refresh.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "syncer", "v=S1,d=athenz;n=syncer;s=sig", 0, new CertificateAuthority());
principal.setX509Certificate(cert);
String publicKeyName = "athenz.syncer_v0";
final String ztsPublicKey = "-----BEGIN PUBLIC KEY-----\n" + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMp9ZHVDK2s/FyinpKpD7lSsU+d6TSRE\n" + "NVo6sdLrEpOaCJETsh+0Qc0knhALxBD1+B9gS5F2rAFgtug0R6savvMCAwEAAQ==\n" + "-----END PUBLIC KEY-----";
ztsImpl.dataStore.getPublicKeyCache().put(publicKeyName, ztsPublicKey);
ZTSAuthorizer authorizer = Mockito.mock(ZTSAuthorizer.class);
Mockito.when(authorizer.access("update", "athenz:service", principal, null)).thenReturn(true);
ztsImpl.authorizer = authorizer;
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("10.0.0.1");
ResourceContext context = createResourceContext(principal, servletRequest);
Identity identity = ztsImpl.postInstanceRefreshRequest(context, "athenz", "syncer", req);
assertNotNull(identity);
assertNotNull(identity.getCertificate());
}
use of com.yahoo.athenz.auth.impl.CertificateAuthority in project athenz by yahoo.
the class CertificateAuthorityTest method testAuthenticateRoleCertificate.
@Test
public void testAuthenticateRoleCertificate() throws Exception, IOException {
CertificateAuthority authority = new CertificateAuthority();
authority.initialize();
try (InputStream inStream = new FileInputStream("src/test/resources/valid_email_x509.cert")) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream);
X509Certificate[] certs = new X509Certificate[1];
certs[0] = cert;
Principal principal = authority.authenticate(certs, null);
assertNotNull(principal);
assertEquals("athens", principal.getDomain());
assertEquals("zts", principal.getName());
assertEquals("sports:role.readers", principal.getRoles().get(0));
}
}
use of com.yahoo.athenz.auth.impl.CertificateAuthority in project athenz by yahoo.
the class CertificateAuthorityTest method testAuthenticateCertificate.
@Test
public void testAuthenticateCertificate() throws Exception, IOException {
CertificateAuthority authority = new CertificateAuthority();
authority.initialize();
try (InputStream inStream = new FileInputStream("src/test/resources/valid_cn_x509.cert")) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream);
X509Certificate[] certs = new X509Certificate[1];
certs[0] = cert;
Principal principal = authority.authenticate(certs, null);
assertNotNull(principal);
assertEquals("athenz", principal.getDomain());
assertEquals("syncer", principal.getName());
assertNull(principal.getRoles());
}
}
use of com.yahoo.athenz.auth.impl.CertificateAuthority in project athenz by yahoo.
the class CertificateAuthorityTest method testHeaderAuthenticate.
@Test
public void testHeaderAuthenticate() {
CertificateAuthority authority = new CertificateAuthority();
authority.initialize();
assertNull(authority.authenticate("v=U1;d=domain;n=service;s=sig", null, "GET", null));
}
use of com.yahoo.athenz.auth.impl.CertificateAuthority in project athenz by yahoo.
the class CertificateAuthorityTest method testGetHeader.
@Test
public void testGetHeader() {
CertificateAuthority authority = new CertificateAuthority();
authority.initialize();
assertNull(authority.getHeader());
}
Aggregations