|
20 | 20 |
|
21 | 21 | import jakarta.annotation.Nonnull; |
22 | 22 | import jakarta.annotation.Nullable; |
23 | | -import java.time.Clock; |
24 | 23 | import java.util.List; |
25 | 24 | import java.util.Map; |
26 | 25 | import java.util.Set; |
27 | | -import org.apache.polaris.core.PolarisCallContext; |
28 | | -import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; |
29 | 26 | import org.apache.polaris.core.config.PolarisConfigurationStore; |
| 27 | +import org.apache.polaris.core.config.RealmConfig; |
| 28 | +import org.apache.polaris.core.config.RealmConfigImpl; |
30 | 29 | import org.apache.polaris.core.context.CallContext; |
31 | 30 | import org.apache.polaris.core.context.RealmContext; |
32 | 31 | import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo; |
|
35 | 34 | import org.junit.jupiter.params.ParameterizedTest; |
36 | 35 | import org.junit.jupiter.params.provider.CsvSource; |
37 | 36 | import org.junit.jupiter.params.provider.ValueSource; |
38 | | -import org.mockito.Mockito; |
39 | 37 |
|
40 | 38 | class InMemoryStorageIntegrationTest { |
41 | 39 |
|
| 40 | + private static final RealmContext REALM_CONTEXT = () -> "realm"; |
| 41 | + |
42 | 42 | @ParameterizedTest |
43 | 43 | @CsvSource({"s3,s3", "s3,s3a", "s3a,s3", "s3a,s3a"}) |
44 | 44 | public void testValidateAccessToLocations(String allowedScheme, String locationScheme) { |
| 45 | + RealmConfig realmConfig = |
| 46 | + new RealmConfigImpl(new MockedConfigurationStore(Map.of()), REALM_CONTEXT); |
45 | 47 | MockInMemoryStorageIntegration storage = new MockInMemoryStorageIntegration(); |
46 | 48 | Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result = |
47 | 49 | storage.validateAccessToLocations( |
| 50 | + realmConfig, |
48 | 51 | new AwsStorageConfigurationInfo( |
49 | 52 | PolarisStorageConfigurationInfo.StorageType.S3, |
50 | 53 | List.of( |
@@ -96,24 +99,12 @@ public void testAwsAccountIdParsing() { |
96 | 99 | @ValueSource(strings = {"s3", "s3a"}) |
97 | 100 | public void testValidateAccessToLocationsWithWildcard(String s3Scheme) { |
98 | 101 | MockInMemoryStorageIntegration storage = new MockInMemoryStorageIntegration(); |
99 | | - Map<String, Boolean> config = Map.of("ALLOW_WILDCARD_LOCATION", true); |
100 | | - PolarisCallContext polarisCallContext = |
101 | | - new PolarisCallContext( |
102 | | - () -> "testRealm", |
103 | | - Mockito.mock(), |
104 | | - new PolarisDefaultDiagServiceImpl(), |
105 | | - new PolarisConfigurationStore() { |
106 | | - @SuppressWarnings("unchecked") |
107 | | - @Override |
108 | | - public <T> @Nullable T getConfiguration( |
109 | | - @Nonnull RealmContext ctx, String configName) { |
110 | | - return (T) config.get(configName); |
111 | | - } |
112 | | - }, |
113 | | - Clock.systemUTC()); |
114 | | - CallContext.setCurrentContext(polarisCallContext); |
| 102 | + Map<String, Object> config = Map.of("ALLOW_WILDCARD_LOCATION", true); |
| 103 | + RealmConfig realmConfig = |
| 104 | + new RealmConfigImpl(new MockedConfigurationStore(config), REALM_CONTEXT); |
115 | 105 | Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result = |
116 | 106 | storage.validateAccessToLocations( |
| 107 | + realmConfig, |
117 | 108 | new FileStorageConfigurationInfo(List.of("file://", "*")), |
118 | 109 | Set.of(PolarisStorageActions.READ), |
119 | 110 | Set.of( |
@@ -151,8 +142,11 @@ public void testValidateAccessToLocationsWithWildcard(String s3Scheme) { |
151 | 142 | @Test |
152 | 143 | public void testValidateAccessToLocationsNoAllowedLocations() { |
153 | 144 | MockInMemoryStorageIntegration storage = new MockInMemoryStorageIntegration(); |
| 145 | + RealmConfig realmConfig = |
| 146 | + new RealmConfigImpl(new MockedConfigurationStore(Map.of()), REALM_CONTEXT); |
154 | 147 | Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result = |
155 | 148 | storage.validateAccessToLocations( |
| 149 | + realmConfig, |
156 | 150 | new AwsStorageConfigurationInfo( |
157 | 151 | PolarisStorageConfigurationInfo.StorageType.S3, |
158 | 152 | List.of(), |
@@ -185,8 +179,11 @@ public void testValidateAccessToLocationsNoAllowedLocations() { |
185 | 179 | @Test |
186 | 180 | public void testValidateAccessToLocationsWithPrefixOfAllowedLocation() { |
187 | 181 | MockInMemoryStorageIntegration storage = new MockInMemoryStorageIntegration(); |
| 182 | + RealmConfig realmConfig = |
| 183 | + new RealmConfigImpl(new MockedConfigurationStore(Map.of()), REALM_CONTEXT); |
188 | 184 | Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result = |
189 | 185 | storage.validateAccessToLocations( |
| 186 | + realmConfig, |
190 | 187 | new AwsStorageConfigurationInfo( |
191 | 188 | PolarisStorageConfigurationInfo.StorageType.S3, |
192 | 189 | List.of("s3://bucket/path/to/warehouse"), |
@@ -220,4 +217,19 @@ public AccessConfig getSubscopedCreds( |
220 | 217 | return null; |
221 | 218 | } |
222 | 219 | } |
| 220 | + |
| 221 | + private static class MockedConfigurationStore implements PolarisConfigurationStore { |
| 222 | + private final Map<String, Object> defaults; |
| 223 | + |
| 224 | + public MockedConfigurationStore(Map<String, Object> defaults) { |
| 225 | + this.defaults = Map.copyOf(defaults); |
| 226 | + } |
| 227 | + |
| 228 | + @Override |
| 229 | + public <T> @Nullable T getConfiguration(@Nonnull RealmContext realmContext, String configName) { |
| 230 | + @SuppressWarnings("unchecked") |
| 231 | + T confgValue = (T) defaults.get(configName); |
| 232 | + return confgValue; |
| 233 | + } |
| 234 | + } |
223 | 235 | } |
0 commit comments