diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/authentication/t/001_password.pl | 42 | ||||
| -rw-r--r-- | src/test/kerberos/t/001_auth.pl | 28 | ||||
| -rw-r--r-- | src/test/regress/expected/create_view.out | 6 | ||||
| -rw-r--r-- | src/test/regress/sql/create_view.sql | 3 |
4 files changed, 74 insertions, 5 deletions
diff --git a/src/test/authentication/t/001_password.pl b/src/test/authentication/t/001_password.pl index 3e3079c824a..58e4176e80d 100644 --- a/src/test/authentication/t/001_password.pl +++ b/src/test/authentication/t/001_password.pl @@ -72,6 +72,11 @@ $node->safe_psql('postgres', $node->safe_psql('postgres', "SET password_encryption='md5'; CREATE ROLE md5_role LOGIN PASSWORD 'pass';" ); +# Set up a table for tests of SYSTEM_USER. +$node->safe_psql( + 'postgres', + "CREATE TABLE sysuser_data (n) AS SELECT NULL FROM generate_series(1, 10); + GRANT ALL ON sysuser_data TO md5_role;"); $ENV{"PGPASSWORD"} = 'pass'; # For "trust" method, all users should be able to connect. These users are not @@ -82,6 +87,24 @@ test_role($node, 'scram_role', 'trust', 0, test_role($node, 'md5_role', 'trust', 0, log_unlike => [qr/connection authenticated:/]); +# SYSTEM_USER is null when not authenticated. +my $res = $node->safe_psql('postgres', "SELECT SYSTEM_USER IS NULL;"); +is($res, 't', "users with trust authentication use SYSTEM_USER = NULL"); + +# Test SYSTEM_USER with parallel workers when not authenticated. +$res = $node->safe_psql( + 'postgres', qq( + SET min_parallel_table_scan_size TO 0; + SET parallel_setup_cost TO 0; + SET parallel_tuple_cost TO 0; + SET max_parallel_workers_per_gather TO 2; + + SELECT bool_and(SYSTEM_USER IS NOT DISTINCT FROM n) FROM sysuser_data;), + connstr => "user=md5_role"); +is($res, 't', + "users with trust authentication use SYSTEM_USER = NULL in parallel workers" +); + # For plain "password" method, all users should also be able to connect. reset_pg_hba($node, 'password'); test_role($node, 'scram_role', 'password', 0, @@ -120,6 +143,25 @@ test_role($node, 'md5_role', 'md5', 0, log_like => [qr/connection authenticated: identity="md5_role" method=md5/]); +# Test SYSTEM_USER <> NULL with parallel workers. +$node->safe_psql( + 'postgres', + "TRUNCATE sysuser_data; +INSERT INTO sysuser_data SELECT 'md5:md5_role' FROM generate_series(1, 10);", + connstr => "user=md5_role"); +$res = $node->safe_psql( + 'postgres', qq( + SET min_parallel_table_scan_size TO 0; + SET parallel_setup_cost TO 0; + SET parallel_tuple_cost TO 0; + SET max_parallel_workers_per_gather TO 2; + + SELECT bool_and(SYSTEM_USER IS NOT DISTINCT FROM n) FROM sysuser_data;), + connstr => "user=md5_role"); +is($res, 't', + "users with md5 authentication use SYSTEM_USER = md5:role in parallel workers" +); + # Tests for channel binding without SSL. # Using the password authentication method; channel binding can't work reset_pg_hba($node, 'password'); diff --git a/src/test/kerberos/t/001_auth.pl b/src/test/kerberos/t/001_auth.pl index 47169a1d1eb..a2bc8a5351e 100644 --- a/src/test/kerberos/t/001_auth.pl +++ b/src/test/kerberos/t/001_auth.pl @@ -4,8 +4,8 @@ # Sets up a KDC and then runs a variety of tests to make sure that the # GSSAPI/Kerberos authentication and encryption are working properly, # that the options in pg_hba.conf and pg_ident.conf are handled correctly, -# and that the server-side pg_stat_gssapi view reports what we expect to -# see for each test. +# that the server-side pg_stat_gssapi view reports what we expect to +# see for each test and that SYSTEM_USER returns what we expect to see. # # Since this requires setting up a full KDC, it doesn't make much sense # to have multiple test scripts (since they'd have to also create their @@ -180,6 +180,13 @@ $node->start; $node->safe_psql('postgres', 'CREATE USER test1;'); +# Set up a table for SYSTEM_USER parallel worker testing. +$node->safe_psql('postgres', + "CREATE TABLE ids (id) AS SELECT 'gss:test1\@$realm' FROM generate_series(1, 10);" +); + +$node->safe_psql('postgres', 'GRANT SELECT ON ids TO public;'); + note "running tests"; # Test connection success or failure, and if success, that query returns true. @@ -311,6 +318,23 @@ test_query( 'gssencmode=require', 'sending 100K lines works'); +# Test that SYSTEM_USER works. +test_query($node, 'test1', 'SELECT SYSTEM_USER;', + qr/^gss:test1\@$realm$/s, 'gssencmode=require', 'testing system_user'); + +# Test that SYSTEM_USER works with parallel workers. +test_query( + $node, + 'test1', qq( + SET min_parallel_table_scan_size TO 0; + SET parallel_setup_cost TO 0; + SET parallel_tuple_cost TO 0; + SET max_parallel_workers_per_gather TO 2; + SELECT bool_and(SYSTEM_USER = id) FROM ids;), + qr/^t$/s, + 'gssencmode=require', + 'testing system_user with parallel workers'); + unlink($node->data_dir . '/pg_hba.conf'); $node->append_conf('pg_hba.conf', qq{hostgssenc all all $hostaddr/32 gss map=mymap}); diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out index a828b1f6de6..bf4ff30d86f 100644 --- a/src/test/regress/expected/create_view.out +++ b/src/test/regress/expected/create_view.out @@ -1940,7 +1940,8 @@ select trim(trailing ' foo ') as rt, trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) as btb, trim(leading E'\\000'::bytea from E'\\000Tom\\000'::bytea) as ltb, - trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea) as rtb; + trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea) as rtb, + SYSTEM_USER as su; select pg_get_viewdef('tt201v', true); pg_get_viewdef ----------------------------------------------------------------------------------------------- @@ -1961,7 +1962,8 @@ select pg_get_viewdef('tt201v', true); TRIM(TRAILING FROM ' foo '::text) AS rt, + TRIM(BOTH '\x00'::bytea FROM '\x00546f6d00'::bytea) AS btb, + TRIM(LEADING '\x00'::bytea FROM '\x00546f6d00'::bytea) AS ltb, + - TRIM(TRAILING '\x00'::bytea FROM '\x00546f6d00'::bytea) AS rtb; + TRIM(TRAILING '\x00'::bytea FROM '\x00546f6d00'::bytea) AS rtb, + + SYSTEM_USER AS su; (1 row) -- corner cases with empty join conditions diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql index 44a6775f907..913b4ee4601 100644 --- a/src/test/regress/sql/create_view.sql +++ b/src/test/regress/sql/create_view.sql @@ -721,7 +721,8 @@ select trim(trailing ' foo ') as rt, trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) as btb, trim(leading E'\\000'::bytea from E'\\000Tom\\000'::bytea) as ltb, - trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea) as rtb; + trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea) as rtb, + SYSTEM_USER as su; select pg_get_viewdef('tt201v', true); -- corner cases with empty join conditions |
