001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.security.access; 019 020import static org.junit.jupiter.api.Assertions.fail; 021 022import java.util.ArrayList; 023import java.util.List; 024import org.apache.hadoop.hbase.DoNotRetryIOException; 025import org.apache.hadoop.hbase.HBaseTestingUtil; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.client.Admin; 028import org.apache.hadoop.hbase.testclassification.SecurityTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.junit.jupiter.api.AfterAll; 031import org.junit.jupiter.api.BeforeAll; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035@Tag(SecurityTests.TAG) 036@Tag(SmallTests.TAG) 037public class TestUnloadAccessController extends SecureTestUtil { 038 039 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 040 private static TableName TEST_TABLE = TableName.valueOf("TestUnloadAccessController"); 041 private static Permission permission = 042 Permission.newBuilder(TEST_TABLE).withActions(Permission.Action.READ).build(); 043 private static Admin admin; 044 045 @BeforeAll 046 public static void setupBeforeClass() throws Exception { 047 TEST_UTIL.startMiniCluster(); 048 TEST_UTIL.waitUntilAllSystemRegionsAssigned(); 049 admin = TEST_UTIL.getAdmin(); 050 } 051 052 @AfterAll 053 public static void tearDownAfterClass() throws Exception { 054 TEST_UTIL.shutdownMiniCluster(); 055 } 056 057 @Test 058 public void testGrant() { 059 try { 060 admin.grant(new UserPermission("user", permission), false); 061 fail("Expected UnsupportedOperationException but not found"); 062 } catch (Throwable e) { 063 checkException(e); 064 } 065 } 066 067 @Test 068 public void testRevoke() { 069 try { 070 admin.revoke(new UserPermission("user", permission)); 071 fail("Expected UnsupportedOperationException but not found"); 072 } catch (Throwable e) { 073 e.printStackTrace(); 074 checkException(e); 075 } 076 } 077 078 @Test 079 public void testGetUserPermissions() { 080 try { 081 admin.getUserPermissions(GetUserPermissionsRequest.newBuilder().build()); 082 fail("Expected UnsupportedOperationException but not found"); 083 } catch (Throwable e) { 084 checkException(e); 085 } 086 } 087 088 @Test 089 public void testHasUserPermission() { 090 try { 091 List<Permission> permissionList = new ArrayList<>(); 092 permissionList.add(permission); 093 admin.hasUserPermissions(permissionList); 094 fail("Expected UnsupportedOperationException but not found"); 095 } catch (Throwable e) { 096 checkException(e); 097 } 098 } 099 100 private void checkException(Throwable e) { 101 if ( 102 e instanceof DoNotRetryIOException 103 && e.getMessage().contains(UnsupportedOperationException.class.getName()) 104 ) { 105 return; 106 } 107 fail("Expected UnsupportedOperationException but found " + e.getMessage()); 108 } 109}