@@ -37,18 +37,21 @@ DETAIL: Failing row contains (8, user2, {CREATE}, SCHEMA, appschema, sometable,
37
37
CREATE SCHEMA appschema;
38
38
GRANT USAGE ON SCHEMA appschema TO PUBLIC; -- missing CREATE for user1
39
39
GRANT CREATE ON SCHEMA appschema TO user2; -- too much
40
+ CREATE SCHEMA pgabc123;
41
+ GRANT USAGE ON SCHEMA pgabc123 TO user1;
40
42
/* table */
41
43
-- desired permissions
42
44
INSERT INTO permission_target
43
45
(role_name, permissions, object_type, schema_name, object_name, column_name)
44
46
VALUES ('user1', ARRAY['SELECT','INSERT','UPDATE','DELETE']::perm_type[], 'TABLE', 'appschema', NULL, NULL),
45
- ('user2', ARRAY['SELECT']::perm_type[], 'TABLE', 'appschema', NULL, NULL);
47
+ ('user2', ARRAY['SELECT']::perm_type[], 'TABLE', 'appschema', NULL, NULL),
48
+ ('user1', ARRAY['SELECT']::perm_type[], 'TABLE', 'pgabc213', 'sometable', NULL);
46
49
-- this should fail
47
50
INSERT INTO permission_target
48
51
(role_name, permissions, object_type, schema_name, object_name, column_name)
49
52
VALUES ('user2', ARRAY['INSERT']::perm_type[], 'TABLE', 'appschema', 'apptable', 'acolumn');
50
53
ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
51
- DETAIL: Failing row contains (11 , user2, {INSERT}, TABLE, appschema, apptable, acolumn).
54
+ DETAIL: Failing row contains (12 , user2, {INSERT}, TABLE, appschema, apptable, acolumn).
52
55
-- actual permissions
53
56
CREATE TABLE appschema.apptable (
54
57
id integer PRIMARY KEY,
@@ -60,8 +63,14 @@ CREATE TABLE appschema.apptable2 (
60
63
val text NOT NULL,
61
64
created timestamp with time zone NOT NULL DEFAULT current_timestamp
62
65
); -- missing all permissions on this one
66
+ CREATE TABLE pgabc123.sometable (
67
+ id integer PRIMARY KEY,
68
+ val text NOT NULL,
69
+ created timestamp with time zone NOT NULL DEFAULT current_timestamp
70
+ );
63
71
GRANT SELECT, INSERT, UPDATE ON appschema.apptable TO user1; -- missing DELETE
64
72
GRANT SELECT, INSERT ON appschema.apptable TO user2; -- extra privilege INSERT
73
+ GRANT SELECT ON pgabc123.sometable TO user1;
65
74
/* column */
66
75
-- desired permissions
67
76
INSERT INTO permission_target
@@ -72,7 +81,7 @@ INSERT INTO permission_target
72
81
(role_name, permissions, object_type, schema_name, object_name, column_name)
73
82
VALUES ('user2', ARRAY['DELETE']::perm_type[], 'COLUMN', 'appschema', 'apptable2', 'val');
74
83
ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
75
- DETAIL: Failing row contains (13 , user2, {DELETE}, COLUMN, appschema, apptable2, val).
84
+ DETAIL: Failing row contains (14 , user2, {DELETE}, COLUMN, appschema, apptable2, val).
76
85
-- actual permissions
77
86
-- missing REFERENCES for user1 on apptable2.val
78
87
GRANT UPDATE (val) ON appschema.apptable2 TO user2; -- extra privilege UPDATE
@@ -109,7 +118,7 @@ INSERT INTO permission_target
109
118
(role_name, permissions, object_type, schema_name, object_name, column_name)
110
119
VALUES ('users', ARRAY['UPDATE']::perm_type[], 'FUNCTION', 'appschema', 'appfun(integer)', NULL);
111
120
ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
112
- DETAIL: Failing row contains (21 , users, {UPDATE}, FUNCTION, appschema, appfun(integer), null).
121
+ DETAIL: Failing row contains (22 , users, {UPDATE}, FUNCTION, appschema, appfun(integer), null).
113
122
-- actual permissions
114
123
CREATE FUNCTION appschema.appfun(i integer) RETURNS integer
115
124
LANGUAGE sql IMMUTABLE AS
@@ -119,13 +128,14 @@ SELECT object_type, role_name, schema_name, object_name, column_name, permission
119
128
FROM all_permissions
120
129
WHERE granted
121
130
AND role_name IN ('users', 'user1', 'user2')
122
- AND coalesce(schema_name, 'appschema') = 'appschema'
131
+ AND coalesce(schema_name, 'appschema') IN ( 'appschema', 'pgabc123')
123
132
ORDER BY object_type, role_name, schema_name, object_name, column_name, permission;
124
133
object_type | role_name | schema_name | object_name | column_name | permission
125
134
-------------+-----------+-------------+-----------------+-------------+------------
126
135
TABLE | user1 | appschema | apptable | | SELECT
127
136
TABLE | user1 | appschema | apptable | | INSERT
128
137
TABLE | user1 | appschema | apptable | | UPDATE
138
+ TABLE | user1 | pgabc123 | sometable | | SELECT
129
139
TABLE | user2 | appschema | apptable | | SELECT
130
140
TABLE | user2 | appschema | apptable | | INSERT
131
141
VIEW | user1 | appschema | appview | | SELECT
@@ -142,6 +152,7 @@ ORDER BY object_type, role_name, schema_name, object_name, column_name, permissi
142
152
FUNCTION | user2 | appschema | appfun(integer) | | EXECUTE
143
153
FUNCTION | users | appschema | appfun(integer) | | EXECUTE
144
154
SCHEMA | user1 | appschema | | | USAGE
155
+ SCHEMA | user1 | pgabc123 | | | USAGE
145
156
SCHEMA | user2 | appschema | | | USAGE
146
157
SCHEMA | user2 | appschema | | | CREATE
147
158
SCHEMA | users | appschema | | | USAGE
@@ -152,7 +163,7 @@ ORDER BY object_type, role_name, schema_name, object_name, column_name, permissi
152
163
DATABASE | user2 | | | | TEMPORARY
153
164
DATABASE | users | | | | CONNECT
154
165
DATABASE | users | | | | TEMPORARY
155
- (29 rows)
166
+ (31 rows)
156
167
157
168
/* report differences */
158
169
SELECT * FROM permission_diffs()
@@ -229,7 +240,9 @@ DROP VIEW appschema.appview;
229
240
DROP SEQUENCE appschema.appseq;
230
241
DROP TABLE appschema.apptable;
231
242
DROP TABLE appschema.apptable2;
243
+ DROP TABLE pgabc123.sometable;
232
244
DROP SCHEMA appschema;
245
+ DROP SCHEMA pgabc123;
233
246
REVOKE ALL ON DATABASE contrib_regression FROM user1, user2, users;
234
247
DROP ROLE user1;
235
248
DROP ROLE user2;
0 commit comments