1 -- This is borderline unsafe in that an additional login-capable user exists
2 -- during the test run. Under installcheck, a too-permissive pg_hba.conf
3 -- might allow unwanted logins as regress_authenticated_user_ssa.
5 -- Setup catalog state.
6 ALTER USER regress_authenticated_user_db_ssa superuser;
7 ALTER USER regress_authenticated_user_ssa superuser;
8 CREATE ROLE regress_session_user;
9 CREATE ROLE regress_current_user;
10 GRANT regress_current_user TO regress_authenticated_user_db_sr;
11 GRANT regress_current_user TO regress_authenticated_user_sr;
12 GRANT regress_session_user TO regress_authenticated_user_db_ssa;
13 GRANT regress_session_user TO regress_authenticated_user_ssa;
14 DO $$BEGIN EXECUTE format(
15 'ALTER DATABASE %I SET session_authorization = regress_session_user',
16 current_catalog); END$$;
17 ALTER ROLE regress_authenticated_user_ssa
18 SET session_authorization = regress_session_user;
19 ALTER ROLE regress_authenticated_user_sr SET ROLE = regress_current_user;
22 -- Test ALTER DATABASE consequences
24 -- The longstanding historical behavior is that session_authorization in
25 -- setconfig has no effect. Hence, session_user remains
26 -- regress_authenticated_user_ssa. See comment in InitializeSessionUserId().
27 \c - regress_authenticated_user_db_ssa
28 SELECT current_user, session_user;
29 -- We document "The DEFAULT and RESET forms reset the session and current user
30 -- identifiers to be the originally authenticated user name." If we let
31 -- session_authorization in setconfig have an effect, we'll need to decide
32 -- whether to make RESET differ from DEFAULT.
33 RESET SESSION AUTHORIZATION;
34 SELECT current_user, session_user;
37 'ALTER DATABASE %I RESET session_authorization', current_catalog);
39 'ALTER DATABASE %I SET role = regress_current_user', current_catalog);
42 \c - regress_authenticated_user_db_sr
43 SELECT current_user, session_user;
45 -- Back to superuser, to reverse ALTER DATABASE
46 \c - regress_authenticated_user_db_ssa
47 SELECT current_user, session_user;
49 DO $$BEGIN EXECUTE format(
50 'ALTER DATABASE %I RESET role', current_catalog); END$$;
53 -- Test connection string options
55 \c -reuse-previous=on "user=regress_authenticated_user_db_sr options=-crole=regress_current_user"
56 SELECT current_user, session_user;
58 -- As above, session_authorization has no effect.
59 \c -reuse-previous=on "user=regress_authenticated_user_db_ssa options=-csession_authorization=regress_session_user"
60 SELECT current_user, session_user;
63 -- Test ALTER ROLE consequences
65 \c -reuse-previous=on "user=regress_authenticated_user_sr options="
66 SELECT current_user, session_user;
68 -- As above, session_authorization has no effect.
69 \c - regress_authenticated_user_ssa
70 SELECT current_user, session_user;
71 RESET SESSION AUTHORIZATION;
72 DROP USER regress_session_user;
73 DROP USER regress_current_user;