|
59 | 59 | import org.apache.polaris.core.admin.model.StorageConfigInfo; |
60 | 60 | import org.apache.polaris.core.auth.PolarisPrincipal; |
61 | 61 | import org.apache.polaris.core.catalog.ExternalCatalogFactory; |
| 62 | +import org.apache.polaris.core.config.FeatureConfiguration; |
| 63 | +import org.apache.polaris.core.config.PolarisConfiguration; |
| 64 | +import org.apache.polaris.core.config.RealmConfig; |
62 | 65 | import org.apache.polaris.core.context.CallContext; |
63 | 66 | import org.apache.polaris.core.entity.CatalogEntity; |
64 | 67 | import org.apache.polaris.core.entity.CatalogRoleEntity; |
@@ -1106,10 +1109,89 @@ public void testUpdateTableFallbackToCoarseGrainedWhenFeatureDisabled() { |
1106 | 1109 | PolarisPrivilege.TABLE_WRITE_DATA, |
1107 | 1110 | PolarisPrivilege.TABLE_FULL_METADATA, |
1108 | 1111 | PolarisPrivilege.CATALOG_MANAGE_CONTENT), |
1109 | | - () -> newWrapper().updateTable(TABLE_NS1A_2, request), |
| 1112 | + () -> newWrapperWithFineGrainedAuthzDisabled().updateTable(TABLE_NS1A_2, request), |
1110 | 1113 | null /* cleanupAction */); |
1111 | 1114 | } |
1112 | 1115 |
|
| 1116 | + /** |
| 1117 | + * Creates a wrapper with fine-grained authorization explicitly disabled for testing the fallback |
| 1118 | + * behavior to coarse-grained authorization. |
| 1119 | + */ |
| 1120 | + private IcebergCatalogHandler newWrapperWithFineGrainedAuthzDisabled() { |
| 1121 | + // Create a custom CallContextCatalogFactory that mocks the configuration |
| 1122 | + CallContextCatalogFactory mockFactory = Mockito.mock(CallContextCatalogFactory.class); |
| 1123 | + |
| 1124 | + // Mock the catalog factory to return our regular catalog but with mocked config |
| 1125 | + Mockito.when( |
| 1126 | + mockFactory.createCallContextCatalog( |
| 1127 | + Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) |
| 1128 | + .thenReturn(baseCatalog); |
| 1129 | + |
| 1130 | + return newWrapperWithFineLevelAuthDisabled(Set.of(), CATALOG_NAME, mockFactory, false); |
| 1131 | + } |
| 1132 | + |
| 1133 | + private IcebergCatalogHandler newWrapperWithFineLevelAuthDisabled( |
| 1134 | + Set<String> activatedPrincipalRoles, |
| 1135 | + String catalogName, |
| 1136 | + CallContextCatalogFactory factory, |
| 1137 | + boolean fineGrainedAuthzEnabled) { |
| 1138 | + |
| 1139 | + PolarisPrincipal authenticatedPrincipal = |
| 1140 | + PolarisPrincipal.of(principalEntity, activatedPrincipalRoles); |
| 1141 | + |
| 1142 | + // Create a custom CallContext that returns a custom RealmConfig |
| 1143 | + CallContext mockCallContext = Mockito.mock(CallContext.class); |
| 1144 | + |
| 1145 | + // Create a simple RealmConfig implementation that overrides just what we need |
| 1146 | + RealmConfig customRealmConfig = |
| 1147 | + new RealmConfig() { |
| 1148 | + @Override |
| 1149 | + public <T> T getConfig(String configName) { |
| 1150 | + return realmConfig.getConfig(configName); |
| 1151 | + } |
| 1152 | + |
| 1153 | + @Override |
| 1154 | + public <T> T getConfig(String configName, T defaultValue) { |
| 1155 | + return realmConfig.getConfig(configName, defaultValue); |
| 1156 | + } |
| 1157 | + |
| 1158 | + @Override |
| 1159 | + public <T> T getConfig(PolarisConfiguration<T> config) { |
| 1160 | + return realmConfig.getConfig(config); |
| 1161 | + } |
| 1162 | + |
| 1163 | + @Override |
| 1164 | + @SuppressWarnings("unchecked") |
| 1165 | + public <T> T getConfig(PolarisConfiguration<T> config, CatalogEntity catalogEntity) { |
| 1166 | + // Override the specific configuration we want to test |
| 1167 | + if (config.equals(FeatureConfiguration.ENABLE_FINE_GRAINED_UPDATE_TABLE_PRIVILEGES)) { |
| 1168 | + return (T) Boolean.valueOf(fineGrainedAuthzEnabled); |
| 1169 | + } |
| 1170 | + return realmConfig.getConfig(config, catalogEntity); |
| 1171 | + } |
| 1172 | + }; |
| 1173 | + |
| 1174 | + // Mock the regular CallContext calls |
| 1175 | + Mockito.when(mockCallContext.getRealmConfig()).thenReturn(customRealmConfig); |
| 1176 | + Mockito.when(mockCallContext.getPolarisCallContext()) |
| 1177 | + .thenReturn(callContext.getPolarisCallContext()); |
| 1178 | + |
| 1179 | + return new IcebergCatalogHandler( |
| 1180 | + diagServices, |
| 1181 | + mockCallContext, |
| 1182 | + resolutionManifestFactory, |
| 1183 | + metaStoreManager, |
| 1184 | + userSecretsManager, |
| 1185 | + securityContext(authenticatedPrincipal), |
| 1186 | + factory, |
| 1187 | + catalogName, |
| 1188 | + polarisAuthorizer, |
| 1189 | + reservedProperties, |
| 1190 | + catalogHandlerUtils, |
| 1191 | + emptyExternalCatalogFactory(), |
| 1192 | + polarisEventListener); |
| 1193 | + } |
| 1194 | + |
1113 | 1195 | @Test |
1114 | 1196 | public void testDropTableWithoutPurgeAllSufficientPrivileges() { |
1115 | 1197 | assertSuccess( |
|
0 commit comments