Skip to content

Commit 3868f69

Browse files
committed
add test for table_by_pk node when roles doesn't have permission to PK
1 parent e194503 commit 3868f69

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

server/tests-py/queries/graphql_query/permissions/setup.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,42 @@ args:
283283
name: search_tracks
284284
schema: public
285285

286+
#Create Books table
287+
- type: run_sql
288+
args:
289+
sql: |
290+
CREATE TABLE books (
291+
id int,
292+
author_name text,
293+
book_name text,
294+
published_on timestamptz,
295+
PRIMARY KEY (id,book_name)
296+
);
297+
298+
# Track table Books
299+
- type: track_table
300+
args:
301+
schema: public
302+
name: books
303+
304+
- type: insert
305+
args:
306+
table: books
307+
objects:
308+
- id: 1
309+
author_name: J.K. Rowling
310+
book_name: Harry Porter
311+
published_on: "1997-06-26"
312+
313+
#Create select permission on books, granting permission only to one of the columns of the primary key
314+
- type: create_select_permission
315+
args:
316+
table: books
317+
role: user
318+
permission:
319+
columns: ["author_name","book_name","published_on"]
320+
filter: {}
321+
286322
#Permission based on PostGIS operators
287323
- type: run_sql
288324
args:

server/tests-py/queries/graphql_query/permissions/teardown.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ args:
77
DROP TABLE author;
88
DROP TABLE "Track" cascade;
99
DROP TABLE "Artist";
10+
DROP TABLE books;
1011
DROP TABLE geom_table;
1112
DROP TABLE jsonb_table;
1213
DROP TABLE gpa cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- description: User cannot access books_by_pk
2+
url: /v1/graphql
3+
status: 200
4+
headers:
5+
X-Hasura-Role: user
6+
response:
7+
errors:
8+
- extensions:
9+
path: $.selectionSet.books_by_pk
10+
code: validation-failed
11+
message: "field \"books_by_pk\" not found in type: 'query_root'"
12+
query:
13+
query: |
14+
query {
15+
books_by_pk(id:1,book_name:"Harry Porter") {
16+
author_name
17+
book_name
18+
published_on
19+
}
20+
}

server/tests-py/test_graphql_queries.py

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def test_jsonb_has_any(self, hge_ctx, transport):
331331
def test_in_and_nin(self, hge_ctx, transport):
332332
check_query_f(hge_ctx, self.dir() + '/in_and_nin.yaml', transport)
333333

334+
def test_user_accessing_books_by_pk_should_fail(self, hge_ctx, transport):
335+
check_query_f(hge_ctx, self.dir() + '/user_should_not_be_able_to_access_books_by_pk.yaml')
336+
334337
@classmethod
335338
def dir(cls):
336339
return 'queries/graphql_query/permissions'

0 commit comments

Comments
 (0)