2020import org .apache .fluss .cluster .ServerNode ;
2121import org .apache .fluss .config .ConfigOptions ;
2222import org .apache .fluss .config .Configuration ;
23+ import org .apache .fluss .exception .AuthorizationException ;
2324import org .apache .fluss .exception .InvalidTableException ;
2425import org .apache .fluss .metadata .TablePath ;
2526import org .apache .fluss .server .testutils .FlussClusterExtension ;
3334import org .apache .flink .table .catalog .Catalog ;
3435import org .apache .flink .table .catalog .CatalogTable ;
3536import org .apache .flink .table .catalog .ObjectPath ;
37+ import org .apache .flink .table .catalog .exceptions .CatalogException ;
3638import org .apache .flink .types .Row ;
3739import org .apache .flink .util .CloseableIterator ;
3840import org .apache .flink .util .CollectionUtil ;
5456import java .util .Map ;
5557import java .util .stream .Collectors ;
5658
59+ import static org .apache .fluss .config .ConfigOptions .AUTHORIZER_ENABLED ;
5760import static org .apache .fluss .config .ConfigOptions .DEFAULT_LISTENER_NAME ;
5861import static org .apache .fluss .flink .FlinkConnectorOptions .BOOTSTRAP_SERVERS ;
5962import static org .apache .fluss .flink .FlinkConnectorOptions .BUCKET_KEY ;
@@ -594,12 +597,13 @@ void testAuthentication() throws Exception {
594597 Configuration serverConfig = new Configuration ();
595598 serverConfig .setString (ConfigOptions .SERVER_SECURITY_PROTOCOL_MAP .key (), "CLIENT:sasl" );
596599 serverConfig .setString ("security.sasl.enabled.mechanisms" , "plain" );
600+ serverConfig .setString (AUTHORIZER_ENABLED .key (), "true" );
597601 serverConfig .setString (
598602 "security.sasl.plain.jaas.config" ,
599603 "org.apache.fluss.security.auth.sasl.plain.PlainLoginModule required "
600604 + " user_root=\" password\" "
601605 + " user_guest=\" password2\" ;" );
602- serverConfig .setString (ConfigOptions .SUPER_USERS .key (), "USER :root" );
606+ serverConfig .setString (ConfigOptions .SUPER_USERS .key (), "User :root" );
603607 FlussClusterExtension flussClusterExtension =
604608 FlussClusterExtension .builder ()
605609 .setCoordinatorServerListeners (
@@ -613,13 +617,34 @@ void testAuthentication() throws Exception {
613617 .setClusterConf (serverConfig )
614618 .build ();
615619 Catalog authenticateCatalog = null ;
620+
616621 try {
617622 flussClusterExtension .start ();
618623 ServerNode coordinatorServerNode =
619624 flussClusterExtension .getCoordinatorServerNode (clientListenerName );
620625 String bootstrapServers =
621626 String .format (
622627 "%s:%d" , coordinatorServerNode .host (), coordinatorServerNode .port ());
628+
629+ assertThatThrownBy (
630+ () ->
631+ tEnv .executeSql (
632+ String .format (
633+ "create catalog test_non_authorization_catalog with ('type' = 'fluss', "
634+ + "'%s' = '%s', "
635+ + "'default-database' = '%s', "
636+ + "'client.security.protocol' = 'sasl',"
637+ + "'client.security.sasl.username' = 'guest', "
638+ + "'client.security.sasl.password' = 'password2' "
639+ + " )" ,
640+ BOOTSTRAP_SERVERS .key (),
641+ bootstrapServers ,
642+ DEFAULT_DB )))
643+ .rootCause ()
644+ .isExactlyInstanceOf (AuthorizationException .class )
645+ .hasMessageContaining (
646+ "Principal FlussPrincipal{name='guest', type='User'} have no authorization to operate DESCRIBE on resource Resource{type=DATABASE, name='fluss'}" );
647+
623648 authenticateCatalog =
624649 new FlinkCatalog (
625650 CATALOG_NAME ,
@@ -635,7 +660,6 @@ void testAuthentication() throws Exception {
635660
636661 Map <String , String > clientConfig = new HashMap <>();
637662 clientConfig .put (ConfigOptions .CLIENT_SECURITY_PROTOCOL .key (), "sasl" );
638- clientConfig .put (ConfigOptions .CLIENT_SASL_MECHANISM .key (), "plain" );
639663 clientConfig .put ("client.security.sasl.username" , "root" );
640664 clientConfig .put ("client.security.sasl.password" , "password" );
641665 authenticateCatalog =
@@ -657,6 +681,20 @@ void testAuthentication() throws Exception {
657681 }
658682 }
659683
684+ @ Test
685+ void createCatalogWithUnexistedDatabase () {
686+ assertThatThrownBy (
687+ () ->
688+ tEnv .executeSql (
689+ String .format (
690+ "create catalog test_non_exist_database_catalog with ('type' = 'fluss', '%s' = '%s', 'default-database' = 'non-exist')" ,
691+ BOOTSTRAP_SERVERS .key (),
692+ FLUSS_CLUSTER_EXTENSION .getBootstrapServers ())))
693+ .rootCause ()
694+ .isExactlyInstanceOf (CatalogException .class )
695+ .hasMessage ("Database non-exist does not exist in fluss server." );
696+ }
697+
660698 private static void assertOptionsEqual (
661699 Map <String , String > actualOptions , Map <String , String > expectedOptions ) {
662700 actualOptions .remove (ConfigOptions .BOOTSTRAP_SERVERS .key ());
0 commit comments