Add more tests for [un-]registering servers
This commit is contained in:
parent
57f420ab4c
commit
03bc3436cd
@ -126,16 +126,21 @@ CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_credentials_to_user_mapping(inpu
|
||||
RETURNS jsonb
|
||||
AS $$
|
||||
DECLARE
|
||||
user_mapping jsonb := json_build_object(
|
||||
'user_mapping',
|
||||
jsonb_build_object( 'user', input_config->'credentials'->'username',
|
||||
'password', input_config->'credentials'->'password')
|
||||
);
|
||||
mapping jsonb := '{}'::jsonb;
|
||||
BEGIN
|
||||
IF NOT (input_config ? 'credentials') THEN
|
||||
RAISE EXCEPTION 'Credentials are mandatory';
|
||||
END IF;
|
||||
RETURN (input_config - 'credentials')::jsonb || user_mapping;
|
||||
|
||||
-- For now, allow not passing username or password
|
||||
IF input_config->'credentials'->'username' IS NOT NULL THEN
|
||||
mapping := jsonb_build_object('user', input_config->'credentials'->'username');
|
||||
END IF;
|
||||
IF input_config->'credentials'->'password' IS NOT NULL THEN
|
||||
mapping := mapping || jsonb_build_object('password', input_config->'credentials'->'password');
|
||||
END IF;
|
||||
|
||||
RETURN (input_config - 'credentials')::jsonb || jsonb_build_object('user_mapping', mapping);
|
||||
END
|
||||
$$
|
||||
LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
|
||||
@ -154,6 +159,9 @@ DECLARE
|
||||
}';
|
||||
server_config jsonb;
|
||||
BEGIN
|
||||
IF NOT (input_config ? 'server') THEN
|
||||
RAISE EXCEPTION 'Server information is mandatory';
|
||||
END IF;
|
||||
server_config := default_options || to_jsonb(input_config->'server');
|
||||
RETURN jsonb_set(input_config, '{server}'::text[], server_config);
|
||||
END
|
||||
|
@ -71,15 +71,64 @@ SELECT '5.1', cartodb.CDB_Federated_Server_Unregister(server := 'doesNotExist'::
|
||||
SELECT '6.1', cartodb.CDB_Federated_Server_Unregister(server := 'myRemote2'::text);
|
||||
SELECT '6.2', cartodb.CDB_Federated_Server_List_Servers();
|
||||
|
||||
-- Should show the appropiate output (database, read-write, user, pass)
|
||||
-- Test empty config
|
||||
SELECT '7.1', cartodb.CDB_Federated_Server_Register_PG(server := 'empty'::text, config := '{}');
|
||||
-- Test without passing credentials
|
||||
SELECT '7.2', cartodb.CDB_Federated_Server_Register_PG(server := 'empty'::text, config := '{
|
||||
"server": {
|
||||
"dbname": "fdw_target",
|
||||
"host": "localhost",
|
||||
"port": @@PGPORT@@,
|
||||
"extensions": "postgis",
|
||||
"updatable": "false",
|
||||
"use_remote_estimate": "true",
|
||||
"fetch_size": "1000"
|
||||
}
|
||||
}'::jsonb);
|
||||
-- Test with empty credentials
|
||||
SELECT '7.3', cartodb.CDB_Federated_Server_Register_PG(server := 'empty'::text, config := '{
|
||||
"server": {
|
||||
"dbname": "fdw_target",
|
||||
"host": "localhost",
|
||||
"port": @@PGPORT@@,
|
||||
"extensions": "postgis",
|
||||
"updatable": "false",
|
||||
"use_remote_estimate": "true",
|
||||
"fetch_size": "1000"
|
||||
},
|
||||
"credentials": { }
|
||||
}'::jsonb);
|
||||
SELECT '7.4', cartodb.CDB_Federated_Server_List_Servers();
|
||||
SELECT '7.5', cartodb.CDB_Federated_Server_Unregister(server := 'empty'::text);
|
||||
-- Test without without server options
|
||||
SELECT '7.6', cartodb.CDB_Federated_Server_Register_PG(server := 'empty'::text, config := '{
|
||||
"credentials": {
|
||||
"username": "other_remote_user",
|
||||
"password": "foobarino"
|
||||
}
|
||||
}'::jsonb);
|
||||
|
||||
-- Test multiple user mappings
|
||||
-- Should work ok with special characters
|
||||
SELECT '8.1', cartodb.CDB_Federated_Server_Register_PG(server := 'myRemote" or''not'::text, config := '{
|
||||
"server": {
|
||||
"dbname": "fdw target",
|
||||
"host": "localhost",
|
||||
"port": @@PGPORT@@,
|
||||
"extensions": "postgis",
|
||||
"updatable": "false",
|
||||
"use_remote_estimate": "true",
|
||||
"fetch_size": "1000"
|
||||
},
|
||||
"credentials": {
|
||||
"username": "fdw user",
|
||||
"password": "foo barino"
|
||||
}
|
||||
}'::jsonb);
|
||||
SELECT '8.2', cartodb.CDB_Federated_Server_List_Servers();
|
||||
SELECT '8.3', cartodb.CDB_Federated_Server_Unregister(server := 'myRemote" or''not'::text);
|
||||
|
||||
-- Should work ok with special characters in the name
|
||||
|
||||
-- Should throw with invalid or NULL config
|
||||
|
||||
-- -- List works with multiple and single server
|
||||
-- Should throw when trying to unregistering a server that doesn't exists
|
||||
SELECT '8.4', cartodb.CDB_Federated_Server_Unregister(server := 'Does not exist'::text);
|
||||
|
||||
-- Cleanup
|
||||
\set QUIET on
|
||||
|
@ -11,3 +11,13 @@
|
||||
4.2|(myRemote2,postgres_fdw,localhost,5432,fdw_target,read-only,other_remote_user)
|
||||
ERROR: Server "doesNotExist" does not exist
|
||||
6.1|
|
||||
ERROR: Server information is mandatory
|
||||
ERROR: Credentials are mandatory
|
||||
7.3|
|
||||
7.4|(empty,postgres_fdw,localhost,5432,fdw_target,read-only,)
|
||||
7.5|
|
||||
ERROR: Server information is mandatory
|
||||
8.1|
|
||||
8.2|("myRemote"" or'not",postgres_fdw,localhost,5432,"fdw target",read-only,"fdw user")
|
||||
8.3|
|
||||
ERROR: Server "Does not exist" does not exist
|
||||
|
Loading…
Reference in New Issue
Block a user