use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.
the class ZTSImplTest method testConfigurationSettings.
@Test
public void testConfigurationSettings() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
System.clearProperty(ZTSConsts.ZTS_PROP_AUTHORIZED_PROXY_USERS);
System.clearProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_O_VALUES);
System.clearProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST);
System.setProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS, "alias");
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
assertNull(ztsImpl.authorizedProxyUsers);
assertNull(ztsImpl.authFreeUriList);
assertNull(ztsImpl.authFreeUriSet);
assertNull(ztsImpl.validCertSubjectOrgValues);
assertEquals(ztsImpl.userDomainAliasPrefix, "alias.");
// some more config values tests
System.clearProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS);
System.setProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST, "/uri1,/uri1+,/uri2");
System.setProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_OU_VALUES, "Athenz|Athens");
ztsImpl = new ZTSImpl(mockCloudStore, store);
assertEquals(ztsImpl.authFreeUriList.size(), 1);
assertEquals(ztsImpl.authFreeUriSet.size(), 2);
assertEquals(ztsImpl.validCertSubjectOrgUnitValues.size(), 2);
assertTrue(ztsImpl.validCertSubjectOrgUnitValues.contains("Athenz"));
assertTrue(ztsImpl.validCertSubjectOrgUnitValues.contains("Athens"));
System.clearProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS);
System.clearProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST);
System.clearProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_OU_VALUES);
}
use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.
the class ZTSImplTest method testReadOnlyMode.
@Test
public void testReadOnlyMode() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
DynamicConfigBoolean dynamicConfigBoolean = Mockito.mock(DynamicConfigBoolean.class);
when(dynamicConfigBoolean.get()).thenReturn(true);
ztsImpl.readOnlyMode = dynamicConfigBoolean;
PrincipalAuthority authority = new PrincipalAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "readonly", "v=S1;d=athenz;n=readonly;s=signature", 0, authority);
ResourceContext ctx = createResourceContext(principal);
try {
ztsImpl.postRoleCertificateRequest(ctx, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRegisterInformation(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRefreshInformation(ctx, null, null, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.deleteInstanceIdentity(ctx, null, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRefreshRequest(ctx, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postSSHCertRequest(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postRoleCertificateRequestExt(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
}
use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.
the class ZTSImplTest method testValidateRequestRegularRequestPort.
@Test
public void testValidateRequestRegularRequestPort() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
ztsImpl.secureRequestsOnly = true;
ztsImpl.statusPort = 8443;
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.isSecure()).thenReturn(true);
Mockito.when(request.getLocalPort()).thenReturn(8443);
// status requests are allowed on port 8443
ztsImpl.validateRequest(request, "test", "principal-domain", true);
try {
ztsImpl.validateRequest(request, "principal-domain", "test");
fail();
} catch (ResourceException ignored) {
}
try {
ztsImpl.validateRequest(request, "principal-domain", "test", false);
fail();
} catch (ResourceException ignored) {
}
}
use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.
the class ZTSImplTest method testDeleteInstanceIdentity.
@Test
public void testDeleteInstanceIdentity() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
InstanceCertManager instanceManager = Mockito.mock(InstanceCertManager.class);
Mockito.when(instanceManager.deleteX509CertRecord("athenz.provider", "1001", "athenz.production")).thenReturn(true);
Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user", "doe", "v=U1,d=user;n=doe;s=sig", 0, new PrincipalAuthority());
ZTSAuthorizer authorizer = Mockito.mock(ZTSAuthorizer.class);
Mockito.when(authorizer.access("delete", "athenz:instance.1001", principal, null)).thenReturn(true);
ztsImpl.authorizer = authorizer;
ztsImpl.instanceCertManager = instanceManager;
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.deleteInstanceIdentity(context, "athenz.provider", "athenz", "production", "1001");
} catch (Exception ex) {
fail();
}
}
use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationInstanceIdMismatch.
@Test
public void testPostInstanceRefreshInformationInstanceIdMismatch() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
SignedDomain providerDomain = signedAuthorizedProviderDomain();
store.processSignedDomain(providerDomain, false);
SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
store.processSignedDomain(tenantDomain, false);
Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceProviderManager instanceProviderManager = Mockito.mock(InstanceProviderManager.class);
InstanceProvider providerClient = Mockito.mock(InstanceProvider.class);
InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider");
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", "athenz.production")).thenReturn(certRecord);
Mockito.when(instanceProviderManager.getProvider(eq("athenz.provider"), Mockito.any())).thenReturn(providerClient);
Mockito.when(providerClient.refreshInstance(Mockito.any())).thenReturn(confirmation);
path = Paths.get("src/test/resources/valid_cn_x509.cert");
String pem = new String(Files.readAllBytes(path));
InstanceIdentity identity = new InstanceIdentity().setName("athenz.production").setX509Certificate(pem);
Mockito.doReturn(identity).when(instanceManager).generateIdentity(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any());
ztsImpl.instanceProviderManager = instanceProviderManager;
ztsImpl.instanceCertManager = instanceManager;
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
CertificateAuthority certAuthority = new CertificateAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
assertNotNull(principal);
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(), 400, ex.getMessage());
assertTrue(ex.getMessage().contains("instance id mismatch"));
}
}
Aggregations