forked from supabase/pg_net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_privileges.py
80 lines (67 loc) · 1.87 KB
/
test_privileges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytest
from sqlalchemy import text
def test_net_on_postgres_role(sess):
"""Check that the postgres role can use the net schema by default"""
role = sess.execute(text("select current_user;")).fetchone()
assert role[0] == "postgres"
# Create a request
(request_id,) = sess.execute(text(
"""
select net.http_get(
'http://localhost:8080/anything'
);
"""
)).fetchone()
# Commit so background worker can start
sess.commit()
# Confirm that the request was retrievable
response = sess.execute(
text(
"""
select * from net._http_collect_response(:request_id, async:=false);
"""
),
{"request_id": request_id},
).fetchone()
assert response[0] == "SUCCESS"
def test_net_on_another_role(sess):
"""Check that a newly created role can use the net schema"""
sess.execute(text("""
create role another;
"""))
# Create a request
(request_id,) = sess.execute(text(
"""
set local role to another;
select net.http_get(
'http://localhost:8080/anything'
);
"""
)).fetchone()
# Commit so background worker can start
sess.commit()
# Confirm that the request was retrievable
response = sess.execute(
text(
"""
set local role to another;
select * from net._http_collect_response(:request_id, async:=false);
"""
),
{"request_id": request_id},
).fetchone()
assert response[0] == "SUCCESS"
## can use the net.worker_restart function
response = sess.execute(
text(
"""
set local role to another;
select net.worker_restart();
"""
)
).fetchone()
assert response[0] == True
sess.execute(text("""
set local role postgres;
drop role another;
"""))