adelapena commented on code in PR #2125:
URL: https://github.com/apache/cassandra/pull/2125#discussion_r1105716591


##########
test/unit/org/apache/cassandra/cql3/functions/masking/UnmaskPermissionTest.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.functions.masking;
+
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.exceptions.AuthenticationException;
+import com.datastax.driver.core.exceptions.UnauthorizedException;
+import org.apache.cassandra.cql3.CQLTester;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ThrowingRunnable;
+
+import static java.lang.String.format;
+
+/**
+ * Tests the {@link org.apache.cassandra.auth.Permission#UNMASK} permission.
+ * <p>
+ * The permission is tested for a regular user with the {@code UNMASK} 
permissions on different resources,
+ * while also verifying the absence of side effects on other ordinary users, 
superusers and internal queries.
+ */
+public class UnmaskPermissionTest extends CQLTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE IF NOT 
EXISTS %s WITH replication = " +
+                                                  "{'class': 'SimpleStrategy', 
'replication_factor': '1'}";
+    private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS 
%s.%s " +
+                                               "(k int, c int, v text MASKED 
WITH mask_replace('redacted'), " +
+                                               "PRIMARY KEY (k, c))";
+    private static final String INSERT = "INSERT INTO %s.%s (k, c, v) VALUES 
(?, ?, ?)";
+    private static final String SELECT_WILDCARD = "SELECT * FROM %s.%s";
+    private static final String SELECT_COLUMNS = "SELECT k, c, v FROM %s.%s";
+
+    private static final Object[] CLEAR_ROW = row(0, 0, "sensitive");
+    private static final Object[] MASKED_ROW = row(0, 0, "redacted");
+
+    private static final String KEYSPACE_1 = "mask_keyspace_1";
+    private static final String KEYSPACE_2 = "mask_keyspace_2";
+    private static final String TABLE_1 = "mask_table_1";
+    private static final String TABLE_2 = "mask_table_2";
+
+    private static final String USER = "ddm_user"; // user that will have 
their permissions changed
+    private static final String OTHER_USER = "ddm_ordinary_user"; // user that 
won't have their permissions altered
+    private static final String PASSWORD = "ddm_password";
+
+    @BeforeClass
+    public static void beforeClass()
+    {
+        CQLTester.setUpClass();
+        requireAuthentication();
+        requireNetwork();
+    }
+
+    @Before
+    public void before() throws Throwable
+    {
+        useSuperUser();
+
+        schemaChange(format(CREATE_KEYSPACE, KEYSPACE_1));
+        schemaChange(format(CREATE_KEYSPACE, KEYSPACE_2));
+
+        createTable(format(CREATE_TABLE, KEYSPACE_1, TABLE_1));
+        createTable(format(CREATE_TABLE, KEYSPACE_1, TABLE_2));
+        createTable(format(CREATE_TABLE, KEYSPACE_2, TABLE_1));
+
+        execute(format(INSERT, KEYSPACE_1, TABLE_1), CLEAR_ROW);
+        execute(format(INSERT, KEYSPACE_1, TABLE_2), CLEAR_ROW);
+        execute(format(INSERT, KEYSPACE_2, TABLE_1), CLEAR_ROW);
+
+        for (String user : Arrays.asList(USER, OTHER_USER))

Review Comment:
   Indeed we only need to create `OTHER_USER` once at the beginning of the 
class. However, the `CQLTester#executeNet` calls that we use here are instance 
methods, so they can't be called by a static `@BeforeClass` class method. As 
for `USER`, we drop it and recreate it on every test to reset its permissions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to