|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.polaris.core.entity; |
| 20 | + |
| 21 | +import java.util.stream.Stream; |
| 22 | +import org.assertj.core.api.Assertions; |
| 23 | +import org.junit.jupiter.params.ParameterizedTest; |
| 24 | +import org.junit.jupiter.params.provider.Arguments; |
| 25 | +import org.junit.jupiter.params.provider.MethodSource; |
| 26 | + |
| 27 | +public class PolarisPrivilegeTest { |
| 28 | + |
| 29 | + static Stream<Arguments> polarisPrivileges() { |
| 30 | + return Stream.of( |
| 31 | + Arguments.of(-1, null), |
| 32 | + Arguments.of(1, PolarisPrivilege.SERVICE_MANAGE_ACCESS), |
| 33 | + Arguments.of(2, PolarisPrivilege.CATALOG_MANAGE_ACCESS), |
| 34 | + Arguments.of(3, PolarisPrivilege.CATALOG_ROLE_USAGE), |
| 35 | + Arguments.of(4, PolarisPrivilege.PRINCIPAL_ROLE_USAGE), |
| 36 | + Arguments.of(5, PolarisPrivilege.NAMESPACE_CREATE), |
| 37 | + Arguments.of(6, PolarisPrivilege.TABLE_CREATE), |
| 38 | + Arguments.of(7, PolarisPrivilege.VIEW_CREATE), |
| 39 | + Arguments.of(8, PolarisPrivilege.NAMESPACE_DROP), |
| 40 | + Arguments.of(9, PolarisPrivilege.TABLE_DROP), |
| 41 | + Arguments.of(10, PolarisPrivilege.VIEW_DROP), |
| 42 | + Arguments.of(11, PolarisPrivilege.NAMESPACE_LIST), |
| 43 | + Arguments.of(12, PolarisPrivilege.TABLE_LIST), |
| 44 | + Arguments.of(13, PolarisPrivilege.VIEW_LIST), |
| 45 | + Arguments.of(14, PolarisPrivilege.NAMESPACE_READ_PROPERTIES), |
| 46 | + Arguments.of(15, PolarisPrivilege.TABLE_READ_PROPERTIES), |
| 47 | + Arguments.of(16, PolarisPrivilege.VIEW_READ_PROPERTIES), |
| 48 | + Arguments.of(17, PolarisPrivilege.NAMESPACE_WRITE_PROPERTIES), |
| 49 | + Arguments.of(18, PolarisPrivilege.TABLE_WRITE_PROPERTIES), |
| 50 | + Arguments.of(19, PolarisPrivilege.VIEW_WRITE_PROPERTIES), |
| 51 | + Arguments.of(20, PolarisPrivilege.TABLE_READ_DATA), |
| 52 | + Arguments.of(21, PolarisPrivilege.TABLE_WRITE_DATA), |
| 53 | + Arguments.of(22, PolarisPrivilege.NAMESPACE_FULL_METADATA), |
| 54 | + Arguments.of(23, PolarisPrivilege.TABLE_FULL_METADATA), |
| 55 | + Arguments.of(24, PolarisPrivilege.VIEW_FULL_METADATA), |
| 56 | + Arguments.of(25, PolarisPrivilege.CATALOG_CREATE), |
| 57 | + Arguments.of(26, PolarisPrivilege.CATALOG_DROP), |
| 58 | + Arguments.of(27, PolarisPrivilege.CATALOG_LIST), |
| 59 | + Arguments.of(28, PolarisPrivilege.CATALOG_READ_PROPERTIES), |
| 60 | + Arguments.of(29, PolarisPrivilege.CATALOG_WRITE_PROPERTIES), |
| 61 | + Arguments.of(30, PolarisPrivilege.CATALOG_FULL_METADATA), |
| 62 | + Arguments.of(31, PolarisPrivilege.CATALOG_MANAGE_METADATA), |
| 63 | + Arguments.of(32, PolarisPrivilege.CATALOG_MANAGE_CONTENT), |
| 64 | + Arguments.of(33, PolarisPrivilege.PRINCIPAL_LIST_GRANTS), |
| 65 | + Arguments.of(34, PolarisPrivilege.PRINCIPAL_ROLE_LIST_GRANTS), |
| 66 | + Arguments.of(35, PolarisPrivilege.CATALOG_ROLE_LIST_GRANTS), |
| 67 | + Arguments.of(36, PolarisPrivilege.CATALOG_LIST_GRANTS), |
| 68 | + Arguments.of(37, PolarisPrivilege.NAMESPACE_LIST_GRANTS), |
| 69 | + Arguments.of(38, PolarisPrivilege.TABLE_LIST_GRANTS), |
| 70 | + Arguments.of(39, PolarisPrivilege.VIEW_LIST_GRANTS), |
| 71 | + Arguments.of(40, PolarisPrivilege.CATALOG_MANAGE_GRANTS_ON_SECURABLE), |
| 72 | + Arguments.of(41, PolarisPrivilege.NAMESPACE_MANAGE_GRANTS_ON_SECURABLE), |
| 73 | + Arguments.of(42, PolarisPrivilege.TABLE_MANAGE_GRANTS_ON_SECURABLE), |
| 74 | + Arguments.of(43, PolarisPrivilege.VIEW_MANAGE_GRANTS_ON_SECURABLE), |
| 75 | + Arguments.of(44, PolarisPrivilege.PRINCIPAL_CREATE), |
| 76 | + Arguments.of(45, PolarisPrivilege.PRINCIPAL_DROP), |
| 77 | + Arguments.of(46, PolarisPrivilege.PRINCIPAL_LIST), |
| 78 | + Arguments.of(47, PolarisPrivilege.PRINCIPAL_READ_PROPERTIES), |
| 79 | + Arguments.of(48, PolarisPrivilege.PRINCIPAL_WRITE_PROPERTIES), |
| 80 | + Arguments.of(49, PolarisPrivilege.PRINCIPAL_FULL_METADATA), |
| 81 | + Arguments.of(50, PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_ON_SECURABLE), |
| 82 | + Arguments.of(51, PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_FOR_GRANTEE), |
| 83 | + Arguments.of(52, PolarisPrivilege.PRINCIPAL_ROTATE_CREDENTIALS), |
| 84 | + Arguments.of(53, PolarisPrivilege.PRINCIPAL_RESET_CREDENTIALS), |
| 85 | + Arguments.of(54, PolarisPrivilege.PRINCIPAL_ROLE_CREATE), |
| 86 | + Arguments.of(55, PolarisPrivilege.PRINCIPAL_ROLE_DROP), |
| 87 | + Arguments.of(56, PolarisPrivilege.PRINCIPAL_ROLE_LIST), |
| 88 | + Arguments.of(57, PolarisPrivilege.PRINCIPAL_ROLE_READ_PROPERTIES), |
| 89 | + Arguments.of(58, PolarisPrivilege.PRINCIPAL_ROLE_WRITE_PROPERTIES), |
| 90 | + Arguments.of(59, PolarisPrivilege.PRINCIPAL_ROLE_FULL_METADATA), |
| 91 | + Arguments.of(60, PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_ON_SECURABLE), |
| 92 | + Arguments.of(61, PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_FOR_GRANTEE), |
| 93 | + Arguments.of(62, PolarisPrivilege.CATALOG_ROLE_CREATE), |
| 94 | + Arguments.of(63, PolarisPrivilege.CATALOG_ROLE_DROP), |
| 95 | + Arguments.of(64, PolarisPrivilege.CATALOG_ROLE_LIST), |
| 96 | + Arguments.of(65, PolarisPrivilege.CATALOG_ROLE_READ_PROPERTIES), |
| 97 | + Arguments.of(66, PolarisPrivilege.CATALOG_ROLE_WRITE_PROPERTIES), |
| 98 | + Arguments.of(67, PolarisPrivilege.CATALOG_ROLE_FULL_METADATA), |
| 99 | + Arguments.of(68, PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_ON_SECURABLE), |
| 100 | + Arguments.of(69, PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE), |
| 101 | + Arguments.of(70, PolarisPrivilege.POLICY_CREATE), |
| 102 | + Arguments.of(71, PolarisPrivilege.POLICY_READ), |
| 103 | + Arguments.of(72, PolarisPrivilege.POLICY_DROP), |
| 104 | + Arguments.of(73, PolarisPrivilege.POLICY_WRITE), |
| 105 | + Arguments.of(74, PolarisPrivilege.POLICY_LIST), |
| 106 | + Arguments.of(75, PolarisPrivilege.POLICY_FULL_METADATA), |
| 107 | + Arguments.of(76, PolarisPrivilege.POLICY_ATTACH), |
| 108 | + Arguments.of(77, PolarisPrivilege.POLICY_DETACH), |
| 109 | + Arguments.of(78, PolarisPrivilege.CATALOG_ATTACH_POLICY), |
| 110 | + Arguments.of(79, PolarisPrivilege.NAMESPACE_ATTACH_POLICY), |
| 111 | + Arguments.of(80, PolarisPrivilege.TABLE_ATTACH_POLICY), |
| 112 | + Arguments.of(81, PolarisPrivilege.CATALOG_DETACH_POLICY), |
| 113 | + Arguments.of(82, PolarisPrivilege.NAMESPACE_DETACH_POLICY), |
| 114 | + Arguments.of(83, PolarisPrivilege.TABLE_DETACH_POLICY), |
| 115 | + Arguments.of(84, PolarisPrivilege.POLICY_MANAGE_GRANTS_ON_SECURABLE), |
| 116 | + Arguments.of(85, null)); |
| 117 | + } |
| 118 | + |
| 119 | + @ParameterizedTest |
| 120 | + @MethodSource("polarisPrivileges") |
| 121 | + public void testFromCode(int code, PolarisPrivilege expected) { |
| 122 | + Assertions.assertThat(PolarisPrivilege.fromCode(code)).isEqualTo(expected); |
| 123 | + } |
| 124 | +} |
0 commit comments