use of com.yahoo.athenz.common.messaging.DomainChangeMessage in project athenz by yahoo.
the class PulsarChangeSubscriberTest method test_subscriber_creation.
@Test
public void test_subscriber_creation() throws IOException, InterruptedException {
System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
PulsarChangeSubscriber<DomainChangeMessage> subscriber = new PulsarChangeSubscriber<>("service-url", "topic", "subs", SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
assertNotNull(getPulsarConsumer(subscriber));
}
use of com.yahoo.athenz.common.messaging.DomainChangeMessage in project athenz by yahoo.
the class ZMSImplTest method testDomainChangeMessages.
@Test
public void testDomainChangeMessages() {
// postTopLevelDomain events
String domainName = "test-dom-change-msg";
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-dom-change-msg", "Test description Domain1", "testOrg", zmsTestInitializer.getAdminUser());
dom1.setAuditEnabled(true);
RsrcCtxWrapper ctx = zmsTestInitializer.contextWithMockPrincipal("postTopLevelDomain");
zmsTestInitializer.getZms().postTopLevelDomain(ctx, zmsTestInitializer.getAuditRef(), dom1);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "postTopLevelDomain");
// putDomainTemplate events
DomainTemplate domTemplate = new DomainTemplate();
List<String> templates = new ArrayList<>();
templates.add("vipng");
domTemplate.setTemplateNames(templates);
ctx = zmsTestInitializer.contextWithMockPrincipal("putDomainTemplate");
zmsTestInitializer.getZms().putDomainTemplate(ctx, domainName, zmsTestInitializer.getAuditRef(), domTemplate);
assertTemplateChanges(domainName, ctx.getDomainChangeMessages(), "putDomainTemplate");
// deleteDomainTemplate events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteDomainTemplate");
zmsTestInitializer.getZms().deleteDomainTemplate(ctx, domainName, "vipng", zmsTestInitializer.getAuditRef());
assertTemplateChanges(domainName, ctx.getDomainChangeMessages(), "deleteDomainTemplate");
// putDomainTemplateExt events
ctx = zmsTestInitializer.contextWithMockPrincipal("putDomainTemplateExt");
zmsTestInitializer.getZms().putDomainTemplateExt(ctx, domainName, "vipng", zmsTestInitializer.getAuditRef(), domTemplate);
assertTemplateChanges(domainName, ctx.getDomainChangeMessages(), "putDomainTemplateExt");
// putDomainMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putDomainMeta");
DomainMeta dm = new DomainMeta().setBusinessService("invalid");
zmsTestInitializer.getZms().putDomainMeta(ctx, domainName, zmsTestInitializer.getAuditRef(), dm);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "putDomainMeta");
// putDomainSystemMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putDomainSystemMeta");
DomainMeta meta = new DomainMeta().setAuditEnabled(true);
zmsTestInitializer.getZms().putDomainSystemMeta(ctx, domainName, "auditenabled", zmsTestInitializer.getAuditRef(), meta);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "putDomainSystemMeta");
// putEntity events
ctx = zmsTestInitializer.contextWithMockPrincipal("putEntity");
Entity entity1 = zmsTestInitializer.createEntityObject(domainName, "Entity1");
zmsTestInitializer.getZms().putEntity(ctx, domainName, "Entity1", zmsTestInitializer.getAuditRef(), entity1);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ENTITY, domainName, "entity1", "putEntity");
// deleteEntity events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteEntity");
zmsTestInitializer.getZms().deleteEntity(ctx, domainName, "Entity1", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ENTITY, domainName, "entity1", "deleteEntity");
// putRole events
ctx = zmsTestInitializer.contextWithMockPrincipal("putRole");
String roleName = "role-test1";
Role role = zmsTestInitializer.createRoleObject(domainName, roleName, null, "user.user101", "user.todelete");
role.setAuditEnabled(true);
zmsTestInitializer.getZms().putRole(ctx, domainName, roleName, zmsTestInitializer.getAuditRef(), role);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putRole");
// putRoleMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putRoleMeta");
RoleMeta rm = createRoleMetaObject(true);
zmsTestInitializer.getZms().putRoleMeta(ctx, domainName, roleName, "auditenabled", rm);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putRoleMeta");
// putMembership events using user.doe principal
ctx = zmsTestInitializer.contextWithMockPrincipal("putMembership", "doe");
Membership mbr = new Membership();
mbr.setMemberName("user.doe");
mbr.setActive(false);
mbr.setApproved(false);
zmsTestInitializer.getZms().putMembership(ctx, domainName, roleName, "user.doe", zmsTestInitializer.getAuditRef(), mbr);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putMembership");
// putRoleReview events
ctx = zmsTestInitializer.contextWithMockPrincipal("putRoleReview");
Role inputRole = new Role().setName(roleName);
List<RoleMember> inputMembers = new ArrayList<>();
inputRole.setRoleMembers(inputMembers);
inputMembers.add(new RoleMember().setMemberName("user.doe").setActive(false));
zmsTestInitializer.getZms().putRoleReview(ctx, domainName, roleName, zmsTestInitializer.getAuditRef(), inputRole);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putRoleReview");
// putMembershipDecision events
ctx = zmsTestInitializer.contextWithMockPrincipal("putMembershipDecision");
mbr.setActive(true);
mbr.setApproved(true);
zmsTestInitializer.getZms().putMembershipDecision(ctx, domainName, roleName, "user.doe", zmsTestInitializer.getAuditRef(), mbr);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putMembershipDecision");
// putMembership events using user.pend principal
ctx = zmsTestInitializer.contextWithMockPrincipal("putMembership", "pend");
Membership mbr1 = new Membership();
mbr1.setMemberName("user.pend");
mbr1.setActive(false);
mbr1.setApproved(false);
zmsTestInitializer.getZms().putMembership(ctx, domainName, roleName, "user.pend", zmsTestInitializer.getAuditRef(), mbr1);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putMembership");
// deletePendingMembership events
ctx = zmsTestInitializer.contextWithMockPrincipal("deletePendingMembership");
zmsTestInitializer.getZms().deletePendingMembership(ctx, domainName, roleName, "user.pend", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "deletePendingMembership");
// deleteMembership events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteMembership");
zmsTestInitializer.getZms().deleteMembership(ctx, domainName, roleName, "user.doe", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "deleteMembership");
// putRoleSystemMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putRoleSystemMeta");
RoleSystemMeta rsm = createRoleSystemMetaObject(true);
zmsTestInitializer.getZms().putRoleSystemMeta(ctx, domainName, roleName, "auditenabled", zmsTestInitializer.getAuditRef(), rsm);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "putRoleSystemMeta");
// deleteRole events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteRole");
zmsTestInitializer.getZms().deleteRole(ctx, domainName, roleName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, roleName, "deleteRole");
// putDefaultAdmins events
ctx = zmsTestInitializer.contextWithMockPrincipal("putDefaultAdmins");
List<String> adminList = Arrays.asList("user.newadmin", zmsTestInitializer.getAdminUser());
DefaultAdmins admins = new DefaultAdmins().setAdmins(adminList);
zmsTestInitializer.getZms().putDefaultAdmins(ctx, domainName, zmsTestInitializer.getAuditRef(), admins);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, "admin", "putDefaultAdmins");
// putGroup events
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroup");
String groupName = "group-test1";
Group group = zmsTestInitializer.createGroupObject(domainName, groupName, "user.user12", "user.user101");
group.setAuditEnabled(true);
zmsTestInitializer.getZms().putGroup(ctx, domainName, groupName, zmsTestInitializer.getAuditRef(), group);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroup");
// putGroupMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupMeta");
GroupMeta gm = new GroupMeta().setSelfServe(true);
zmsTestInitializer.getZms().putGroupMeta(ctx, domainName, groupName, "auditenabled", gm);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupMeta");
// putGroupMembership events using user.doe principal
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupMembership", "doe");
GroupMembership gmbr = new GroupMembership();
gmbr.setMemberName("user.doe");
gmbr.setActive(false);
gmbr.setApproved(false);
zmsTestInitializer.getZms().putGroupMembership(ctx, domainName, groupName, "user.doe", zmsTestInitializer.getAuditRef(), gmbr);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupMembership");
// putGroupReview events
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupReview");
Group inputGroup = new Group().setName(groupName);
List<GroupMember> gInputMembers = new ArrayList<>();
inputGroup.setGroupMembers(gInputMembers);
gInputMembers.add(new GroupMember().setMemberName("user.doe").setActive(false));
zmsTestInitializer.getZms().putGroupReview(ctx, domainName, groupName, zmsTestInitializer.getAuditRef(), inputGroup);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupReview");
// putGroupMembershipDecision events
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupMembershipDecision");
mbr.setActive(true);
mbr.setApproved(true);
zmsTestInitializer.getZms().putGroupMembershipDecision(ctx, domainName, groupName, "user.doe", zmsTestInitializer.getAuditRef(), gmbr);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupMembershipDecision");
// putGroupMembership events using user.pend principal
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupMembership", "pend");
GroupMembership gmbr1 = new GroupMembership();
gmbr1.setMemberName("user.pend");
gmbr1.setActive(false);
gmbr1.setApproved(false);
zmsTestInitializer.getZms().putGroupMembership(ctx, domainName, groupName, "user.pend", zmsTestInitializer.getAuditRef(), gmbr1);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupMembership");
// deletePendingGroupMembership events
ctx = zmsTestInitializer.contextWithMockPrincipal("deletePendingGroupMembership");
zmsTestInitializer.getZms().deletePendingGroupMembership(ctx, domainName, groupName, "user.pend", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "deletePendingGroupMembership");
// deleteGroupMembership events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteGroupMembership");
zmsTestInitializer.getZms().deleteGroupMembership(ctx, domainName, groupName, "user.user12", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "deleteGroupMembership");
// putGroupSystemMeta events
ctx = zmsTestInitializer.contextWithMockPrincipal("putGroupSystemMeta");
GroupSystemMeta gsm = createGroupSystemMetaObject(true);
zmsTestInitializer.getZms().putGroupSystemMeta(ctx, domainName, groupName, "auditenabled", zmsTestInitializer.getAuditRef(), gsm);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "putGroupSystemMeta");
// deleteGroup events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteGroup");
zmsTestInitializer.getZms().deleteGroup(ctx, domainName, groupName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), GROUP, domainName, groupName, "deleteGroup");
// putPolicy events
ctx = zmsTestInitializer.contextWithMockPrincipal("putPolicy");
String policyName = "test-policy";
Policy policy = zmsTestInitializer.createPolicyObject(domainName, policyName);
zmsTestInitializer.getZms().putPolicy(ctx, domainName, policyName, zmsTestInitializer.getAuditRef(), policy);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "putPolicy");
// putAssertion events
ctx = zmsTestInitializer.contextWithMockPrincipal("putAssertion");
Assertion assertion = new Assertion();
assertion.setAction("update");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource(domainName + ":resource");
assertion.setRole(ResourceUtils.roleResourceName(domainName, "admin"));
assertion = zmsTestInitializer.getZms().putAssertion(ctx, domainName, policyName, zmsTestInitializer.getAuditRef(), assertion);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "putAssertion");
// deleteAssertion events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteAssertion");
zmsTestInitializer.getZms().deleteAssertion(ctx, domainName, policyName, assertion.getId(), zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "deleteAssertion");
// putPolicyVersion events
ctx = zmsTestInitializer.contextWithMockPrincipal("putPolicyVersion");
String newVersion = "new-version";
zmsTestInitializer.getZms().putPolicyVersion(ctx, domainName, policyName, new PolicyOptions().setVersion(newVersion), zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "putPolicyVersion");
// putAssertionPolicyVersion events
addRoleNeededForTest(domainName, "Role1");
ctx = zmsTestInitializer.contextWithMockPrincipal("putAssertionPolicyVersion");
Assertion assertionWithVersion = new Assertion();
assertionWithVersion.setAction("testAction");
assertionWithVersion.setEffect(AssertionEffect.DENY);
assertionWithVersion.setResource(domainName + ":test-resource");
assertionWithVersion.setRole(ResourceUtils.roleResourceName(domainName, "Role1"));
assertionWithVersion = zmsTestInitializer.getZms().putAssertionPolicyVersion(ctx, domainName, policyName, newVersion, zmsTestInitializer.getAuditRef(), assertionWithVersion);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "putAssertionPolicyVersion");
// setActivePolicyVersion events
ctx = zmsTestInitializer.contextWithMockPrincipal("setActivePolicyVersion");
zmsTestInitializer.getZms().setActivePolicyVersion(ctx, domainName, policyName, new PolicyOptions().setVersion(newVersion), zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "setActivePolicyVersion");
// deleteAssertionPolicyVersion events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteAssertionPolicyVersion");
zmsTestInitializer.getZms().deleteAssertionPolicyVersion(ctx, domainName, policyName, newVersion, assertionWithVersion.getId(), zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "deleteAssertionPolicyVersion");
// deletePolicyVersion events
ctx = zmsTestInitializer.contextWithMockPrincipal("deletePolicyVersion");
zmsTestInitializer.getZms().putPolicyVersion(ctx, domainName, policyName, new PolicyOptions().setVersion("versionToDelete"), zmsTestInitializer.getAuditRef());
zmsTestInitializer.getZms().deletePolicyVersion(ctx, domainName, policyName, "versionToDelete", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyName, "deletePolicyVersion");
// putAssertionCondition events
ctx = zmsTestInitializer.contextWithMockPrincipal("putAssertionCondition");
String policyConditionName = "test-policy-cond";
Policy policyCondition = zmsTestInitializer.createPolicyObject(domainName, policyConditionName);
zmsTestInitializer.getZms().putPolicy(ctx, domainName, policyConditionName, zmsTestInitializer.getAuditRef(), policyCondition);
policyCondition = zmsTestInitializer.getZms().getPolicy(ctx, domainName, policyConditionName);
Long assertionId = policyCondition.getAssertions().get(0).getId();
AssertionCondition ac = createAssertionConditionObject(1, "instances", "HOST1,host2,Host3");
ac.setId(null);
ac = zmsTestInitializer.getZms().putAssertionCondition(ctx, domainName, policyConditionName, assertionId, zmsTestInitializer.getAuditRef(), ac);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyConditionName, "putAssertionCondition");
// putAssertionConditions events
ctx = zmsTestInitializer.contextWithMockPrincipal("putAssertionConditions");
AssertionConditions acs = new AssertionConditions().setConditionsList(Collections.singletonList(ac));
zmsTestInitializer.getZms().putAssertionConditions(ctx, domainName, policyConditionName, assertionId, zmsTestInitializer.getAuditRef(), acs);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyConditionName, "putAssertionConditions");
// deleteAssertionCondition events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteAssertionCondition");
zmsTestInitializer.getZms().deleteAssertionCondition(ctx, domainName, policyConditionName, assertionId, 1, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyConditionName, "deleteAssertionCondition");
// deleteAssertionConditions events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteAssertionConditions");
zmsTestInitializer.getZms().deleteAssertionConditions(ctx, domainName, policyConditionName, assertionId, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyConditionName, "deleteAssertionConditions");
// deletePolicy events
ctx = zmsTestInitializer.contextWithMockPrincipal("deletePolicy");
zmsTestInitializer.getZms().deletePolicy(ctx, domainName, policyConditionName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, domainName, policyConditionName, "deletePolicy");
// putServiceIdentity events
String serviceName = "test-srv";
ServiceIdentity service = zmsTestInitializer.createServiceObject(domainName, serviceName, "http://localhost", "/usr/bin/test", "root", "users", "host1");
ctx = zmsTestInitializer.contextWithMockPrincipal("putServiceIdentity");
zmsTestInitializer.getZms().putServiceIdentity(ctx, domainName, serviceName, zmsTestInitializer.getAuditRef(), service);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), SERVICE, domainName, serviceName, "putServiceIdentity");
// putPublicKeyEntry events
PublicKeyEntry keyEntry = new PublicKeyEntry();
keyEntry.setId("1");
keyEntry.setKey(zmsTestInitializer.getPubKeyK2());
ctx = zmsTestInitializer.contextWithMockPrincipal("putPublicKeyEntry");
zmsTestInitializer.getZms().putPublicKeyEntry(ctx, domainName, serviceName, "1", zmsTestInitializer.getAuditRef(), keyEntry);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), SERVICE, domainName, serviceName, "putPublicKeyEntry");
// deletePublicKeyEntry events
ctx = zmsTestInitializer.contextWithMockPrincipal("deletePublicKeyEntry");
zmsTestInitializer.getZms().deletePublicKeyEntry(ctx, domainName, serviceName, "1", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), SERVICE, domainName, serviceName, "deletePublicKeyEntry");
// putServiceIdentitySystemMeta events
ServiceIdentitySystemMeta srvIdMeta = new ServiceIdentitySystemMeta();
srvIdMeta.setProviderEndpoint("https://localhost");
ctx = zmsTestInitializer.contextWithMockPrincipal("putServiceIdentitySystemMeta");
zmsTestInitializer.getZms().putServiceIdentitySystemMeta(ctx, domainName, serviceName, "providerendpoint", zmsTestInitializer.getAuditRef(), srvIdMeta);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), SERVICE, domainName, serviceName, "putServiceIdentitySystemMeta");
// putTenancy events
String tenantDomainName = domainName + "-tenant";
TopLevelDomain tenDom = zmsTestInitializer.createTopLevelDomainObject(tenantDomainName, "Test Tenant Provider Domain", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), tenDom);
Tenancy tenancy = zmsTestInitializer.createTenantObject(tenantDomainName, domainName + "." + serviceName);
ctx = zmsTestInitializer.contextWithMockPrincipal("putTenancy");
zmsTestInitializer.getZms().putTenancy(ctx, tenantDomainName, domainName + "." + serviceName, zmsTestInitializer.getAuditRef(), tenancy);
List<DomainChangeMessage> changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, tenantDomainName, "test-dom-change-msg-tenant:role.tenancy.test-dom-change-msg.test-srv.admin", "putTenancy");
assertChange(changeMsgs.get(1), POLICY, tenantDomainName, "test-dom-change-msg-tenant:policy.tenancy.test-dom-change-msg.test-srv.admin", "putTenancy");
// deleteTenancy events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteTenancy");
zmsTestInitializer.getZms().deleteTenancy(ctx, tenantDomainName, domainName + "." + serviceName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, tenantDomainName, "tenancy.test-dom-change-msg.test-srv.admin", "deleteTenancy");
// putTenant events
String tenantServiceName = serviceName + "-tenant";
ServiceIdentity tenantService = zmsTestInitializer.createServiceObject(tenantDomainName, tenantServiceName, "http://localhost", "/usr/bin/test", "root", "users", "host1");
zmsTestInitializer.getZms().putServiceIdentity(zmsTestInitializer.getMockDomRsrcCtx(), tenantDomainName, tenantServiceName, zmsTestInitializer.getAuditRef(), tenantService);
ctx = zmsTestInitializer.contextWithMockPrincipal("putTenant");
Tenancy tenant = new Tenancy().setDomain(tenantDomainName).setService(domainName + "." + serviceName);
zmsTestInitializer.getZms().putTenant(ctx, domainName, serviceName, tenantDomainName, zmsTestInitializer.getAuditRef(), tenant);
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "putTenant");
assertChange(changeMsgs.get(1), POLICY, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "putTenant");
// deleteTenant events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteTenant");
zmsTestInitializer.getZms().deleteTenant(ctx, domainName, serviceName, tenantDomainName, zmsTestInitializer.getAuditRef());
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "deleteTenant");
assertChange(changeMsgs.get(1), POLICY, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "deleteTenant");
// putProviderResourceGroupRoles events
ctx = zmsTestInitializer.contextWithMockPrincipal("putProviderResourceGroupRoles");
ProviderResourceGroupRoles providerRoles = new ProviderResourceGroupRoles().setDomain(domainName).setService(serviceName).setTenant(tenantDomainName).setRoles(Collections.singletonList(new TenantRoleAction().setRole("role").setAction("action"))).setResourceGroup("set1-test");
zmsTestInitializer.getZms().putProviderResourceGroupRoles(ctx, tenantDomainName, domainName, serviceName, "set1-test", zmsTestInitializer.getAuditRef(), providerRoles);
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), POLICY, tenantDomainName, "test-dom-change-msg-tenant:policy.tenancy.test-dom-change-msg.test-srv.admin", "putProviderResourceGroupRoles");
assertChange(changeMsgs.get(1), ROLE, tenantDomainName, "test-dom-change-msg.test-srv.res_group.set1-test.role", "putProviderResourceGroupRoles");
// putTenantResourceGroupRoles events
ctx = zmsTestInitializer.contextWithMockPrincipal("putTenantResourceGroupRoles");
TenantResourceGroupRoles tenantRoles = new TenantResourceGroupRoles().setDomain(domainName).setService(serviceName).setTenant(tenantDomainName).setRoles(Collections.singletonList(new TenantRoleAction().setRole("role").setAction("action"))).setResourceGroup("set1-test");
zmsTestInitializer.getZms().putTenantResourceGroupRoles(ctx, domainName, serviceName, tenantDomainName, "set1-test", zmsTestInitializer.getAuditRef(), tenantRoles);
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "putTenantResourceGroupRoles");
assertChange(changeMsgs.get(1), POLICY, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "putTenantResourceGroupRoles");
// deleteTenantResourceGroupRoles events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteTenantResourceGroupRoles");
zmsTestInitializer.getZms().deleteTenantResourceGroupRoles(ctx, domainName, serviceName, tenantDomainName, "set1-test", zmsTestInitializer.getAuditRef());
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, domainName, "test-srv.tenant.test-dom-change-msg-tenant.res_group.set1-test.role", "deleteTenantResourceGroupRoles");
assertChange(changeMsgs.get(1), POLICY, domainName, "test-srv.tenant.test-dom-change-msg-tenant.res_group.set1-test.role", "deleteTenantResourceGroupRoles");
// deleteProviderResourceGroupRoles events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteProviderResourceGroupRoles");
zmsTestInitializer.getZms().deleteProviderResourceGroupRoles(ctx, tenantDomainName, domainName, serviceName, "set1-test", zmsTestInitializer.getAuditRef());
changeMsgs = ctx.getDomainChangeMessages();
assertSingleChangeMessage(ctx.getDomainChangeMessages(), POLICY, tenantDomainName, "tenancy.test-dom-change-msg.test-srv.res_group.set1-test.role", "deleteProviderResourceGroupRoles");
// deleteTenant events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteTenant");
zmsTestInitializer.getZms().deleteTenant(ctx, domainName, serviceName, tenantDomainName, zmsTestInitializer.getAuditRef());
changeMsgs = ctx.getDomainChangeMessages();
assertEquals(changeMsgs.size(), 2);
assertChange(changeMsgs.get(0), ROLE, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "deleteTenant");
assertChange(changeMsgs.get(1), POLICY, domainName, "test-srv.tenant.test-dom-change-msg-tenant.admin", "deleteTenant");
// deleteServiceIdentity events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteServiceIdentity");
zmsTestInitializer.getZms().deleteServiceIdentity(ctx, domainName, serviceName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), SERVICE, domainName, serviceName, "deleteServiceIdentity");
// deleteDomainRoleMember events
role = zmsTestInitializer.createRoleObject(domainName, "some-role", null, "user.user222", "user.todelete");
zmsTestInitializer.getZms().putRole(zmsTestInitializer.getMockDomRsrcCtx(), domainName, "some-role", zmsTestInitializer.getAuditRef(), role);
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteDomainRoleMember");
zmsTestInitializer.getZms().deleteDomainRoleMember(ctx, domainName, "user.todelete", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), ROLE, domainName, "some-role", "deleteDomainRoleMember");
// putQuota events
ctx = zmsTestInitializer.contextWithMockPrincipal("putQuota");
Quota quota = new Quota().setName(domainName).setRole(14).setRoleMember(15).setGroup(16);
zmsTestInitializer.getZms().putQuota(ctx, domainName, zmsTestInitializer.getAuditRef(), quota);
assertSingleChangeMessage(ctx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "putQuota");
// deleteQuota events
ctx = zmsTestInitializer.contextWithMockPrincipal("deleteQuota");
zmsTestInitializer.getZms().deleteQuota(ctx, domainName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(ctx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "deleteQuota");
// postSubDomain events
RsrcCtxWrapper subCtx = zmsTestInitializer.contextWithMockPrincipal("postSubDomain");
SubDomain subDomain = zmsTestInitializer.createSubDomainObject("AddSubDom1", domainName, "Test Domain2", null, zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postSubDomain(subCtx, domainName, zmsTestInitializer.getAuditRef(), subDomain);
assertSingleChangeMessage(subCtx.getDomainChangeMessages(), DOMAIN, "test-dom-change-msg.addsubdom1", "test-dom-change-msg.addsubdom1", "postSubDomain");
// deleteSubDomain events
RsrcCtxWrapper deleteCtx = zmsTestInitializer.contextWithMockPrincipal("deleteSubDomain");
zmsTestInitializer.getZms().deleteSubDomain(deleteCtx, domainName, "AddSubDom1", zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(deleteCtx.getDomainChangeMessages(), DOMAIN, "test-dom-change-msg.addsubdom1", "test-dom-change-msg.addsubdom1", "deleteSubDomain");
// deleteTopLevelDomain events
deleteCtx = zmsTestInitializer.contextWithMockPrincipal("deleteTopLevelDomain");
zmsTestInitializer.getZms().deleteTopLevelDomain(deleteCtx, domainName, zmsTestInitializer.getAuditRef());
assertSingleChangeMessage(deleteCtx.getDomainChangeMessages(), DOMAIN, domainName, domainName, "deleteTopLevelDomain");
}
use of com.yahoo.athenz.common.messaging.DomainChangeMessage in project athenz by yahoo.
the class RsrcCtxWrapperTest method testDomainChangeMessage.
@Test
public void testDomainChangeMessage() {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Object timerMetric = new Object();
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, timerMetric, "apiName", true);
assertNull(wrapper.getDomainChangeMessages());
// add domain msg
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain1Name").setObjectName("domain1Name1").setObjectType(DOMAIN));
// add domain msg for the same domain - should be ignored
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain1Name").setObjectName("domain1Name2").setObjectType(DOMAIN));
// add role msg for the same domain
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain1Name").setObjectName("domain1role").setObjectType(ROLE));
// add domain msg for other domain
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain2Name").setObjectName("domain2Name1").setObjectType(DOMAIN));
List<DomainChangeMessage> messages = wrapper.getDomainChangeMessages();
assertEquals(messages.size(), 3);
assertEquals(messages.get(0).getDomainName(), "domain1Name");
assertEquals(messages.get(1).getDomainName(), "domain1Name");
assertEquals(messages.get(2).getDomainName(), "domain2Name");
assertEquals(messages.get(0).getObjectType(), DOMAIN);
assertEquals(messages.get(1).getObjectType(), ROLE);
assertEquals(messages.get(2).getObjectType(), DOMAIN);
assertEquals(messages.get(0).getObjectName(), "domain1Name1");
assertEquals(messages.get(1).getObjectName(), "domain1role");
assertEquals(messages.get(2).getObjectName(), "domain2Name1");
}
use of com.yahoo.athenz.common.messaging.DomainChangeMessage in project athenz by yahoo.
the class PulsarChangePublisherTest method test_publisher_creation.
@Test
public void test_publisher_creation() {
System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
PulsarChangePublisher<DomainChangeMessage> publisher = new PulsarChangePublisher<>(serviceUrl(), "some-topic", new TlsConfig("cert", "key", "trust"));
publisher.publish(new DomainChangeMessage());
publisher.close();
assertNotNull(getPulsarProducer(publisher));
System.clearProperty(PROP_MESSAGING_CLI_SERVICE_URL);
}
use of com.yahoo.athenz.common.messaging.DomainChangeMessage in project athenz by yahoo.
the class PulsarFactoryTest method test_publisher_creation.
@Test
public void test_publisher_creation() {
System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
System.setProperty(PROP_MESSAGING_CLI_CERT_PATH, "cert");
System.setProperty(PROP_MESSAGING_CLI_KEY_PATH, "key");
System.setProperty(PROP_MESSAGING_CLI_TRUST_STORE_PATH, "trust");
PulsarFactory<DomainChangeMessage> factory = new PulsarFactory<>();
PulsarChangePublisher<DomainChangeMessage> publisher = (PulsarChangePublisher<DomainChangeMessage>) factory.create(null, "topic");
publisher.publish(new DomainChangeMessage());
assertNotNull(getPulsarProducer(publisher));
System.clearProperty(PROP_MESSAGING_CLI_SERVICE_URL);
System.clearProperty(PROP_MESSAGING_CLI_CERT_PATH);
System.clearProperty(PROP_MESSAGING_CLI_KEY_PATH);
System.clearProperty(PROP_MESSAGING_CLI_TRUST_STORE_PATH);
}
Aggregations