bharos commented on code in PR #10704:
URL: https://github.com/apache/gravitino/pull/10704#discussion_r3102900394
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/server/web/filter/IcebergMetadataAuthorizationMethodInterceptor.java:
##########
@@ -131,4 +132,27 @@ protected Optional<AuthorizationHandler>
createAuthorizationHandler(
protected boolean isExceptionPropagate(Exception e) {
return e.getClass().getName().startsWith("org.apache.iceberg.exceptions");
}
+
+ @Override
Review Comment:
nit : The base class hook has a proper JavaDoc, but the override in
IcebergMetadataAuthorizationMethodInterceptor has no documentation explaining
when/why it skips. A brief @Override comment noting the REST-backend proxy
scenario would help.
##########
iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/server/web/filter/TestIcebergMetadataAuthorizationMethodInterceptor.java:
##########
@@ -165,6 +176,212 @@ public void testIsExceptionPropagate() {
assertFalse(interceptor.isExceptionPropagate(otherException));
}
+ @Test
+ public void testInvokeSkipsAuthorizationForRestCatalog() throws Throwable {
+ IcebergCatalogWrapperManager wrapperManager =
Mockito.mock(IcebergCatalogWrapperManager.class);
+ CatalogWrapperForREST wrapper = Mockito.mock(CatalogWrapperForREST.class);
+ RESTCatalog restCatalog = Mockito.mock(RESTCatalog.class);
+
Mockito.when(wrapperManager.getCatalogWrapper(TEST_CATALOG)).thenReturn(wrapper);
+ Mockito.when(wrapper.getCatalog()).thenReturn(restCatalog);
+ Mockito.when(wrapper.isRESTCatalog()).thenReturn(true);
+ resetContext(wrapperManager, true);
+
+ Method method =
+ TestOperations.class.getMethod(
+ "testTableOperationWithAuthorizationExpression",
+ String.class,
+ String.class,
+ String.class);
+ MethodInvocation invocation = Mockito.mock(MethodInvocation.class);
+ Mockito.when(invocation.getMethod()).thenReturn(method);
+ Mockito.when(invocation.getArguments())
+ .thenReturn(new Object[] {TEST_CATALOG + "/", TEST_SCHEMA, "tbl"});
+ Mockito.when(invocation.proceed()).thenReturn("PROCEEDED");
+
+ IcebergMetadataAuthorizationMethodInterceptor interceptor =
+ new IcebergMetadataAuthorizationMethodInterceptor() {
+ @Override
+ protected Optional<AuthorizationHandler> createAuthorizationHandler(
+ Parameter[] parameters, Object[] args) {
+ return Optional.of(
+ new AuthorizationHandler() {
+ @Override
+ public void process(Map<Entity.EntityType, NameIdentifier>
nameIdentifierMap)
+ throws ForbiddenException {
+ throw new RuntimeException("test");
+ }
+
+ @Override
+ public boolean authorizationCompleted() {
+ return false;
+ }
+ });
+ }
+ };
+ Object result = interceptor.invoke(invocation);
+
+ assertEquals("PROCEEDED", result);
+ Mockito.verify(invocation, Mockito.times(1)).proceed();
+ }
+
+ @Test
+ public void testInvokeDoesNotSkipAuthorizationForNonRestCatalog() throws
Throwable {
Review Comment:
nit:
It works because Mockito returns false for un-stubbed boolean methods, but
an explicit Mockito.when(wrapper.isRESTCatalog()).thenReturn(false) would make
the test intent clearer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]