adelapena commented on code in PR #2146: URL: https://github.com/apache/cassandra/pull/2146#discussion_r1105969944
########## test/unit/org/apache/cassandra/cql3/functions/masking/QueryMaskedPermissionTest.java: ########## @@ -0,0 +1,391 @@ +/* + * 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.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#SELECT_MASKED} permission. + */ +public class QueryMaskedPermissionTest extends CQLTester +{ + private static final Object[] CLEAR_ROW = row(7, 7, 7, 7); + + private static final String USER = "ddm_user"; // user that will have their permissions changed + private static final String PASSWORD = "ddm_password"; + + @BeforeClass + public static void beforeClass() + { + CQLTester.setUpClass(); + requireAuthentication(); + requireNetwork(); + } + + @Before + public void before() throws Throwable + { + useSuperUser(); + + createTable("CREATE TABLE %s (k int, c int, s int static, v int, PRIMARY KEY (k, c))"); + executeNet("INSERT INTO %s(k, c, s, v) VALUES (?, ?, ?, ?)", CLEAR_ROW); + + executeNet(format("CREATE USER IF NOT EXISTS %s WITH PASSWORD '%s'", USER, PASSWORD)); + executeNet(format("GRANT SELECT ON ALL KEYSPACES TO %s", USER)); + } + + @After + public void after() throws Throwable + { + useSuperUser(); + executeNet("DROP USER IF EXISTS " + USER); + alterTable("ALTER TABLE %s ALTER k DROP MASKED"); + alterTable("ALTER TABLE %s ALTER c DROP MASKED"); + alterTable("ALTER TABLE %s ALTER s DROP MASKED"); + alterTable("ALTER TABLE %s ALTER v DROP MASKED"); + } + + @Test + public void testPartitionKeyColumn() throws Throwable + { + alterTable("ALTER TABLE %s ALTER k MASKED WITH DEFAULT"); + Object[] maskedRow = row(0, 7, 7, 7); + + // test queries with default permissions (no UNMASK nor SELECT_MASKED) + assertWithAuthSpin(() -> { Review Comment: I think that the queries tested of every block are different to each other. And the blocks are different to each other on whether they return a masked or unmasked row, or an authorization failure. The only blocks that are repeated are the ones for only `UNMASK` permission and for both `UNMASK` and `SELECT_MASKED` permissions, and the ones for defaults and manually removed permissions. I can put those pairs on blocks on separate methods to save some duplication, although I'm not sure that actually improves readability. As for the differences test to test, they might look similar but they aren't identical, since different schemas allow different queries. -- 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]

