4040import org .apache .polaris .core .PolarisCallContext ;
4141import org .apache .polaris .core .admin .model .AuthenticationParameters ;
4242import org .apache .polaris .core .admin .model .AwsStorageConfigInfo ;
43+ import org .apache .polaris .core .admin .model .BearerAuthenticationParameters ;
4344import org .apache .polaris .core .admin .model .Catalog ;
4445import org .apache .polaris .core .admin .model .CatalogProperties ;
4546import org .apache .polaris .core .admin .model .ConnectionConfigInfo ;
@@ -153,6 +154,23 @@ void testCreateCatalogCleansUpInlineSecretsWhenCatalogAlreadyExists() {
153154 verify (userSecretsManager ).deleteSecret (secretReference );
154155 }
155156
157+ @ Test
158+ void testCreateCatalogCleansUpInlineBearerSecretWhenCatalogAlreadyExists () {
159+ SecretReference secretReference =
160+ new SecretReference ("urn:polaris-secret:test:bearer" , Map .of ());
161+ setupExternalCatalogCreate (
162+ secretReference , AuthenticationParameters .AuthenticationTypeEnum .BEARER );
163+ when (metaStoreManager .createCatalog (any (), any (), any ()))
164+ .thenReturn (new CreateCatalogResult (BaseResult .ReturnStatus .ENTITY_ALREADY_EXISTS , null ));
165+
166+ assertThatThrownBy (
167+ () ->
168+ adminService .createCatalog (new CreateCatalogRequest (createExternalBearerCatalog ())))
169+ .isInstanceOf (AlreadyExistsException .class );
170+
171+ verify (userSecretsManager ).deleteSecret (secretReference );
172+ }
173+
156174 @ Test
157175 void testCreateCatalogCleanupFailureDoesNotHideOriginalFailure () {
158176 SecretReference secretReference =
@@ -755,14 +773,20 @@ private PolarisEntity createEntity(String name, PolarisEntityType type) {
755773 }
756774
757775 private void setupExternalCatalogCreate (SecretReference secretReference ) {
776+ setupExternalCatalogCreate (
777+ secretReference , AuthenticationParameters .AuthenticationTypeEnum .OAUTH );
778+ }
779+
780+ private void setupExternalCatalogCreate (
781+ SecretReference secretReference , AuthenticationParameters .AuthenticationTypeEnum authType ) {
758782 when (realmConfig .getConfig (FeatureConfiguration .ALLOW_OVERLAPPING_CATALOG_URLS ))
759783 .thenReturn (true );
760784 when (realmConfig .getConfig (BehaviorChangeConfiguration .STORAGE_CONFIGURATION_MAX_LOCATIONS ))
761785 .thenReturn (-1 );
762786 when (realmConfig .getConfig (FeatureConfiguration .ENABLE_CATALOG_FEDERATION )).thenReturn (true );
763787 when (realmConfig .getConfig (
764788 FeatureConfiguration .SUPPORTED_EXTERNAL_CATALOG_AUTHENTICATION_TYPES ))
765- .thenReturn (List .of (AuthenticationParameters . AuthenticationTypeEnum . OAUTH .name ()));
789+ .thenReturn (List .of (authType .name ()));
766790
767791 GenerateEntityIdResult idResult = mock (GenerateEntityIdResult .class );
768792 when (idResult .getId ()).thenReturn (2L );
@@ -773,15 +797,17 @@ private void setupExternalCatalogCreate(SecretReference secretReference) {
773797 when (identityProvider .allocateServiceIdentity (any ())).thenReturn (Optional .empty ());
774798 }
775799
800+ private AwsStorageConfigInfo createAwsStorageConfig () {
801+ return AwsStorageConfigInfo .builder ()
802+ .setRoleArn ("arn:aws:iam::123456789012:role/my-role" )
803+ .setExternalId ("externalId" )
804+ .setUserArn ("userArn" )
805+ .setStorageType (StorageConfigInfo .StorageTypeEnum .S3 )
806+ .setAllowedLocations (List .of ("s3://bucket/path/to/data" ))
807+ .build ();
808+ }
809+
776810 private Catalog createExternalOauthCatalog () {
777- AwsStorageConfigInfo awsConfigModel =
778- AwsStorageConfigInfo .builder ()
779- .setRoleArn ("arn:aws:iam::123456789012:role/my-role" )
780- .setExternalId ("externalId" )
781- .setUserArn ("userArn" )
782- .setStorageType (StorageConfigInfo .StorageTypeEnum .S3 )
783- .setAllowedLocations (List .of ("s3://bucket/path/to/data" ))
784- .build ();
785811 ConnectionConfigInfo connectionConfigInfo =
786812 IcebergRestConnectionConfigInfo .builder (
787813 ConnectionConfigInfo .ConnectionTypeEnum .ICEBERG_REST )
@@ -800,7 +826,29 @@ private Catalog createExternalOauthCatalog() {
800826 .setType (Catalog .TypeEnum .EXTERNAL )
801827 .setName ("external-catalog" )
802828 .setProperties (CatalogProperties .builder ("s3://bucket/path/to/data" ).build ())
803- .setStorageConfigInfo (awsConfigModel )
829+ .setStorageConfigInfo (createAwsStorageConfig ())
830+ .setConnectionConfigInfo (connectionConfigInfo )
831+ .build ();
832+ }
833+
834+ private Catalog createExternalBearerCatalog () {
835+ ConnectionConfigInfo connectionConfigInfo =
836+ IcebergRestConnectionConfigInfo .builder (
837+ ConnectionConfigInfo .ConnectionTypeEnum .ICEBERG_REST )
838+ .setUri ("https://example.com/polaris/api/catalog" )
839+ .setRemoteCatalogName ("remote-catalog" )
840+ .setAuthenticationParameters (
841+ BearerAuthenticationParameters .builder (
842+ AuthenticationParameters .AuthenticationTypeEnum .BEARER )
843+ .setBearerToken ("bearer-token" )
844+ .build ())
845+ .build ();
846+
847+ return ExternalCatalog .builder ()
848+ .setType (Catalog .TypeEnum .EXTERNAL )
849+ .setName ("external-catalog" )
850+ .setProperties (CatalogProperties .builder ("s3://bucket/path/to/data" ).build ())
851+ .setStorageConfigInfo (createAwsStorageConfig ())
804852 .setConnectionConfigInfo (connectionConfigInfo )
805853 .build ();
806854 }
0 commit comments