|
44 | 44 | import org.apache.cassandra.audit.AuditLogEntryType; |
45 | 45 | import org.apache.cassandra.audit.AuditLogManager; |
46 | 46 | import org.apache.cassandra.audit.DiagnosticEventAuditLogger; |
| 47 | +import org.apache.cassandra.auth.AuthTestUtils; |
47 | 48 | import org.apache.cassandra.auth.CassandraRoleManager; |
48 | 49 | import org.apache.cassandra.auth.PasswordAuthenticator; |
49 | 50 | import org.apache.cassandra.config.DatabaseDescriptor; |
@@ -78,6 +79,8 @@ public static void setup() throws Exception |
78 | 79 | SUPERUSER_SETUP_DELAY_MS.setLong(0); |
79 | 80 |
|
80 | 81 | embedded = ServerTestUtils.startEmbeddedCassandraService(); |
| 82 | + AuthTestUtils.waitForExistingRoles(); |
| 83 | + |
81 | 84 |
|
82 | 85 | executeAs(Arrays.asList("CREATE ROLE testuser WITH LOGIN = true AND SUPERUSER = false AND PASSWORD = 'foo'", |
83 | 86 | "CREATE ROLE testuser_nologin WITH LOGIN = false AND SUPERUSER = false AND PASSWORD = 'foo'", |
@@ -214,20 +217,23 @@ private static ArrayList<AuditEvent> executeAs(List<String> queries, String user |
214 | 217 | AuditLogEntryType expectedAuthType) throws Exception |
215 | 218 | { |
216 | 219 | boolean authFailed = false; |
217 | | - Cluster cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress()) |
| 220 | + try(Cluster cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress()) |
218 | 221 | .withoutJMXReporting() |
219 | 222 | .withCredentials(username, password) |
220 | | - .withPort(DatabaseDescriptor.getNativeTransportPort()).build(); |
221 | | - try (Session session = cluster.connect()) |
222 | | - { |
223 | | - for (String query : queries) |
224 | | - session.execute(query); |
225 | | - } |
226 | | - catch (AuthenticationException e) |
| 223 | + .withPort(DatabaseDescriptor.getNativeTransportPort()).build()) |
227 | 224 | { |
228 | | - authFailed = true; |
| 225 | + try (Session session = cluster.connect()) |
| 226 | + { |
| 227 | + for (String query : queries) |
| 228 | + session.execute(query); |
| 229 | + } |
| 230 | + catch (AuthenticationException e) |
| 231 | + { |
| 232 | + if (expectedAuthType == null) |
| 233 | + throw e; |
| 234 | + authFailed = true; |
| 235 | + } |
229 | 236 | } |
230 | | - cluster.close(); |
231 | 237 |
|
232 | 238 | if (expectedAuthType == null) return null; |
233 | 239 |
|
|
0 commit comments