NO-JIRA fixing tests after ARTEMIS-2889 changes broke them

This commit is contained in:
Justin Bertram 2020-09-17 09:50:41 -05:00
parent bc1f841244
commit b89690813d
1 changed files with 20 additions and 15 deletions

View File

@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
@ -349,6 +350,8 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
@Test
public void testNewUserAndRole() throws Exception {
final String USERNAME = UUID.randomUUID().toString();
final String ROLE = UUID.randomUUID().toString();
server.getConfiguration().setSecurityInvalidationInterval(0);
server.start();
String queue = "queue1";
@ -357,7 +360,7 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
// authentication should fail
try {
cf.createSession("third", "secret", false, true, true, false, 0);
cf.createSession(USERNAME, "secret", false, true, true, false, 0);
Assert.fail("Creating a session here should fail due to the original security data.");
} catch (ActiveMQException e) {
Assert.assertTrue(e.getMessage().contains("229031")); // authentication exception
@ -372,23 +375,23 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
objclass.add("simpleSecurityObject");
objclass.add("account");
basicAttributes.put(objclass);
ctx.bind("uid=third,ou=system", null, basicAttributes);
ctx.bind("uid=" + USERNAME + ",ou=system", null, basicAttributes);
}
{ // add new role
DirContext ctx = getContext();
BasicAttributes basicAttributes = new BasicAttributes();
basicAttributes.put("member", "uid=third,ou=system");
basicAttributes.put("member", "uid=" + USERNAME + ",ou=system");
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("groupOfNames");
basicAttributes.put(objclass);
ctx.bind("cn=role3,ou=system", null, basicAttributes);
ctx.bind("cn=" + ROLE + ",ou=system", null, basicAttributes);
}
// authentication should succeed now, but authorization for sending should still fail
try {
ClientSession session = cf.createSession("third", "secret", false, true, true, false, 0);
ClientSession session = cf.createSession(USERNAME, "secret", false, true, true, false, 0);
ClientProducer producer = session.createProducer(queue);
producer.send(session.createMessage(true));
Assert.fail("Producing here should fail due to the original security data.");
@ -399,12 +402,12 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
{ // add write/send permission for new role to existing "queue1"
DirContext ctx = getContext();
BasicAttributes basicAttributes = new BasicAttributes();
basicAttributes.put("uniquemember", "cn=role3");
basicAttributes.put("uniquemember", "cn=" + ROLE);
ctx.modifyAttributes("cn=write,cn=queue1,ou=queues,ou=destinations,o=ActiveMQ,ou=system", DirContext.ADD_ATTRIBUTE, basicAttributes);
ctx.close();
}
ClientSession session = cf.createSession("third", "secret", false, true, true, false, 0);
ClientSession session = cf.createSession(USERNAME, "secret", false, true, true, false, 0);
ClientProducer producer = session.createProducer(queue);
producer.send(session.createMessage(true));
@ -413,6 +416,8 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
@Test
public void testNewUserAndRoleWithNewDestination() throws Exception {
final String USERNAME = UUID.randomUUID().toString();
final String ROLE = UUID.randomUUID().toString();
server.getConfiguration().setSecurityInvalidationInterval(0);
server.start();
ClientSessionFactory cf = locator.createSessionFactory();
@ -423,7 +428,7 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
// authentication should fail
try {
cf.createSession("third", "secret", false, true, true, false, 0);
cf.createSession(USERNAME, "secret", false, true, true, false, 0);
Assert.fail("Creating a session here should fail due to the original security data.");
} catch (ActiveMQException e) {
Assert.assertTrue(e.getMessage().contains("229031")); // authentication exception
@ -438,23 +443,23 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
objclass.add("simpleSecurityObject");
objclass.add("account");
basicAttributes.put(objclass);
ctx.bind("uid=third,ou=system", null, basicAttributes);
ctx.bind("uid=" + USERNAME + ",ou=system", null, basicAttributes);
}
{ // add new role
DirContext ctx = getContext();
BasicAttributes basicAttributes = new BasicAttributes();
basicAttributes.put("member", "uid=third,ou=system");
basicAttributes.put("member", "uid=" + USERNAME + ",ou=system");
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("groupOfNames");
basicAttributes.put(objclass);
ctx.bind("cn=role3,ou=system", null, basicAttributes);
ctx.bind("cn=" + ROLE + ",ou=system", null, basicAttributes);
}
// authentication should succeed now, but authorization for sending should still fail
try {
ClientSession session = cf.createSession("third", "secret", false, true, true, false, 0);
ClientSession session = cf.createSession(USERNAME, "secret", false, true, true, false, 0);
ClientProducer producer = session.createProducer(goodQueue);
producer.send(session.createMessage(true));
Assert.fail("Producing here should fail due to the original security data.");
@ -475,7 +480,7 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
{ // add permissions for new destination
DirContext ctx = getContext();
BasicAttributes basicAttributes = new BasicAttributes();
basicAttributes.put("uniquemember", "cn=role3");
basicAttributes.put("uniquemember", "cn=" + ROLE);
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("groupOfUniqueNames");
@ -485,7 +490,7 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
server.createQueue(new QueueConfiguration(goodQueue).setRoutingType(RoutingType.ANYCAST).setDurable(false));
ClientSession session = cf.createSession("third", "secret", false, true, true, false, 0);
ClientSession session = cf.createSession(USERNAME, "secret", false, true, true, false, 0);
ClientProducer producer = session.createProducer(goodQueue);
producer.send(session.createMessage(true));
session.close();
@ -495,7 +500,7 @@ public class LegacyLDAPSecuritySettingPluginListenerTest extends AbstractLdapTes
// authorization for sending should fail for the new queue
try {
session = cf.createSession("third", "secret", false, true, true, false, 0);
session = cf.createSession(USERNAME, "secret", false, true, true, false, 0);
producer = session.createProducer(badQueue);
producer.send(session.createMessage(true));
Assert.fail("Producing here should fail.");