HBASE-23665: Split unit tests from TestTableName into a separate test-only class. (#1032)
Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
This commit is contained in:
parent
cb78b103a7
commit
fd05aabf02
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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.hadoop.hbase;
|
||||
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
|
||||
/**
|
||||
* Returns a {@code TableName} based on currently running test method name.
|
||||
*/
|
||||
public class TableNameTestRule extends TestWatcher {
|
||||
|
||||
private TableName tableName;
|
||||
|
||||
@Override
|
||||
protected void starting(Description description) {
|
||||
tableName = TableName.valueOf(description.getMethodName());
|
||||
}
|
||||
|
||||
public TableName getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* 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
|
||||
|
@ -20,99 +20,36 @@ package org.apache.hadoop.hbase;
|
|||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
|
||||
/**
|
||||
* Returns a {@code byte[]} containing the name of the currently running test method.
|
||||
* Tests for various kinds of TableNames.
|
||||
*/
|
||||
@Category({MiscTests.class, MediumTests.class})
|
||||
public class TestTableName extends TestWatcher {
|
||||
|
||||
@Category({MiscTests.class, SmallTests.class})
|
||||
public class TestTableName {
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestTableName.class);
|
||||
|
||||
private TableName tableName;
|
||||
|
||||
/**
|
||||
* Invoked when a test is about to start
|
||||
*/
|
||||
@Override
|
||||
protected void starting(Description description) {
|
||||
tableName = TableName.valueOf(description.getMethodName());
|
||||
}
|
||||
|
||||
public TableName getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
String[] emptyNames = {"", " "};
|
||||
String[] invalidNamespace = {":a", "%:a"};
|
||||
String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
|
||||
private static String[] emptyNames = {"", " "};
|
||||
private static String[] invalidNamespace = {":a", "%:a"};
|
||||
private static String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
|
||||
"with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02",
|
||||
"dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
|
||||
"trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
|
||||
String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal", "spaces not ok",
|
||||
"-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
|
||||
private static String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal",
|
||||
"spaces not ok", "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
|
||||
"new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidNamespace() {
|
||||
for (String tn : invalidNamespace) {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
fail("invalid namespace " + tn
|
||||
+ " should have failed with IllegalArgumentException for namespace");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEmptyNamespaceName() {
|
||||
for (String nn : emptyNames) {
|
||||
TableName.isLegalNamespaceName(Bytes.toBytes(nn));
|
||||
fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEmptyTableName() {
|
||||
for (String tn : emptyNames) {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLegalHTableNames() {
|
||||
for (String tn : legalTableNames) {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalHTableNames() {
|
||||
for (String tn : illegalTableNames) {
|
||||
try {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
fail("invalid tablename " + tn + " should have failed");
|
||||
} catch (Exception e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class Names {
|
||||
String ns;
|
||||
byte[] nsb;
|
||||
|
@ -147,7 +84,6 @@ public class TestTableName extends TestWatcher {
|
|||
if (!tn.equals(names.tn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -159,7 +95,7 @@ public class TestTableName extends TestWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
Names[] names = new Names[] {
|
||||
private static Names[] names = new Names[] {
|
||||
new Names("n1", "n1"),
|
||||
new Names("n2", "n2"),
|
||||
new Names("table1", "table1"),
|
||||
|
@ -172,9 +108,41 @@ public class TestTableName extends TestWatcher {
|
|||
new Names("n2", "table2")
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
@Test public void testInvalidNamespace() {
|
||||
for (String tn : invalidNamespace) {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testEmptyNamespaceName() {
|
||||
for (String nn : emptyNames) {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> TableName.isLegalNamespaceName(Bytes.toBytes(nn)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testEmptyTableName() {
|
||||
for (String tn : emptyNames) {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testLegalHTableNames() {
|
||||
for (String tn : legalTableNames) {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testIllegalHTableNames() {
|
||||
for (String tn : illegalTableNames) {
|
||||
assertThrows(Exception.class,
|
||||
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testValueOf() {
|
||||
Map<String, TableName> inCache = new HashMap<>();
|
||||
// fill cache
|
||||
for (Names name : names) {
|
||||
|
@ -188,7 +156,6 @@ public class TestTableName extends TestWatcher {
|
|||
assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(
|
||||
ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TableName validateNames(TableName expected, Names names) {
|
||||
|
@ -200,5 +167,4 @@ public class TestTableName extends TestWatcher {
|
|||
assertArrayEquals(expected.getNamespace(), names.nsb);
|
||||
return expected;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hadoop.fs.Path;
|
|||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.client.Durability;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
|
@ -68,7 +68,7 @@ public class TestScannerRetriableFailure {
|
|||
private static final String FAMILY_NAME_STR = "f";
|
||||
private static final byte[] FAMILY_NAME = Bytes.toBytes(FAMILY_NAME_STR);
|
||||
|
||||
@Rule public TestTableName TEST_TABLE = new TestTableName();
|
||||
@Rule public TableNameTestRule testTable = new TableNameTestRule();
|
||||
|
||||
public static class FaultyScannerObserver implements RegionCoprocessor, RegionObserver {
|
||||
private int faults = 0;
|
||||
|
@ -116,7 +116,7 @@ public class TestScannerRetriableFailure {
|
|||
|
||||
@Test
|
||||
public void testFaultyScanner() throws Exception {
|
||||
TableName tableName = TEST_TABLE.getTableName();
|
||||
TableName tableName = testTable.getTableName();
|
||||
Table table = UTIL.createTable(tableName, FAMILY_NAME);
|
||||
try {
|
||||
final int NUM_ROWS = 100;
|
||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
@ -34,8 +33,8 @@ import org.apache.hadoop.hbase.HConstants;
|
|||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.NamespaceDescriptor;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
||||
|
@ -105,7 +104,7 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
private static User TESTGROUP2_USER1;
|
||||
|
||||
@Rule
|
||||
public TestTableName TEST_TABLE = new TestTableName();
|
||||
public TableNameTestRule testTable = new TableNameTestRule();
|
||||
private String namespace = "testNamespace";
|
||||
private String tname = namespace + ":testtable1";
|
||||
private TableName tableName = TableName.valueOf(tname);
|
||||
|
@ -187,7 +186,7 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
|
||||
desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
|
||||
try (Connection connection =
|
||||
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), testUser)) {
|
||||
|
@ -198,11 +197,11 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
return null;
|
||||
}
|
||||
}, testUser);
|
||||
TEST_UTIL.waitTableAvailable(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.waitTableAvailable(testTable.getTableName());
|
||||
// Verify that owner permissions have been granted to the test user on the
|
||||
// table just created
|
||||
List<UserPermission> perms = PermissionStorage
|
||||
.getTablePermissions(conf, TEST_TABLE.getTableName()).get(testUser.getShortName());
|
||||
.getTablePermissions(conf, testTable.getTableName()).get(testUser.getShortName());
|
||||
assertNotNull(perms);
|
||||
assertFalse(perms.isEmpty());
|
||||
// Should be RWXCA
|
||||
|
@ -220,7 +219,7 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
AccessTestAction createAction = new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
|
||||
desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
|
||||
try (Connection connection =
|
||||
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
|
||||
|
@ -261,13 +260,13 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
User nsCreate = User.createUserForTesting(conf, "nsCreate", new String[0]);
|
||||
User nsAdmin = User.createUserForTesting(conf, "nsAdmin", new String[0]);
|
||||
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsRead.getShortName(),
|
||||
TEST_TABLE.getTableName().getNamespaceAsString(), Action.READ);
|
||||
testTable.getTableName().getNamespaceAsString(), Action.READ);
|
||||
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsWrite.getShortName(),
|
||||
TEST_TABLE.getTableName().getNamespaceAsString(), Action.WRITE);
|
||||
testTable.getTableName().getNamespaceAsString(), Action.WRITE);
|
||||
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsCreate.getShortName(),
|
||||
TEST_TABLE.getTableName().getNamespaceAsString(), Action.CREATE);
|
||||
testTable.getTableName().getNamespaceAsString(), Action.CREATE);
|
||||
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsAdmin.getShortName(),
|
||||
TEST_TABLE.getTableName().getNamespaceAsString(), Action.ADMIN);
|
||||
testTable.getTableName().getNamespaceAsString(), Action.ADMIN);
|
||||
|
||||
// Table users
|
||||
User tableRead = User.createUserForTesting(conf, "tableRead", new String[0]);
|
||||
|
@ -275,13 +274,13 @@ public class TestAccessController2 extends SecureTestUtil {
|
|||
User tableCreate = User.createUserForTesting(conf, "tableCreate", new String[0]);
|
||||
User tableAdmin = User.createUserForTesting(conf, "tableAdmin", new String[0]);
|
||||
SecureTestUtil.grantOnTable(TEST_UTIL, tableRead.getShortName(),
|
||||
TEST_TABLE.getTableName(), null, null, Action.READ);
|
||||
testTable.getTableName(), null, null, Action.READ);
|
||||
SecureTestUtil.grantOnTable(TEST_UTIL, tableWrite.getShortName(),
|
||||
TEST_TABLE.getTableName(), null, null, Action.WRITE);
|
||||
testTable.getTableName(), null, null, Action.WRITE);
|
||||
SecureTestUtil.grantOnTable(TEST_UTIL, tableCreate.getShortName(),
|
||||
TEST_TABLE.getTableName(), null, null, Action.CREATE);
|
||||
testTable.getTableName(), null, null, Action.CREATE);
|
||||
SecureTestUtil.grantOnTable(TEST_UTIL, tableAdmin.getShortName(),
|
||||
TEST_TABLE.getTableName(), null, null, Action.ADMIN);
|
||||
testTable.getTableName(), null, null, Action.ADMIN);
|
||||
|
||||
grantGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.WRITE);
|
||||
try {
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.security.access;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.HashMap;
|
||||
|
@ -31,8 +30,8 @@ import org.apache.hadoop.hbase.HBaseClassTestRule;
|
|||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
||||
|
@ -71,7 +70,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLWithMultipleVersions.class);
|
||||
|
||||
@Rule
|
||||
public TestTableName TEST_TABLE = new TestTableName();
|
||||
public TableNameTestRule testTable = new TableNameTestRule();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
|
||||
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
|
||||
|
@ -133,7 +132,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
|
||||
hcd.setMaxVersions(4);
|
||||
htd.setOwner(USER_OWNER);
|
||||
|
@ -148,7 +147,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
|
||||
}
|
||||
}
|
||||
TEST_UTIL.waitTableEnabled(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.waitTableEnabled(testTable.getTableName());
|
||||
LOG.info("Sleeping a second because of HBASE-12581");
|
||||
Threads.sleep(1000);
|
||||
}
|
||||
|
@ -163,7 +162,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
// with ro ACL
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
|
||||
|
@ -195,7 +194,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
Get get = new Get(TEST_ROW);
|
||||
get.readVersions(10);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +206,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
Get get = new Get(TEST_ROW);
|
||||
get.readVersions(10);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +222,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
|
||||
p.setACL(writePerms);
|
||||
|
@ -269,7 +268,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
// with rw ACL for "user1"
|
||||
Put p = new Put(TEST_ROW1);
|
||||
p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
|
||||
|
@ -294,7 +293,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
// with rw ACL for "user1", "user2" and "@group"
|
||||
Put p = new Put(TEST_ROW1);
|
||||
p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
|
||||
|
@ -322,7 +321,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW1);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q1);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q2);
|
||||
|
@ -345,7 +344,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW2);
|
||||
d.addFamily(TEST_FAMILY1);
|
||||
t.delete(d);
|
||||
|
@ -362,7 +361,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(row);
|
||||
d.addColumns(TEST_FAMILY1, q1);
|
||||
d.addColumns(TEST_FAMILY1, q2);
|
||||
|
@ -386,7 +385,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
// Store a read write ACL without a timestamp, server will use current time
|
||||
Put p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2, ONE);
|
||||
Map<String, Permission> readAndWritePerms =
|
||||
|
@ -416,7 +415,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1);
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +427,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2);
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +461,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Delete delete = new Delete(TEST_ROW).addFamily(fam);
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.delete(delete);
|
||||
}
|
||||
}
|
||||
|
@ -478,7 +477,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
// This version (TS = 123) with rw ACL for USER_OTHER and USER_OTHER2
|
||||
Put p = new Put(TEST_ROW);
|
||||
p.addColumn(TEST_FAMILY1, TEST_Q1, 123L, ZERO);
|
||||
|
@ -517,7 +516,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW, 124L);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q1);
|
||||
t.delete(d);
|
||||
|
@ -532,7 +531,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q2, 124L);
|
||||
t.delete(d);
|
||||
|
@ -557,7 +556,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Map<String, Permission> permsU1andOwner =
|
||||
prepareCellPermissions(
|
||||
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
|
||||
|
@ -611,7 +610,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW1);
|
||||
d.addColumn(TEST_FAMILY1, TEST_Q1, 123);
|
||||
d.addColumn(TEST_FAMILY1, TEST_Q2);
|
||||
|
@ -633,7 +632,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(row, 127);
|
||||
d.addColumns(TEST_FAMILY1, q1);
|
||||
d.addColumns(TEST_FAMILY1, q2);
|
||||
|
@ -663,7 +662,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Map<String, Permission> permsU1andOwner =
|
||||
prepareCellPermissions(
|
||||
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
|
||||
|
@ -700,7 +699,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Increment inc = new Increment(TEST_ROW1);
|
||||
inc.setTimeRange(0, 123);
|
||||
inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
|
||||
|
@ -722,7 +721,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Increment inc = new Increment(row);
|
||||
inc.setTimeRange(0, 127);
|
||||
inc.addColumn(TEST_FAMILY1, q1, 2L);
|
||||
|
@ -751,7 +750,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Map<String, Permission> permsU1andOwner =
|
||||
prepareCellPermissions(
|
||||
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
|
||||
|
@ -794,7 +793,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p = new Put(TEST_ROW1);
|
||||
p.addColumn(TEST_FAMILY1, TEST_Q1, 125, ZERO);
|
||||
p.addColumn(TEST_FAMILY1, TEST_Q2, ZERO);
|
||||
|
@ -818,7 +817,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p = new Put(row);
|
||||
// column Q1 covers version at 123 fr which user2 do not have permission
|
||||
p.addColumn(TEST_FAMILY1, q1, 124, value);
|
||||
|
@ -847,7 +846,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Map<String, Permission> permsU1andOwner =
|
||||
prepareCellPermissions(
|
||||
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
|
||||
|
@ -900,7 +899,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(TEST_ROW1);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q1, 120);
|
||||
t.checkAndMutate(TEST_ROW1, TEST_FAMILY1).qualifier(TEST_Q1)
|
||||
|
@ -937,7 +936,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(row);
|
||||
d.addColumn(TEST_FAMILY1, q1, 120);
|
||||
t.checkAndMutate(row, TEST_FAMILY1).qualifier(q1).ifEquals(value).thenDelete(d);
|
||||
|
@ -954,7 +953,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf)) {
|
||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
try (Table t = connection.getTable(testTable.getTableName())) {
|
||||
Delete d = new Delete(row);
|
||||
d.addColumns(TEST_FAMILY1, TEST_Q1);
|
||||
t.checkAndMutate(row, TEST_FAMILY1).qualifier(TEST_Q1).ifEquals(value).thenDelete(d);
|
||||
|
@ -971,11 +970,11 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
|||
public void tearDown() throws Exception {
|
||||
// Clean the _acl_ table
|
||||
try {
|
||||
TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.deleteTable(testTable.getTableName());
|
||||
} catch (TableNotFoundException ex) {
|
||||
// Test deleted the table, no problem
|
||||
LOG.info("Test deleted table " + TEST_TABLE.getTableName());
|
||||
LOG.info("Test deleted table " + testTable.getTableName());
|
||||
}
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.hadoop.hbase.security.access;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -31,8 +30,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
|
|||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
||||
|
@ -62,7 +61,6 @@ import org.junit.Test;
|
|||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
||||
|
||||
@Category({SecurityTests.class, LargeTests.class})
|
||||
|
@ -75,7 +73,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLs.class);
|
||||
|
||||
@Rule
|
||||
public TestTableName TEST_TABLE = new TestTableName();
|
||||
public TableNameTestRule testTable = new TableNameTestRule();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
|
||||
private static final byte[] TEST_ROW = Bytes.toBytes("cellpermtest");
|
||||
|
@ -137,13 +135,13 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public void setUp() throws Exception {
|
||||
// Create the test table (owner added to the _acl_ table)
|
||||
Admin admin = TEST_UTIL.getAdmin();
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
|
||||
hcd.setMaxVersions(4);
|
||||
htd.setOwner(USER_OWNER);
|
||||
htd.addFamily(hcd);
|
||||
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
|
||||
TEST_UTIL.waitTableEnabled(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.waitTableEnabled(testTable.getTableName());
|
||||
LOG.info("Sleeping a second because of HBASE-12581");
|
||||
Threads.sleep(1000);
|
||||
}
|
||||
|
@ -155,7 +153,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
// with ro ACL
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
|
||||
|
@ -182,7 +180,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +191,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +202,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +213,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q4);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(get).listCells();
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +243,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
|
||||
scan.addFamily(TEST_FAMILY);
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
ResultScanner scanner = t.getScanner(scan);
|
||||
Result result = null;
|
||||
|
@ -284,7 +282,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.increment(i);
|
||||
}
|
||||
return null;
|
||||
|
@ -296,7 +294,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.increment(i);
|
||||
}
|
||||
return null;
|
||||
|
@ -310,7 +308,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
// Tag this increment with an ACL that denies write permissions to USER_OTHER and GROUP
|
||||
i.setACL(prepareCellPermissions(usersAndGroups, Action.READ));
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.increment(i);
|
||||
}
|
||||
return null;
|
||||
|
@ -322,7 +320,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.increment(i);
|
||||
}
|
||||
return null;
|
||||
|
@ -347,7 +345,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Delete delete = new Delete(TEST_ROW).addFamily(TEST_FAMILY);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.delete(delete);
|
||||
}
|
||||
return null;
|
||||
|
@ -359,7 +357,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
Delete delete = new Delete(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
t.delete(delete);
|
||||
}
|
||||
return null;
|
||||
|
@ -378,10 +376,10 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
@Test
|
||||
public void testCoveringCheck() throws Exception {
|
||||
// Grant read access to USER_OTHER
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY,
|
||||
null, Action.READ);
|
||||
// Grant read access to GROUP
|
||||
grantOnTable(TEST_UTIL, AuthUtil.toGroupEntry(GROUP), TEST_TABLE.getTableName(), TEST_FAMILY,
|
||||
grantOnTable(TEST_UTIL, AuthUtil.toGroupEntry(GROUP), testTable.getTableName(), TEST_FAMILY,
|
||||
null, Action.READ);
|
||||
|
||||
// A write by USER_OTHER should be denied.
|
||||
|
@ -396,7 +394,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
|
||||
t.put(p);
|
||||
|
@ -421,7 +419,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, value);
|
||||
t.put(p);
|
||||
|
@ -436,7 +434,7 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try (Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
return t.get(new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1));
|
||||
}
|
||||
}
|
||||
|
@ -455,11 +453,11 @@ public class TestCellACLs extends SecureTestUtil {
|
|||
public void tearDown() throws Exception {
|
||||
// Clean the _acl_ table
|
||||
try {
|
||||
TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.deleteTable(testTable.getTableName());
|
||||
} catch (TableNotFoundException ex) {
|
||||
// Test deleted the table, no problem
|
||||
LOG.info("Test deleted table " + TEST_TABLE.getTableName());
|
||||
LOG.info("Test deleted table " + testTable.getTableName());
|
||||
}
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.security.access;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.Coprocessor;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
|
@ -28,8 +27,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
|
|||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.client.ConnectionFactory;
|
||||
|
@ -65,7 +64,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(TestScanEarlyTermination.class);
|
||||
|
||||
@Rule
|
||||
public TestTableName TEST_TABLE = new TestTableName();
|
||||
public TableNameTestRule testTable = new TableNameTestRule();
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
|
||||
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
|
||||
|
@ -116,7 +115,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Admin admin = TEST_UTIL.getAdmin();
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
htd.setOwner(USER_OWNER);
|
||||
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
|
||||
hcd.setMaxVersions(10);
|
||||
|
@ -130,25 +129,25 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
htd.setConfiguration(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, "true");
|
||||
|
||||
admin.createTable(htd);
|
||||
TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
// Clean the _acl_ table
|
||||
try {
|
||||
TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.deleteTable(testTable.getTableName());
|
||||
} catch (TableNotFoundException ex) {
|
||||
// Test deleted the table, no problem
|
||||
LOG.info("Test deleted table " + TEST_TABLE.getTableName());
|
||||
LOG.info("Test deleted table " + testTable.getTableName());
|
||||
}
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
|
||||
assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEarlyScanTermination() throws Exception {
|
||||
// Grant USER_OTHER access to TEST_FAMILY1 only
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY1,
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY1,
|
||||
null, Action.READ);
|
||||
|
||||
// Set up test data
|
||||
|
@ -158,7 +157,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
// force a new RS connection
|
||||
conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
Put put = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
|
||||
t.put(put);
|
||||
|
@ -185,7 +184,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
// force a new RS connection
|
||||
conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
Scan scan = new Scan().addFamily(TEST_FAMILY1);
|
||||
Result result = t.getScanner(scan).next();
|
||||
|
@ -211,7 +210,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
// force a new RS connection
|
||||
conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
Scan scan = new Scan();
|
||||
Result result = t.getScanner(scan).next();
|
||||
|
@ -235,7 +234,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
// force a new RS connection
|
||||
conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
Scan scan = new Scan().addFamily(TEST_FAMILY2);
|
||||
Result result = t.getScanner(scan).next();
|
||||
|
@ -251,7 +250,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
}, USER_OTHER);
|
||||
|
||||
// Now grant USER_OTHER access to TEST_FAMILY2:TEST_Q2
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY2,
|
||||
grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY2,
|
||||
TEST_Q2, Action.READ);
|
||||
|
||||
// A scan of FAMILY1 and FAMILY2 will produce combined results. In FAMILY2
|
||||
|
@ -263,7 +262,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
|
|||
// force a new RS connection
|
||||
conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
Scan scan = new Scan();
|
||||
Result result = t.getScanner(scan).next();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.hadoop.hbase.security.access;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
|
@ -33,8 +32,8 @@ import org.apache.hadoop.hbase.HTableDescriptor;
|
|||
import org.apache.hadoop.hbase.NamespaceDescriptor;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.Append;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
|
@ -78,7 +77,6 @@ import org.junit.Test;
|
|||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
||||
|
||||
@Category({SecurityTests.class, LargeTests.class})
|
||||
|
@ -105,7 +103,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
private static RegionServerCoprocessorEnvironment RSCP_ENV;
|
||||
private RegionCoprocessorEnvironment RCP_ENV;
|
||||
|
||||
@Rule public TestTableName TEST_TABLE = new TestTableName();
|
||||
@Rule public TableNameTestRule testTable = new TableNameTestRule();
|
||||
|
||||
// default users
|
||||
|
||||
|
@ -177,15 +175,15 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
public void setUp() throws Exception {
|
||||
// Create the test table (owner added to the _acl_ table)
|
||||
Admin admin = TEST_UTIL.getAdmin();
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
|
||||
hcd.setMaxVersions(100);
|
||||
htd.addFamily(hcd);
|
||||
htd.setOwner(USER_OWNER);
|
||||
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
|
||||
TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName());
|
||||
TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
|
||||
|
||||
HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TEST_TABLE.getTableName()).get(0);
|
||||
HRegion region = TEST_UTIL.getHBaseCluster().getRegions(testTable.getTableName()).get(0);
|
||||
RegionCoprocessorHost rcpHost = region.getCoprocessorHost();
|
||||
RCP_ENV = rcpHost.createEnvironment(ACCESS_CONTROLLER,
|
||||
Coprocessor.PRIORITY_HIGHEST, 1, TEST_UTIL.getConfiguration());
|
||||
|
@ -199,44 +197,44 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
Permission.Action.WRITE);
|
||||
|
||||
grantOnTable(TEST_UTIL, USER_RW.getShortName(),
|
||||
TEST_TABLE.getTableName(), TEST_FAMILY, null,
|
||||
testTable.getTableName(), TEST_FAMILY, null,
|
||||
Permission.Action.READ,
|
||||
Permission.Action.WRITE);
|
||||
|
||||
// USER_CREATE is USER_RW plus CREATE permissions
|
||||
grantOnTable(TEST_UTIL, USER_CREATE.getShortName(),
|
||||
TEST_TABLE.getTableName(), null, null,
|
||||
testTable.getTableName(), null, null,
|
||||
Permission.Action.CREATE,
|
||||
Permission.Action.READ,
|
||||
Permission.Action.WRITE);
|
||||
|
||||
grantOnTable(TEST_UTIL, USER_RO.getShortName(),
|
||||
TEST_TABLE.getTableName(), TEST_FAMILY, null,
|
||||
testTable.getTableName(), TEST_FAMILY, null,
|
||||
Permission.Action.READ);
|
||||
|
||||
grantOnTable(TEST_UTIL, USER_QUAL.getShortName(),
|
||||
TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
testTable.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
Permission.Action.READ,
|
||||
Permission.Action.WRITE);
|
||||
|
||||
assertEquals(5, PermissionStorage
|
||||
.getTablePermissions(TEST_UTIL.getConfiguration(), TEST_TABLE.getTableName()).size());
|
||||
.getTablePermissions(TEST_UTIL.getConfiguration(), testTable.getTableName()).size());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
// Clean the _acl_ table
|
||||
try {
|
||||
deleteTable(TEST_UTIL, TEST_TABLE.getTableName());
|
||||
deleteTable(TEST_UTIL, testTable.getTableName());
|
||||
} catch (TableNotFoundException ex) {
|
||||
// Test deleted the table, no problem
|
||||
LOG.info("Test deleted table " + TEST_TABLE.getTableName());
|
||||
LOG.info("Test deleted table " + testTable.getTableName());
|
||||
}
|
||||
// Verify all table/namespace permissions are erased
|
||||
assertEquals(0, PermissionStorage
|
||||
.getTablePermissions(TEST_UTIL.getConfiguration(), TEST_TABLE.getTableName()).size());
|
||||
.getTablePermissions(TEST_UTIL.getConfiguration(), testTable.getTableName()).size());
|
||||
assertEquals(0, PermissionStorage.getNamespacePermissions(TEST_UTIL.getConfiguration(),
|
||||
TEST_TABLE.getTableName().getNamespaceAsString()).size());
|
||||
testTable.getTableName().getNamespaceAsString()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -278,7 +276,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkTableAdmin = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
|
||||
Permission.Action.ADMIN);
|
||||
return null;
|
||||
}
|
||||
|
@ -290,7 +288,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkTableCreate = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
|
||||
Permission.Action.CREATE);
|
||||
return null;
|
||||
}
|
||||
|
@ -302,7 +300,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkTableRead = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
|
||||
Permission.Action.READ);
|
||||
return null;
|
||||
}
|
||||
|
@ -314,7 +312,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkTableReadWrite = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
|
||||
Permission.Action.READ, Permission.Action.WRITE);
|
||||
return null;
|
||||
}
|
||||
|
@ -326,7 +324,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkColumnRead = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
|
||||
Permission.Action.READ);
|
||||
return null;
|
||||
}
|
||||
|
@ -338,7 +336,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkColumnReadWrite = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
|
||||
Permission.Action.READ, Permission.Action.WRITE);
|
||||
return null;
|
||||
}
|
||||
|
@ -350,7 +348,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkQualifierRead = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
Permission.Action.READ);
|
||||
return null;
|
||||
}
|
||||
|
@ -362,7 +360,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkQualifierReadWrite = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, TEST_Q1,
|
||||
Permission.Action.READ, Permission.Action.WRITE);
|
||||
return null;
|
||||
}
|
||||
|
@ -376,9 +374,9 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL,
|
||||
new Permission[] {
|
||||
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY)
|
||||
Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
|
||||
.withQualifier(TEST_Q1).withActions(Action.READ).build(),
|
||||
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY)
|
||||
Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
|
||||
.withQualifier(TEST_Q2).withActions(Action.READ).build() });
|
||||
return null;
|
||||
}
|
||||
|
@ -392,10 +390,10 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL,
|
||||
new Permission[] {
|
||||
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY)
|
||||
Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
|
||||
.withQualifier(TEST_Q1)
|
||||
.withActions(Permission.Action.READ, Permission.Action.WRITE).build(),
|
||||
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY)
|
||||
Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
|
||||
.withQualifier(TEST_Q2)
|
||||
.withActions(Permission.Action.READ, Permission.Action.WRITE).build() });
|
||||
return null;
|
||||
|
@ -420,7 +418,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
AccessTestAction checkTableRead = new AccessTestAction() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
|
||||
checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
|
||||
Permission.Action.READ);
|
||||
return null;
|
||||
}
|
||||
|
@ -434,7 +432,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Void run() throws Exception {
|
||||
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
|
||||
Table t = conn.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = conn.getTable(testTable.getTableName())) {
|
||||
t.get(new Get(TEST_ROW).addFamily(TEST_FAMILY));
|
||||
}
|
||||
return null;
|
||||
|
@ -445,7 +443,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
|
||||
// Grant read perms to the test user
|
||||
|
||||
grantOnTable(TEST_UTIL, tblUser.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
|
||||
grantOnTable(TEST_UTIL, tblUser.getShortName(), testTable.getTableName(), TEST_FAMILY,
|
||||
null, Permission.Action.READ);
|
||||
|
||||
// Now both the permission check and actual op will succeed
|
||||
|
@ -455,7 +453,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
|
||||
// Revoke read perms from the test user
|
||||
|
||||
revokeFromTable(TEST_UTIL, tblUser.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
|
||||
revokeFromTable(TEST_UTIL, tblUser.getShortName(), testTable.getTableName(), TEST_FAMILY,
|
||||
null, Permission.Action.READ);
|
||||
|
||||
// Now the permission check will indicate revocation but the actual op will still succeed
|
||||
|
@ -472,7 +470,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
|
||||
ACCESS_CONTROLLER.preCreateTable(ObserverContextImpl.createAndPrepare(CP_ENV), htd,
|
||||
null);
|
||||
|
@ -484,11 +482,11 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
|
||||
htd.addFamily(new HColumnDescriptor(TEST_FAMILY2));
|
||||
ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName(),
|
||||
testTable.getTableName(),
|
||||
null, // not needed by AccessController
|
||||
htd);
|
||||
return null;
|
||||
|
@ -500,7 +498,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preDeleteTable(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName());
|
||||
testTable.getTableName());
|
||||
return null;
|
||||
}
|
||||
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
|
||||
|
@ -510,7 +508,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preTruncateTable(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName());
|
||||
testTable.getTableName());
|
||||
return null;
|
||||
}
|
||||
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
|
||||
|
@ -520,7 +518,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preEnableTable(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName());
|
||||
testTable.getTableName());
|
||||
return null;
|
||||
}
|
||||
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
|
||||
|
@ -530,7 +528,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preDisableTable(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName());
|
||||
testTable.getTableName());
|
||||
return null;
|
||||
}
|
||||
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
|
||||
|
@ -539,7 +537,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
|
||||
HRegionInfo region = new HRegionInfo(testTable.getTableName());
|
||||
ServerName srcServer = ServerName.valueOf("1.1.1.1", 1, 0);
|
||||
ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0);
|
||||
ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV), region,
|
||||
|
@ -552,7 +550,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
|
||||
HRegionInfo region = new HRegionInfo(testTable.getTableName());
|
||||
ACCESS_CONTROLLER.preAssign(ObserverContextImpl.createAndPrepare(CP_ENV), region);
|
||||
return null;
|
||||
}
|
||||
|
@ -562,7 +560,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
verifyAllowed(new AccessTestAction() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
|
||||
HRegionInfo region = new HRegionInfo(testTable.getTableName());
|
||||
ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), region,
|
||||
true);
|
||||
return null;
|
||||
|
@ -593,7 +591,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
SnapshotDescription snapshot = new SnapshotDescription("foo");
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
ACCESS_CONTROLLER.preSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
snapshot, htd);
|
||||
return null;
|
||||
|
@ -616,7 +614,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
SnapshotDescription snapshot = new SnapshotDescription("foo");
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
snapshot, htd);
|
||||
return null;
|
||||
|
@ -628,7 +626,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
SnapshotDescription snapshot = new SnapshotDescription("foo");
|
||||
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
|
||||
HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
|
||||
ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
snapshot, htd);
|
||||
return null;
|
||||
|
@ -651,7 +649,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
List<TableName> tableNamesList = Lists.newArrayList();
|
||||
tableNamesList.add(TEST_TABLE.getTableName());
|
||||
tableNamesList.add(testTable.getTableName());
|
||||
List<TableDescriptor> descriptors = Lists.newArrayList();
|
||||
ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
tableNamesList, descriptors, ".+");
|
||||
|
@ -730,7 +728,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preSplitRegion(
|
||||
ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName(),
|
||||
testTable.getTableName(),
|
||||
Bytes.toBytes("ss"));
|
||||
return null;
|
||||
}
|
||||
|
@ -751,7 +749,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
ACCESS_CONTROLLER.preSetTableQuota(ObserverContextImpl.createAndPrepare(CP_ENV),
|
||||
TEST_TABLE.getTableName(), null);
|
||||
testTable.getTableName(), null);
|
||||
return null;
|
||||
}
|
||||
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
|
||||
|
@ -939,7 +937,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
@Override
|
||||
public Object run() throws Exception {
|
||||
try(Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||
Table t = connection.getTable(testTable.getTableName())) {
|
||||
Put p;
|
||||
// with ro ACL
|
||||
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
|
||||
|
@ -971,7 +969,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
|
|||
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
|
||||
scan.addFamily(TEST_FAMILY);
|
||||
Connection connection = ConnectionFactory.createConnection(conf);
|
||||
Table t = connection.getTable(TEST_TABLE.getTableName());
|
||||
Table t = connection.getTable(testTable.getTableName());
|
||||
try {
|
||||
ResultScanner scanner = t.getScanner(scan);
|
||||
Result result = null;
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.client.SnapshotDescription;
|
||||
import org.apache.hadoop.hbase.client.TableDescriptor;
|
||||
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
|
||||
|
@ -53,7 +53,7 @@ public class TestSnapshotClientRetries {
|
|||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotClientRetries.class);
|
||||
|
||||
@Rule public TestTableName TEST_TABLE = new TestTableName();
|
||||
@Rule public TableNameTestRule testTable = new TableNameTestRule();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -70,15 +70,15 @@ public class TestSnapshotClientRetries {
|
|||
@Test(expected=SnapshotExistsException.class)
|
||||
public void testSnapshotAlreadyExist() throws Exception {
|
||||
final String snapshotName = "testSnapshotAlreadyExist";
|
||||
TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f");
|
||||
TEST_UTIL.getAdmin().snapshot(snapshotName, TEST_TABLE.getTableName());
|
||||
snapshotAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName());
|
||||
TEST_UTIL.createTable(testTable.getTableName(), "f");
|
||||
TEST_UTIL.getAdmin().snapshot(snapshotName, testTable.getTableName());
|
||||
snapshotAndAssertOneRetry(snapshotName, testTable.getTableName());
|
||||
}
|
||||
|
||||
@Test(expected=SnapshotDoesNotExistException.class)
|
||||
public void testCloneNonExistentSnapshot() throws Exception {
|
||||
final String snapshotName = "testCloneNonExistentSnapshot";
|
||||
cloneAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName());
|
||||
cloneAndAssertOneRetry(snapshotName, testTable.getTableName());
|
||||
}
|
||||
|
||||
public static class MasterSyncObserver implements MasterCoprocessor, MasterObserver {
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.hadoop.fs.Path;
|
|||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.TestTableName;
|
||||
import org.apache.hadoop.hbase.TableNameTestRule;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.client.Table;
|
||||
import org.apache.hadoop.hbase.master.HMaster;
|
||||
|
@ -75,7 +75,7 @@ public class TestSnapshotWhenChoreCleaning {
|
|||
private static Table TABLE;
|
||||
|
||||
@Rule
|
||||
public TestTableName TEST_TABLE = new TestTableName();
|
||||
public TableNameTestRule testTable = new TableNameTestRule();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue