diff --git a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyAudit.java b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyAudit.java index 2363420d..b65834a3 100644 --- a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyAudit.java +++ b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyAudit.java @@ -97,10 +97,10 @@ public static void beforeClass() throws Exception "ALTER ROLE cassandra WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/system_schema' }")); session.execute(new SimpleStatement( - "CREATE KEYSPACE ecks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); - session.execute(new SimpleStatement("CREATE TABLE ecks.ectbl (partk int PRIMARY KEY, clustk text, value text)")); + "CREATE KEYSPACE ecks_itva WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); + session.execute(new SimpleStatement("CREATE TABLE ecks_itva.ectbl (partk int PRIMARY KEY, clustk text, value text)")); session.execute(new SimpleStatement( - "CREATE TABLE ecks.ectypetbl (partk int PRIMARY KEY, v0 text, v1 ascii, v2 bigint, v3 blob, v4 boolean, " + "CREATE TABLE ecks_itva.ectypetbl (partk int PRIMARY KEY, v0 text, v1 ascii, v2 bigint, v3 blob, v4 boolean, " + "v5 date, v6 decimal, v7 double, v8 float, v9 inet, v10 int, v11 smallint, v12 time, v13 timestamp, " + "v14 uuid, v15 varchar, v16 varint)")); @@ -114,17 +114,17 @@ public static void beforeClass() throws Exception session.execute(new SimpleStatement( "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/system_schema'}")); session.execute(new SimpleStatement( - "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/ectbl'}")); + "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itva/ectbl'}")); session.execute(new SimpleStatement( "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/nonexistingks'}")); session.execute(new SimpleStatement( - "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/nonexistingtbl'}")); + "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itva/nonexistingtbl'}")); session.execute(new SimpleStatement( "ALTER ROLE sam WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'connections'}")); session.execute(new SimpleStatement( - "GRANT MODIFY ON ecks.ectbl TO sam")); + "GRANT MODIFY ON ecks_itva.ectbl TO sam")); session.execute(new SimpleStatement( - "GRANT SELECT ON ecks.ectbl TO sam")); + "GRANT SELECT ON ecks_itva.ectbl TO sam")); session.execute(new SimpleStatement( "CREATE ROLE foo WITH PASSWORD = 'secret' AND LOGIN = true AND SUPERUSER = true")); @@ -176,14 +176,20 @@ public void after() @AfterClass public static void afterClass() { - session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS ecuser")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS foo")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS bar")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS mute")); - - session.close(); - cluster.close(); + if(session != null) + { + session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks_itva")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS ecuser")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS foo")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS bar")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS mute")); + + session.close(); + } + if(cluster != null) + { + cluster.close(); + } } @Test @@ -291,18 +297,18 @@ public void testValidSimpleStatementsAreLogged() public void testValidPreparedStatementsAreLogged() { PreparedStatement preparedInsertStatement = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); + .prepare("INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); PreparedStatement preparedSelectStatement = session - .prepare("SELECT * FROM ecks.ectbl WHERE partk = ?"); - PreparedStatement preparedDeleteStatement = session.prepare("DELETE FROM ecks.ectbl WHERE partk = ?"); + .prepare("SELECT * FROM ecks_itva.ectbl WHERE partk = ?"); + PreparedStatement preparedDeleteStatement = session.prepare("DELETE FROM ecks_itva.ectbl WHERE partk = ?"); List expectedStatements = Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[1, '1', 'valid']", - "SELECT * FROM ecks.ectbl WHERE partk = ?[1]", - "DELETE FROM ecks.ectbl WHERE partk = ?[1]", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[2, '2', 'valid']", - "SELECT * FROM ecks.ectbl WHERE partk = ?[2]", - "DELETE FROM ecks.ectbl WHERE partk = ?[2]"); + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)[1, '1', 'valid']", + "SELECT * FROM ecks_itva.ectbl WHERE partk = ?[1]", + "DELETE FROM ecks_itva.ectbl WHERE partk = ?[1]", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)[2, '2', 'valid']", + "SELECT * FROM ecks_itva.ectbl WHERE partk = ?[2]", + "DELETE FROM ecks_itva.ectbl WHERE partk = ?[2]"); for (int i = 1; i <= 2; i++) { @@ -326,22 +332,22 @@ public void testValidPreparedStatementsAreLogged() public void testValidBatchStatementsAreLogged() { PreparedStatement preparedInsertStatement1 = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); + .prepare("INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); PreparedStatement preparedInsertStatement2 = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')"); + .prepare("INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')"); List expectedStatements = Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[1, '1', 'valid']", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[2, '2', 'valid']", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')[3, '3']", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')[5, '5']"); + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)[1, '1', 'valid']", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?)[2, '2', 'valid']", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')[3, '3']", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, 'valid')[5, '5']"); BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED); batch.add(preparedInsertStatement1.bind(1, "1", "valid")); batch.add(preparedInsertStatement1.bind(2, "2", "valid")); batch.add(preparedInsertStatement2.bind(3, "3")); - batch.add(new SimpleStatement("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')")); + batch.add(new SimpleStatement("INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')")); batch.add(preparedInsertStatement2.bind(5, "5")); session.execute(batch); @@ -361,11 +367,11 @@ public void testValidBatchStatementsAreLogged() public void testValidNonPreparedBatchStatementsAreLogged() { List allStatements = Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (1, '1', 'valid')", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (2, '2', 'valid')", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (3, '3', 'valid')", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (5, '5', 'valid')"); + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (1, '1', 'valid')", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (2, '2', 'valid')", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (3, '3', 'valid')", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (5, '5', 'valid')"); StringBuilder batchStatementBuilder = new StringBuilder("BEGIN UNLOGGED BATCH "); for (String statement : allStatements) @@ -393,8 +399,8 @@ public void testValidNonPreparedBatchStatementsAreLogged() public void testValidPreparedBatchStatementsAreLogged() { String statement = "BEGIN UNLOGGED BATCH USING TIMESTAMP ? " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?); " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'valid'); " + + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, ?); " + + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (?, ?, 'valid'); " + "APPLY BATCH;"; List expectedStatements = Collections.singletonList(statement + "[1234, 1, '1', 'valid', 3, '3']"); @@ -417,12 +423,12 @@ public void testValidPreparedBatchStatementsAreLogged() public void testValidPreparedStatementTypesAreLogged() throws Exception { PreparedStatement preparedStatement = session - .prepare("INSERT INTO ecks.ectypetbl " + .prepare("INSERT INTO ecks_itva.ectypetbl " + "(partk, v0, v1, v2, v4, v5, v9, v13, v15)" + " VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?)"); - String expectedStatement = "INSERT INTO ecks.ectypetbl " + String expectedStatement = "INSERT INTO ecks_itva.ectypetbl " + "(partk, v0, v1, v2, v4, v5, v9, v13, v15)" + " VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?)[1, 'text', 'ascii', 123123123123123123, true, 1976-02-25, 8.8.8.8, 2004-05-29T14:29:00.000Z, 'varchar']"; @@ -449,7 +455,7 @@ public void testValidPreparedStatementTypesAreLogged() throws Exception @Test public void testValidSimpleStatementTypesAreLogged() { - String statement = "INSERT INTO ecks.ectypetbl " + String statement = "INSERT INTO ecks_itva.ectypetbl " + "(partk, v0, v1, v2, v4, v5, v9, v13, v15)" + " VALUES " + "(1, 'text', 'ascii', 123123123123123123, true, '1976-02-25', '8.8.8.8', '2004-05-29T14:29:00.000Z', 'varchar')"; @@ -501,9 +507,9 @@ public void testWhitelistedUserValidStatementsWithUseAreNotLogged() // Driver or Cassandra will add double-quotes to ks on one of the connections if statemens doesn't have it here. // TODO: Research if this is "bug" in Cassandra, driver or ecAudit? List statements = Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (1, 'one', 'valid')", - "SELECT * FROM ecks.ectbl", - "USE \"ecks\"", + "INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (1, 'one', 'valid')", + "SELECT * FROM ecks_itva.ectbl", + "USE \"ecks_itva\"", "INSERT INTO ectbl (partk, clustk, value) VALUES (1, 'one', 'valid')", "SELECT * FROM ectbl"); @@ -527,7 +533,7 @@ public void testWhitelistedUserValidStatementsWithUseAreNotLogged() .stream() .map(ILoggingEvent::getFormattedMessage) .collect(Collectors.toList())) - .containsOnlyElementsOf(expectedAttemptsAsUser(Arrays.asList("USE \"ecks\""), user)); + .containsOnlyElementsOf(expectedAttemptsAsUser(Arrays.asList("USE \"ecks_itva\""), user)); } /** @@ -544,7 +550,7 @@ public void testMultipleUseStatementsPreserveOrder() try (Cluster privateCluster = cdt.createCluster(user, "secret"); Session privateSession = privateCluster.connect()) { - executeOneUseWithFollowingSelect(user, privateSession, "USE \"ecks\""); + executeOneUseWithFollowingSelect(user, privateSession, "USE \"ecks_itva\""); executeOneUseWithFollowingSelect(user, privateSession, "USE \"ecks2\""); executeOneUseWithFollowingSelect(user, privateSession, "USE \"ecks3\""); } @@ -553,14 +559,14 @@ public void testMultipleUseStatementsPreserveOrder() private void executeOneUseWithFollowingSelect(String user, Session privateSession, String useStatement) { ArgumentCaptor loggingEventCaptor1 = ArgumentCaptor.forClass(ILoggingEvent.class); privateSession.execute(new SimpleStatement(useStatement)); - privateSession.execute(new SimpleStatement("SELECT * FROM ecks.ectypetbl")); + privateSession.execute(new SimpleStatement("SELECT * FROM ecks_itva.ectypetbl")); verify(mockAuditAppender, atLeast(2)).doAppend(loggingEventCaptor1.capture()); List loggingEvents1 = loggingEventCaptor1.getAllValues(); assertThat(loggingEvents1 .stream() .map(ILoggingEvent::getFormattedMessage) .collect(Collectors.toList())) - .containsOnlyElementsOf(expectedAttemptsAsUser(Arrays.asList(useStatement, "SELECT * FROM ecks.ectypetbl"), user)); + .containsOnlyElementsOf(expectedAttemptsAsUser(Arrays.asList(useStatement, "SELECT * FROM ecks_itva.ectypetbl"), user)); reset(mockAuditAppender); } @@ -569,11 +575,11 @@ public void testFailedStatementsAreLogged() { List statements = Arrays.asList( "CREATE ROLE ecuser WITH PASSWORD = 'secret' AND LOGIN = true", - "CREATE KEYSPACE ecks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false", - "CREATE TABLE ecks.ectbl (partk int PRIMARY KEY, clustk text, value text)", + "CREATE KEYSPACE ecks_itva WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false", + "CREATE TABLE ecks_itva.ectbl (partk int PRIMARY KEY, clustk text, value text)", "INSERT INTO invalidks.invalidtbl (partk, clustk, value) VALUES (1, 'one', 'valid')", "SELECT * FROM invalidks.invalidtbl", - "SELECT * FROM ecks.invalidtbl", + "SELECT * FROM ecks_itva.invalidtbl", "DELETE FROM invalidks.invalidtbl WHERE partk = 2", "DROP KEYSPACE invalidks", "DROP ROLE invaliduser", @@ -600,9 +606,9 @@ public void testFailedWhitelistedStatementsAreNotLogged() { List statements = Arrays.asList( "SELECT * FROM nonexistingks.nonexistingtbl", - "SELECT * FROM ecks.nonexistingtbl", + "SELECT * FROM ecks_itva.nonexistingtbl", "INSERT INTO nonexistingks.nonexistingtbl (partk, clustk, value) VALUES (1, 'one', 'valid')", - "INSERT INTO ecks.nonexistingtbl (partk, clustk, value) VALUES (1, 'one', 'valid')"); + "INSERT INTO ecks_itva.nonexistingtbl (partk, clustk, value) VALUES (1, 'one', 'valid')"); try (Cluster privateCluster = cdt.createCluster("sam", "secret"); Session privateSession = privateCluster.connect()) @@ -627,7 +633,7 @@ public void testFailedWhitelistedBatchStatementIsNotLogged() for (String statement : statements) { BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED); - batch.add(new SimpleStatement("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')")); + batch.add(new SimpleStatement("INSERT INTO ecks_itva.ectbl (partk, clustk, value) VALUES (4, '4', 'valid')")); batch.add(new SimpleStatement(statement)); assertThatExceptionOfType(InvalidQueryException.class).isThrownBy(() -> privateSession.execute(batch)); } diff --git a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyThreadedAudit.java b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyThreadedAudit.java index be65abbd..75b6673d 100644 --- a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyThreadedAudit.java +++ b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyThreadedAudit.java @@ -75,9 +75,9 @@ public static void beforeClass() throws Exception { session.execute(new SimpleStatement( - "CREATE KEYSPACE ecks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); + "CREATE KEYSPACE ecks_itvta WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); session.execute(new SimpleStatement( - "CREATE TABLE ecks.ectbl (partk int PRIMARY KEY, clustk text, value text)")); + "CREATE TABLE ecks_itvta.ectbl (partk int PRIMARY KEY, clustk text, value text)")); session.execute(new SimpleStatement( "CREATE ROLE test_role WITH LOGIN = false")); @@ -88,9 +88,9 @@ public static void beforeClass() throws Exception session.execute(new SimpleStatement( "ALTER ROLE test_role WITH OPTIONS = { 'grant_audit_whitelist_for_execute' : 'connections' }")); session.execute(new SimpleStatement( - "GRANT MODIFY ON ecks.ectbl TO test_role")); + "GRANT MODIFY ON ecks_itvta.ectbl TO test_role")); session.execute(new SimpleStatement( - "GRANT SELECT ON ecks.ectbl TO test_role")); + "GRANT SELECT ON ecks_itvta.ectbl TO test_role")); for (int i = 0; i < USER_COUNT; i++) { @@ -121,7 +121,7 @@ public static void afterClass() try (Cluster cluster = cdt.createCluster(); Session session = cluster.connect()) { - session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks")); + session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks_itvta")); session.execute(new SimpleStatement("DROP ROLE IF EXISTS test_role")); for (int i = 0; i < USER_COUNT; i++) { @@ -191,21 +191,21 @@ public List call() Session privateSession = privateCluster.connect()) { PreparedStatement preparedInsertStatement = privateSession - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); + .prepare("INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); PreparedStatement preparedSelectStatement = privateSession - .prepare("SELECT * FROM ecks.ectbl WHERE partk = ?"); + .prepare("SELECT * FROM ecks_itvta.ectbl WHERE partk = ?"); PreparedStatement preparedDeleteStatement = privateSession - .prepare("DELETE FROM ecks.ectbl WHERE partk = ?"); + .prepare("DELETE FROM ecks_itvta.ectbl WHERE partk = ?"); List expectedStatements = new ArrayList<>(); for (int i = 0; i < 100; i++) { expectedStatements.addAll(Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + i + ", '" + i + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + i + ", '" + i + "', 'valid']", - "SELECT * FROM ecks.ectbl WHERE partk = ?[" + i + "]", - "DELETE FROM ecks.ectbl WHERE partk = ?[" + i + "]")); + "SELECT * FROM ecks_itvta.ectbl WHERE partk = ?[" + i + "]", + "DELETE FROM ecks_itvta.ectbl WHERE partk = ?[" + i + "]")); privateSession.execute(preparedInsertStatement.bind(i, Integer.toString(i), "valid")); privateSession.execute(preparedSelectStatement.bind(i)); @@ -233,22 +233,22 @@ public List call() Session session = cluster.connect()) { PreparedStatement preparedInsertStatement1 = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); + .prepare("INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?)"); PreparedStatement preparedInsertStatement2 = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'static')"); + .prepare("INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, 'static')"); PreparedStatement preparedInsertStatement3 = session - .prepare("INSERT INTO ecks.ectbl (partk, clustk) VALUES (?, ?)"); + .prepare("INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (?, ?)"); List expectedStatements = new ArrayList<>(); for (int i = 0; i < 10; i++) { expectedStatements.addAll(Arrays.asList( - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + (100 + i) + ", '1', 'b1']", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + (200 + i) + ", '2', 'b2']", - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'static')[" + (300 + i) + ", '3']", - "INSERT INTO ecks.ectbl (partk, clustk) VALUES (?, ?)[" + (400 + i) + ", '4']", - "INSERT INTO ecks.ectbl (partk, clustk) VALUES (?, ?)[" + (500 + i) + ", '5']")); + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + (100 + i) + ", '1', 'b1']", + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?)[" + (200 + i) + ", '2', 'b2']", + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, 'static')[" + (300 + i) + ", '3']", + "INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (?, ?)[" + (400 + i) + ", '4']", + "INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (?, ?)[" + (500 + i) + ", '5']")); BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED); batch.add(preparedInsertStatement1.bind(100 + i, "1", "b1")); batch.add(preparedInsertStatement1.bind(200 + i, "2", "b2")); @@ -283,11 +283,11 @@ public List call() for (int i = 0; i < 10; i++) { String batchStatement = "BEGIN UNLOGGED BATCH " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (" + (100 + i) + ", '1', 'b1'); " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (" + (200 + i) + ", '2', 'b2'); " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (" + (300 + i) + ", '3', 'static'); " + - "INSERT INTO ecks.ectbl (partk, clustk) VALUES (" + (400 + i) + ", '4'); " + - "INSERT INTO ecks.ectbl (partk, clustk) VALUES (" + (500 + i) + ", '5'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (" + (100 + i) + ", '1', 'b1'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (" + (200 + i) + ", '2', 'b2'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (" + (300 + i) + ", '3', 'static'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (" + (400 + i) + ", '4'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (" + (500 + i) + ", '5'); " + "APPLY BATCH;"; expectedStatements.add(batchStatement); session.execute(batchStatement); @@ -314,9 +314,9 @@ public List call() Session session = cluster.connect()) { String batch = "BEGIN UNLOGGED BATCH USING TIMESTAMP ? " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, ?); " + - "INSERT INTO ecks.ectbl (partk, clustk, value) VALUES (?, ?, 'static'); " + - "INSERT INTO ecks.ectbl (partk, clustk) VALUES (?, ?); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, ?); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk, value) VALUES (?, ?, 'static'); " + + "INSERT INTO ecks_itvta.ectbl (partk, clustk) VALUES (?, ?); " + "APPLY BATCH;"; PreparedStatement preparedBatchStatement = session.prepare(batch); diff --git a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyWhitelistManagement.java b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyWhitelistManagement.java index 6538aa7f..4647b69b 100644 --- a/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyWhitelistManagement.java +++ b/integration-test-standard/src/test/java/com/ericsson/bss/cassandra/ecaudit/integration/standard/ITVerifyWhitelistManagement.java @@ -77,19 +77,19 @@ public static void beforeClass() throws Exception session = cluster.connect(); session.execute(new SimpleStatement( - "CREATE KEYSPACE ecks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); + "CREATE KEYSPACE ecks_itvwm WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} AND DURABLE_WRITES = false")); session.execute(new SimpleStatement( - "CREATE TABLE ecks.ectbl (partk int PRIMARY KEY, clustk text, value text)")); + "CREATE TABLE ecks_itvwm.ectbl (partk int PRIMARY KEY, clustk text, value text)")); session.execute(new SimpleStatement( "CREATE ROLE ordinary_user WITH PASSWORD = 'secret' AND LOGIN = true")); session.execute(new SimpleStatement( - "GRANT SELECT ON TABLE ecks.ectbl TO ordinary_user")); + "GRANT SELECT ON TABLE ecks_itvwm.ectbl TO ordinary_user")); session.execute(new SimpleStatement( "CREATE ROLE create_user WITH PASSWORD = 'secret' AND LOGIN = true")); session.execute(new SimpleStatement( - "GRANT SELECT ON TABLE ecks.ectbl TO create_user")); + "GRANT SELECT ON TABLE ecks_itvwm.ectbl TO create_user")); session.execute(new SimpleStatement( "GRANT CREATE ON ALL ROLES TO create_user")); @@ -99,7 +99,7 @@ public static void beforeClass() throws Exception session.execute(new SimpleStatement( "CREATE ROLE authorized_user WITH PASSWORD = 'secret' AND LOGIN = true")); session.execute(new SimpleStatement( - "GRANT SELECT ON TABLE ecks.ectbl TO authorized_user")); + "GRANT SELECT ON TABLE ecks_itvwm.ectbl TO authorized_user")); session.execute(new SimpleStatement( "GRANT CREATE ON ALL ROLES TO authorized_user")); session.execute(new SimpleStatement( @@ -125,7 +125,7 @@ public static void beforeClass() throws Exception session.execute(new SimpleStatement( "CREATE ROLE trusted_user WITH PASSWORD = 'secret' AND LOGIN = true")); session.execute(new SimpleStatement( - "GRANT SELECT ON TABLE ecks.ectbl TO trusted_user")); + "GRANT SELECT ON TABLE ecks_itvwm.ectbl TO trusted_user")); session.execute(new SimpleStatement( "GRANT AUTHORIZE ON ROLE whitelist_role TO trusted_user")); session.execute(new SimpleStatement( @@ -147,21 +147,39 @@ public void after() @AfterClass public static void afterClass() { - authorizedSession.close(); - authorizedCluster.close(); - - superSession.close(); - superCluster.close(); + if(session != null) + { + session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks_itvwm")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS whitelist_role")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS ordinary_user")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS create_user")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS authorized_user")); + session.execute(new SimpleStatement("DROP ROLE IF EXISTS super_user")); + + session.close(); + } + if(cluster != null) + { + cluster.close(); + } - session.execute(new SimpleStatement("DROP KEYSPACE IF EXISTS ecks")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS whitelist_role")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS ordinary_user")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS create_user")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS authorized_user")); - session.execute(new SimpleStatement("DROP ROLE IF EXISTS super_user")); + if(superSession != null) + { + superSession.close(); + } + if(superCluster != null) + { + superCluster.close(); + } - session.close(); - cluster.close(); + if(authorizedSession != null) + { + authorizedCluster.close(); + } + if(authorizedCluster != null) + { + authorizedCluster.close(); + } } @Test @@ -288,9 +306,9 @@ public void testSuperUserCanWhitelistOnDataPartly() { given_temporary_user(superSession); superSession.execute(new SimpleStatement( - "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/ectbl' }")); + "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itvwm/ectbl' }")); - assertRoleOperations("temporary_user", "data/ecks/ectbl", asList("ALTER", "DROP", "SELECT", "MODIFY", "AUTHORIZE")); + assertRoleOperations("temporary_user", "data/ecks_itvwm/ectbl", asList("ALTER", "DROP", "SELECT", "MODIFY", "AUTHORIZE")); } @Test @@ -316,9 +334,9 @@ public void testSuperUserCanWhitelistOnNonexistingTable() { given_temporary_user(superSession); superSession.execute(new SimpleStatement( - "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/unknowntbl' }")); + "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itvwm/unknowntbl' }")); - assertRoleOperations("temporary_user", "data/ecks/unknowntbl", asList("ALTER", "DROP", "SELECT", "MODIFY", "AUTHORIZE")); + assertRoleOperations("temporary_user", "data/ecks_itvwm/unknowntbl", asList("ALTER", "DROP", "SELECT", "MODIFY", "AUTHORIZE")); } @Test (expected = InvalidQueryException.class) @@ -326,7 +344,7 @@ public void testSuperUserCanNotWhitelistOnInvalidTable() { given_temporary_user(superSession); superSession.execute(new SimpleStatement( - "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/unknown?tbl' }")); + "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itvwm/unknown?tbl' }")); } @Test (expected = InvalidQueryException.class) @@ -334,7 +352,7 @@ public void testSuperUserCanNotWhitelistTwoOperationsInOneStatement() { given_temporary_user(superSession); superSession.execute(new SimpleStatement( - "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_select' : 'data/ecks' ,'grant_audit_whitelist_for_modify' : 'data/ecks'}")); + "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_select' : 'data/ecks_itvwm' ,'grant_audit_whitelist_for_modify' : 'data/ecks_itvwm'}")); } @Test @@ -398,7 +416,7 @@ public void testSuperUserCanNotWhitelistOnInvalidDataResource() { given_temporary_user(superSession); superSession.execute(new SimpleStatement( - "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks/unknowntbl/invalid' }")); + "ALTER ROLE temporary_user WITH OPTIONS = { 'grant_audit_whitelist_for_all' : 'data/ecks_itvwm/unknowntbl/invalid' }")); } @Test (expected = InvalidQueryException.class)