From 9dd9265a127ec046ce0e136503ebf941972cd308 Mon Sep 17 00:00:00 2001 From: Pablo Arteaga Date: Thu, 21 Dec 2023 14:42:24 +0100 Subject: [PATCH] Fix checkstyle --- .../java/io/trino/plugin/opa/TestHelpers.java | 37 +++++++++++++------ .../plugin/opa/TestOpaAccessControl.java | 14 +++++-- ...stOpaAccessControlDataFilteringSystem.java | 1 - .../TestOpaBatchAccessControlFiltering.java | 2 +- .../plugin/opa/TestOpaResponseDecoding.java | 12 +++--- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestHelpers.java b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestHelpers.java index ea3b36a5710cb..e82149c99a77d 100644 --- a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestHelpers.java +++ b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestHelpers.java @@ -105,27 +105,34 @@ public static Stream allErrorCasesArgumentProvider() Stream.of(Arguments.of(Named.of("No access response", NO_ACCESS_RESPONSE), AccessDeniedException.class, "Access Denied"))); } - public static SystemSecurityContext systemSecurityContextFromIdentity(Identity identity) { + public static SystemSecurityContext systemSecurityContextFromIdentity(Identity identity) + { return new SystemSecurityContext(identity, new QueryIdGenerator().createNextQueryId(), Instant.now()); } - public abstract static class MethodWrapper { + public abstract static class MethodWrapper + { public abstract boolean isAccessAllowed(OpaAccessControl opaAccessControl); } - public static class ThrowingMethodWrapper extends MethodWrapper { + public static class ThrowingMethodWrapper + extends MethodWrapper + { private final Consumer callable; - public ThrowingMethodWrapper(Consumer callable) { + public ThrowingMethodWrapper(Consumer callable) + { this.callable = callable; } @Override - public boolean isAccessAllowed(OpaAccessControl opaAccessControl) { + public boolean isAccessAllowed(OpaAccessControl opaAccessControl) + { try { this.callable.accept(opaAccessControl); return true; - } catch (AccessDeniedException e) { + } + catch (AccessDeniedException e) { if (!e.getMessage().contains("Access Denied")) { throw new AssertionError("Expected AccessDenied exception to contain 'Access Denied' in the message"); } @@ -134,15 +141,19 @@ public boolean isAccessAllowed(OpaAccessControl opaAccessControl) { } } - public static class ReturningMethodWrapper extends MethodWrapper { + public static class ReturningMethodWrapper + extends MethodWrapper + { private final Function callable; - public ReturningMethodWrapper(Function callable) { + public ReturningMethodWrapper(Function callable) + { this.callable = callable; } @Override - public boolean isAccessAllowed(OpaAccessControl opaAccessControl) { + public boolean isAccessAllowed(OpaAccessControl opaAccessControl) + { return this.callable.apply(opaAccessControl); } } @@ -194,13 +205,15 @@ public Map buildConfig() convertPropertyToString(attribute.getGetter().invoke(config)).ifPresent( propertyValue -> opaConfigBuilder.put(attribute.getInjectionPoint().getProperty(), propertyValue)); } - } catch (InvocationTargetException|IllegalAccessException e) { + } + catch (InvocationTargetException | IllegalAccessException e) { throw new AssertionError("Failed to build config map", e); } return opaConfigBuilder.buildOrThrow(); } - private static Optional convertPropertyToString(Object value) { + private static Optional convertPropertyToString(Object value) + { if (value instanceof Optional optionalValue) { return optionalValue.map(Object::toString); } @@ -209,7 +222,7 @@ private static Optional convertPropertyToString(Object value) { } static final class TestingSystemAccessControlContext - implements SystemAccessControlFactory.SystemAccessControlContext + implements SystemAccessControlFactory.SystemAccessControlContext { private final String trinoVersion; diff --git a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControl.java b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControl.java index 45bf09b8e41fe..2d0cbcbe85810 100644 --- a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControl.java +++ b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControl.java @@ -78,7 +78,7 @@ public class TestOpaAccessControl @Test public void testResponseHasExtraFields() { - InstrumentedHttpClient mockClient = createMockHttpClient(OPA_SERVER_URI, buildValidatingRequestHandler(requestingIdentity, 200,""" + InstrumentedHttpClient mockClient = createMockHttpClient(OPA_SERVER_URI, buildValidatingRequestHandler(requestingIdentity, 200, """ { "result": true, "decision_id": "foo", @@ -1173,7 +1173,11 @@ private void testGetRowFilters(String responseContent, List e @Test public void testGetRowFiltersDoesNothingIfNotConfigured() { - InstrumentedHttpClient httpClient = createMockHttpClient(OPA_SERVER_ROW_FILTERING_URI, request -> {throw new AssertionError("Should not have been called");}); + InstrumentedHttpClient httpClient = createMockHttpClient( + OPA_SERVER_ROW_FILTERING_URI, + request -> { + throw new AssertionError("Should not have been called"); + }); OpaAccessControl authorizer = createOpaAuthorizer(OPA_CONFIG_WITH_ONLY_ALLOW, httpClient); CatalogSchemaTableName tableName = new CatalogSchemaTableName("some_catalog", "some_schema", "some_table"); @@ -1271,7 +1275,11 @@ private void testGetColumnMask(String responseContent, Optional {throw new AssertionError("Should not have been called");}); + InstrumentedHttpClient httpClient = createMockHttpClient( + OPA_SERVER_COLUMN_MASK_URI, + request -> { + throw new AssertionError("Should not have been called"); + }); OpaAccessControl authorizer = createOpaAuthorizer(OPA_CONFIG_WITH_ONLY_ALLOW, httpClient); CatalogSchemaTableName tableName = new CatalogSchemaTableName("some_catalog", "some_schema", "some_table"); diff --git a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControlDataFilteringSystem.java b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControlDataFilteringSystem.java index 1cced9f230a8c..d825233b6f164 100644 --- a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControlDataFilteringSystem.java +++ b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaAccessControlDataFilteringSystem.java @@ -101,7 +101,6 @@ public class TestOpaAccessControlDataFilteringSystem private DistributedQueryRunnerHelper runner; - @AfterEach public void teardown() { diff --git a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaBatchAccessControlFiltering.java b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaBatchAccessControlFiltering.java index 3f63e94cc29cf..b2514593261fc 100644 --- a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaBatchAccessControlFiltering.java +++ b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaBatchAccessControlFiltering.java @@ -261,7 +261,7 @@ public void testFilterColumns() requestingIdentity, parsedRequest -> { String tableName = parsedRequest.at("/input/action/filterResources/0/table/tableName").asText(); - String responseContents = switch(tableName) { + String responseContents = switch (tableName) { case "table_one" -> "{\"result\": [0, 1]}"; case "table_two" -> "{\"result\": [1]}"; default -> "{\"result\": []}"; diff --git a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaResponseDecoding.java b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaResponseDecoding.java index b40bd9213125c..ad08d98878131 100644 --- a/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaResponseDecoding.java +++ b/plugin/trino-opa/src/test/java/io/trino/plugin/opa/TestOpaResponseDecoding.java @@ -216,9 +216,9 @@ public void testRowFilteringResponseWithExtraFields() public void testRowFilteringResponseIllegalResponseThrows() { testIllegalResponseDecodingThrows(""" - { - "result": ["foo"] - }""", rowFilteringResponseCodec); + { + "result": ["foo"] + }""", rowFilteringResponseCodec); } @Test @@ -280,9 +280,9 @@ public void testColumnMaskingResponseWithExtraFields() public void testColumnMaskingResponseIllegalResponseThrows() { testIllegalResponseDecodingThrows(""" - { - "result": {"foo": "bar"} - }""", columnMaskingResponseCodec); + { + "result": {"foo": "bar"} + }""", columnMaskingResponseCodec); } private void testIllegalResponseDecodingThrows(String rawResponse, JsonCodec codec)