Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions phoenix-queryserver-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
<configuration>
<!-- dependency:analyze is quite useless for hadoop test dependencies -->
<ignoreNonCompile>true</ignoreNonCompile>
<!-- Engine is required at test runtime by Surefire; not referenced from test sources -->
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>org.junit.jupiter:junit-jupiter-engine</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -123,11 +127,23 @@
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package org.apache.phoenix.end2end;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.security.PrivilegedExceptionAction;
Expand All @@ -44,17 +44,14 @@
import org.apache.phoenix.queryserver.QueryServerOptions;
import org.apache.phoenix.queryserver.QueryServerProperties;
import org.apache.phoenix.queryserver.client.Driver;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
@Category(NeedsOwnMiniClusterTest.class)
@Tag("NeedsOwnMiniClusterTest")
public class HttpParamImpersonationQueryServerIT {

private static final Logger LOG = LoggerFactory.getLogger(HttpParamImpersonationQueryServerIT.class);
Expand All @@ -67,12 +64,7 @@ public class HttpParamImpersonationQueryServerIT {
PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_HBASE_TABLE_NAME,
PhoenixDatabaseMetaData.SYSTEM_STATS_HBASE_TABLE_NAME);

@Parameters(name = "tls = {0}")
public static synchronized Iterable<Boolean> data() {
return Arrays.asList(new Boolean[] {false, true});
}

public HttpParamImpersonationQueryServerIT(Boolean tls) throws Exception {
public void restartEnvironmentForTls(Boolean tls) throws Exception {
//Clean up previous environment if any (Junit 4.13 @BeforeParam / @AfterParam would be an alternative)
if(environment != null) {
stopEnvironment();
Expand All @@ -90,7 +82,7 @@ public HttpParamImpersonationQueryServerIT(Boolean tls) throws Exception {
environment = new QueryServerEnvironment(conf, 2, tls);
}

@AfterClass
@AfterAll
public static synchronized void stopEnvironment() throws Exception {
environment.stop();
}
Expand All @@ -106,8 +98,10 @@ private String getUrlTemplate() {
}
}

@Test
public void testSuccessfulImpersonation() throws Exception {
@ParameterizedTest(name = "tls = {0}")
@ValueSource(booleans = { false, true })
public void testSuccessfulImpersonation(Boolean tls) throws Exception {
restartEnvironmentForTls(tls);
final Entry<String,File> user1 = environment.getUser(1);
final Entry<String,File> user2 = environment.getUser(2);
// Build the JDBC URL by hand with the doAs
Expand Down Expand Up @@ -139,8 +133,10 @@ public void testSuccessfulImpersonation() throws Exception {
});
}

@Test
public void testDisallowedImpersonation() throws Exception {
@ParameterizedTest(name = "tls = {0}")
@ValueSource(booleans = { false, true })
public void testDisallowedImpersonation(Boolean tls) throws Exception {
restartEnvironmentForTls(tls);
final Entry<String,File> user2 = environment.getUser(2);
// Build the JDBC URL by hand with the doAs
final String doAsUrlTemplate = getUrlTemplate();
Expand Down Expand Up @@ -209,10 +205,10 @@ void readAndExpectPermissionError(String jdbcUrl, String tableName, int numRows)
LOG.debug("Caught expected exception", e);
// Avatica doesn't re-create new exceptions across the wire. Need to just look at the contents of the message.
String errorMessage = e.getMessage();
assertTrue("Expected the error message to contain an HBase AccessDeniedException", errorMessage.contains("org.apache.hadoop.hbase.security.AccessDeniedException"));
assertTrue(errorMessage.contains("org.apache.hadoop.hbase.security.AccessDeniedException"),"Expected the error message to contain an HBase AccessDeniedException");
// Expecting an error message like: "Insufficient permissions for user 'user1' (table=POSITIVE_IMPERSONATION, action=READ)"
// Being overly cautious to make sure we don't inadvertently pass the test due to permission errors on phoenix system tables.
assertTrue("Expected message to contain " + tableName + " and READ", errorMessage.contains(tableName) && errorMessage.contains("READ"));
assertTrue(errorMessage.contains(tableName) && errorMessage.contains("READ"),"Expected message to contain " + tableName + " and READ");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CATALOG;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.lang.reflect.Method;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -39,20 +40,16 @@
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.queryserver.QueryServerProperties;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.ThinClientUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -67,10 +64,8 @@ public class QueryServerBasicsIT extends BaseTest {
private static Configuration CONF;
private static String CONN_STRING;

@Rule
public TestName name = new TestName();

@BeforeClass
@BeforeAll
public static synchronized void doSetup() throws Exception {
setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);

Expand All @@ -89,16 +84,16 @@ public static synchronized void doSetup() throws Exception {
LOG.info("JDBC connection string is " + CONN_STRING);
}

@AfterClass
@AfterAll
public static synchronized void afterClass() throws Exception {
if (AVATICA_SERVER != null) {
AVATICA_SERVER.join(TimeUnit.MINUTES.toMillis(1));
Throwable t = AVATICA_SERVER.getQueryServer().getThrowable();
if (t != null) {
fail("query server threw. " + t.getMessage());
}
assertEquals("query server didn't exit cleanly", 0, AVATICA_SERVER.getQueryServer()
.getRetCode());
assertEquals(0, AVATICA_SERVER.getQueryServer()
.getRetCode(),"query server didn't exit cleanly");
}
}

Expand All @@ -108,7 +103,7 @@ public void testCatalogs() throws Exception {
assertFalse(connection.isClosed());
try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) {
final ResultSetMetaData metaData = resultSet.getMetaData();
assertFalse("unexpected populated resultSet", resultSet.next());
assertFalse(resultSet.next(),"unexpected populated resultSet");
assertEquals(1, metaData.getColumnCount());
assertEquals(TABLE_CAT, metaData.getColumnLabel(1));
}
Expand All @@ -124,22 +119,22 @@ public void testSchemas() throws Exception {
assertFalse(connection.isClosed());
try (final ResultSet resultSet = connection.getMetaData().getSchemas()) {
final ResultSetMetaData metaData = resultSet.getMetaData();
assertTrue("unexpected empty resultset", resultSet.next());
assertTrue(resultSet.next(),"unexpected empty resultset");
assertEquals(2, metaData.getColumnCount());
assertEquals(TABLE_SCHEM, metaData.getColumnLabel(1));
assertEquals(TABLE_CATALOG, metaData.getColumnLabel(2));
boolean containsSystem = false;
do {
if (resultSet.getString(1).equalsIgnoreCase(SYSTEM_SCHEMA_NAME)) containsSystem = true;
} while (resultSet.next());
assertTrue(format("should contain at least %s schema.", SYSTEM_SCHEMA_NAME), containsSystem);
assertTrue(containsSystem, format("should contain at least %s schema.", SYSTEM_SCHEMA_NAME));
}
}
}

@Test
public void smokeTest() throws Exception {
final String tableName = name.getMethodName();
public void smokeTest(TestInfo testInfo) throws Exception {
final String tableName = testInfo.getTestMethod().map(Method::getName).orElseThrow(IllegalStateException::new);
try (final Connection connection = DriverManager.getConnection(CONN_STRING)) {
assertFalse(connection.isClosed());
connection.setAutoCommit(true);
Expand Down Expand Up @@ -180,8 +175,8 @@ public void smokeTest() throws Exception {
}

@Test
public void arrayTest() throws Exception {
final String tableName = name.getMethodName();
public void arrayTest(TestInfo testInfo) throws Exception {
final String tableName = testInfo.getTestMethod().map(Method::getName).orElseThrow(IllegalStateException::new);
try (Connection conn = DriverManager.getConnection(CONN_STRING);
Statement stmt = conn.createStatement()) {
conn.setAutoCommit(false);
Expand Down Expand Up @@ -213,7 +208,8 @@ public void arrayTest() throws Exception {
assertEquals(i, Integer.parseInt(rs.getString(1)));
Array array = rs.getArray(2);
Object untypedArrayData = array.getArray();
assertTrue("Expected array data to be an int array, but was " + untypedArrayData.getClass(), untypedArrayData instanceof Object[]);
assertTrue(untypedArrayData instanceof Object[],
"Expected array data to be an int array, but was " + untypedArrayData.getClass());
Object[] arrayData = (Object[]) untypedArrayData;
int expectedArrayLength = i % 2 == 0 ? numEvenElements : numOddElements;
assertEquals(expectedArrayLength, arrayData.length);
Expand All @@ -227,8 +223,8 @@ public void arrayTest() throws Exception {
}

@Test
public void preparedStatementArrayTest() throws Exception {
final String tableName = name.getMethodName();
public void preparedStatementArrayTest(TestInfo testInfo) throws Exception {
final String tableName = testInfo.getTestMethod().map(Method::getName).orElseThrow(IllegalStateException::new);
try (Connection conn = DriverManager.getConnection(CONN_STRING);
Statement stmt = conn.createStatement()) {
conn.setAutoCommit(false);
Expand Down Expand Up @@ -261,7 +257,8 @@ public void preparedStatementArrayTest() throws Exception {
assertEquals(i, Integer.parseInt(rs.getString(1)));
Array array = rs.getArray(2);
Object untypedArrayData = array.getArray();
assertTrue("Expected array data to be an int array, but was " + untypedArrayData.getClass(), untypedArrayData instanceof Object[]);
assertTrue(untypedArrayData instanceof Object[],
"Expected array data to be an int array, but was " + untypedArrayData.getClass());
Object[] arrayData = (Object[]) untypedArrayData;
int expectedArrayLength = i % 2 == 0 ? numEvenElements : numOddElements;
assertEquals(expectedArrayLength, arrayData.length);
Expand All @@ -275,8 +272,8 @@ public void preparedStatementArrayTest() throws Exception {
}

@Test
public void preparedStatementVarcharArrayTest() throws Exception {
final String tableName = name.getMethodName();
public void preparedStatementVarcharArrayTest(TestInfo testInfo) throws Exception {
final String tableName = testInfo.getTestMethod().map(Method::getName).orElseThrow(IllegalStateException::new);
try (Connection conn = DriverManager.getConnection(CONN_STRING);
Statement stmt = conn.createStatement()) {
conn.setAutoCommit(false);
Expand Down Expand Up @@ -309,7 +306,8 @@ public void preparedStatementVarcharArrayTest() throws Exception {
assertEquals(i, Integer.parseInt(rs.getString(1)));
Array array = rs.getArray(2);
Object untypedArrayData = array.getArray();
assertTrue("Expected array data to be an int array, but was " + untypedArrayData.getClass(), untypedArrayData instanceof Object[]);
assertTrue(untypedArrayData instanceof Object[],
"Expected array data to be an int array, but was " + untypedArrayData.getClass());
Object[] arrayData = (Object[]) untypedArrayData;
int expectedArrayLength = i % 2 == 0 ? numEvenElements : numOddElements;
assertEquals(expectedArrayLength, arrayData.length);
Expand Down Expand Up @@ -381,15 +379,16 @@ public void testTimezoneLess() throws Exception {
ResultSet rs = stmt.executeQuery("select * from " + tableName);
assertTrue(rs.next());
LocalDateTime fromDB = rs.getTimestamp("i").toLocalDateTime();
assertTrue("Timestamps do not match. inserted:" + now.toString() + " returned:" + fromDB.toString(), fromDB.compareTo(now) == 0);
assertTrue(fromDB.compareTo(now) == 0,
"Timestamps do not match. inserted:" + now.toString() + " returned:" + fromDB.toString());
}
}
}

@Test
//Quick and dirty way start up a local Phoenix+PQS instance for testing against
public void startLocalPQS() throws Exception {
Assume.assumeNotNull(System.getProperty("start.unsecure.pqs"));
Assumptions.assumeTrue(System.getProperty("start.unsecure.pqs") != null);
System.out.println("CONN STRING:" + CONN_STRING);
System.out.println("Tests suspended!!!");
System.out.println("Kill maven run to stop server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
package org.apache.phoenix.end2end;

import static org.apache.hadoop.hbase.HConstants.HBASE_DIR;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -137,7 +137,7 @@ private static void updateDefaultRealm() throws Exception {
}

private void createUsers(int numUsers) throws Exception {
assertNotNull("KDC is null, was setup method called?", KDC);
assertNotNull(KDC,"KDC is null, was setup method called?");
NUM_CREATED_USERS = numUsers;
for (int i = 1; i <= numUsers; i++) {
String principal = "user" + i;
Expand Down Expand Up @@ -190,10 +190,10 @@ private static void ensureIsEmptyDirectory(File f) throws IOException {
if (f.isDirectory()) {
FileUtils.deleteDirectory(f);
} else {
assertTrue("Failed to delete keytab directory", f.delete());
assertTrue(f.delete(),"Failed to delete keytab directory");
}
}
assertTrue("Failed to create keytab directory", f.mkdirs());
assertTrue(f.mkdirs(),"Failed to create keytab directory");
}

/**
Expand Down
Loading