-
Notifications
You must be signed in to change notification settings - Fork 367
Add SUPPORTED_EXTERNAL_CATALOG_AUTHENTICATION_TYPES feature configuration #1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd8bd89
Add SUPPORTED_FEDERATION_AUTHENTICATION_TYPES feature configuration
poojanilangekar 4450b4b
Add unit tests
poojanilangekar 3f8761d
Rename to
poojanilangekar 72de204
Remove CONNECTION_TYPES change
poojanilangekar 3db6ed8
Remove @Mock annotations in the test
poojanilangekar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
238 changes: 238 additions & 0 deletions
238
service/common/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.service.admin; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.List; | ||
| import org.apache.polaris.core.PolarisCallContext; | ||
| import org.apache.polaris.core.admin.model.AuthenticationParameters; | ||
| import org.apache.polaris.core.admin.model.Catalog; | ||
| import org.apache.polaris.core.admin.model.CatalogProperties; | ||
| import org.apache.polaris.core.admin.model.ConnectionConfigInfo; | ||
| import org.apache.polaris.core.admin.model.ExternalCatalog; | ||
| import org.apache.polaris.core.admin.model.FileStorageConfigInfo; | ||
| import org.apache.polaris.core.admin.model.PolarisCatalog; | ||
| import org.apache.polaris.core.admin.model.StorageConfigInfo; | ||
| import org.apache.polaris.core.auth.PolarisAuthorizer; | ||
| import org.apache.polaris.core.config.FeatureConfiguration; | ||
| import org.apache.polaris.core.config.PolarisConfigurationStore; | ||
| import org.apache.polaris.core.context.CallContext; | ||
| import org.apache.polaris.core.context.RealmContext; | ||
| import org.apache.polaris.core.persistence.MetaStoreManagerFactory; | ||
| import org.apache.polaris.core.secrets.UserSecretsManagerFactory; | ||
| import org.apache.polaris.service.config.RealmEntityManagerFactory; | ||
| import org.apache.polaris.service.config.ReservedProperties; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| public class PolarisServiceImplTest { | ||
|
|
||
| private RealmEntityManagerFactory entityManagerFactory; | ||
| private MetaStoreManagerFactory metaStoreManagerFactory; | ||
| private UserSecretsManagerFactory userSecretsManagerFactory; | ||
| private PolarisAuthorizer polarisAuthorizer; | ||
| private CallContext callContext; | ||
| private ReservedProperties reservedProperties; | ||
| private PolarisCallContext polarisCallContext; | ||
| private PolarisConfigurationStore configurationStore; | ||
| private RealmContext realmContext; | ||
|
|
||
| private PolarisServiceImpl polarisService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| entityManagerFactory = Mockito.mock(RealmEntityManagerFactory.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I have removed it. |
||
| metaStoreManagerFactory = Mockito.mock(MetaStoreManagerFactory.class); | ||
| userSecretsManagerFactory = Mockito.mock(UserSecretsManagerFactory.class); | ||
| polarisAuthorizer = Mockito.mock(PolarisAuthorizer.class); | ||
| callContext = Mockito.mock(CallContext.class); | ||
| reservedProperties = Mockito.mock(ReservedProperties.class); | ||
| polarisCallContext = Mockito.mock(PolarisCallContext.class); | ||
| configurationStore = Mockito.mock(PolarisConfigurationStore.class); | ||
| realmContext = Mockito.mock(RealmContext.class); | ||
|
|
||
| when(callContext.getPolarisCallContext()).thenReturn(polarisCallContext); | ||
| when(callContext.getRealmContext()).thenReturn(realmContext); | ||
| when(polarisCallContext.getConfigurationStore()).thenReturn(configurationStore); | ||
| when(configurationStore.getConfiguration( | ||
| realmContext, FeatureConfiguration.SUPPORTED_CATALOG_CONNECTION_TYPES)) | ||
| .thenReturn(List.of("ICEBERG_REST")); | ||
| when(configurationStore.getConfiguration( | ||
| realmContext, FeatureConfiguration.SUPPORTED_EXTERNAL_CATALOG_AUTHENTICATION_TYPES)) | ||
| .thenReturn(List.of("OAUTH")); | ||
|
|
||
| polarisService = | ||
| new PolarisServiceImpl( | ||
| entityManagerFactory, | ||
| metaStoreManagerFactory, | ||
| userSecretsManagerFactory, | ||
| polarisAuthorizer, | ||
| callContext, | ||
| reservedProperties); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateExternalCatalog_InternalCatalog() { | ||
| StorageConfigInfo storageConfig = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://tmp")) | ||
| .build(); | ||
|
|
||
| PolarisCatalog internalCatalog = | ||
| PolarisCatalog.builder() | ||
| .setType(Catalog.TypeEnum.INTERNAL) | ||
| .setName("test-catalog") | ||
| .setProperties(new CatalogProperties("file://tmp")) | ||
| .setStorageConfigInfo(storageConfig) | ||
| .build(); | ||
|
|
||
| assertThatCode(() -> invokeValidateExternalCatalog(polarisService, internalCatalog)) | ||
| .doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateExternalCatalog_LegacyExternalCatalog() { | ||
| StorageConfigInfo storageConfig = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://tmp")) | ||
| .build(); | ||
| ExternalCatalog externalCatalog = | ||
| ExternalCatalog.builder() | ||
| .setType(Catalog.TypeEnum.EXTERNAL) | ||
| .setName("test-catalog") | ||
| .setProperties(new CatalogProperties("file://tmp")) | ||
| .setStorageConfigInfo(storageConfig) | ||
| .setConnectionConfigInfo(null) | ||
| .build(); | ||
|
|
||
| assertThatCode(() -> invokeValidateExternalCatalog(polarisService, externalCatalog)) | ||
| .doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateExternalCatalog_SupportedExternalCatalog() { | ||
| StorageConfigInfo storageConfig = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://tmp")) | ||
| .build(); | ||
|
|
||
| ConnectionConfigInfo connectionConfigInfo = Mockito.mock(ConnectionConfigInfo.class); | ||
| AuthenticationParameters authenticationParameters = | ||
| Mockito.mock(AuthenticationParameters.class); | ||
| when(connectionConfigInfo.getConnectionType()) | ||
| .thenReturn(ConnectionConfigInfo.ConnectionTypeEnum.ICEBERG_REST); | ||
| when(connectionConfigInfo.getAuthenticationParameters()).thenReturn(authenticationParameters); | ||
| when(authenticationParameters.getAuthenticationType()) | ||
| .thenReturn(AuthenticationParameters.AuthenticationTypeEnum.OAUTH); | ||
|
|
||
| ExternalCatalog externalCatalog = | ||
| ExternalCatalog.builder() | ||
| .setType(Catalog.TypeEnum.EXTERNAL) | ||
| .setName("test-catalog") | ||
| .setProperties(new CatalogProperties("file://tmp")) | ||
| .setStorageConfigInfo(storageConfig) | ||
| .setConnectionConfigInfo(connectionConfigInfo) | ||
| .build(); | ||
|
|
||
| assertThatCode(() -> invokeValidateExternalCatalog(polarisService, externalCatalog)) | ||
| .doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateExternalCatalog_UnsupportedConnectionType() { | ||
| StorageConfigInfo storageConfig = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://tmp")) | ||
| .build(); | ||
|
|
||
| ConnectionConfigInfo connectionConfigInfo = Mockito.mock(ConnectionConfigInfo.class); | ||
| AuthenticationParameters authenticationParameters = | ||
| Mockito.mock(AuthenticationParameters.class); | ||
| when(connectionConfigInfo.getConnectionType()) | ||
| .thenReturn(ConnectionConfigInfo.ConnectionTypeEnum.HADOOP); | ||
| when(connectionConfigInfo.getAuthenticationParameters()).thenReturn(authenticationParameters); | ||
| when(authenticationParameters.getAuthenticationType()) | ||
| .thenReturn(AuthenticationParameters.AuthenticationTypeEnum.OAUTH); | ||
|
|
||
| ExternalCatalog externalCatalog = | ||
| ExternalCatalog.builder() | ||
| .setType(Catalog.TypeEnum.EXTERNAL) | ||
| .setName("test-catalog") | ||
| .setProperties(new CatalogProperties("file://tmp")) | ||
| .setStorageConfigInfo(storageConfig) | ||
| .setConnectionConfigInfo(connectionConfigInfo) | ||
| .build(); | ||
|
|
||
| assertThatThrownBy(() -> invokeValidateExternalCatalog(polarisService, externalCatalog)) | ||
| .isInstanceOf(IllegalStateException.class) | ||
| .hasMessage("Unsupported connection type: HADOOP"); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateExternalCatalog_UnsupportedAuthenticationType() { | ||
| StorageConfigInfo storageConfig = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://tmp")) | ||
| .build(); | ||
|
|
||
| ConnectionConfigInfo connectionConfigInfo = Mockito.mock(ConnectionConfigInfo.class); | ||
| AuthenticationParameters authenticationParameters = | ||
| Mockito.mock(AuthenticationParameters.class); | ||
| when(connectionConfigInfo.getConnectionType()) | ||
| .thenReturn(ConnectionConfigInfo.ConnectionTypeEnum.ICEBERG_REST); | ||
| when(connectionConfigInfo.getAuthenticationParameters()).thenReturn(authenticationParameters); | ||
| when(authenticationParameters.getAuthenticationType()) | ||
| .thenReturn(AuthenticationParameters.AuthenticationTypeEnum.BEARER); | ||
|
|
||
| ExternalCatalog externalCatalog = | ||
| ExternalCatalog.builder() | ||
| .setType(Catalog.TypeEnum.EXTERNAL) | ||
| .setName("test-catalog") | ||
| .setProperties(new CatalogProperties("file://tmp")) | ||
| .setStorageConfigInfo(storageConfig) | ||
| .setConnectionConfigInfo(connectionConfigInfo) | ||
| .build(); | ||
|
|
||
| assertThatThrownBy(() -> invokeValidateExternalCatalog(polarisService, externalCatalog)) | ||
| .isInstanceOf(IllegalStateException.class) | ||
| .hasMessage("Unsupported authentication type: BEARER"); | ||
| } | ||
|
|
||
| private void invokeValidateExternalCatalog(PolarisServiceImpl service, Catalog catalog) | ||
| throws Exception { | ||
| Method method = | ||
| PolarisServiceImpl.class.getDeclaredMethod("validateExternalCatalog", Catalog.class); | ||
| method.setAccessible(true); | ||
| try { | ||
| method.invoke(service, catalog); | ||
| } catch (java.lang.reflect.InvocationTargetException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause instanceof Exception) { | ||
| throw (Exception) cause; | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.