restrict openapi spec based on sql grants
This commit is contained in:
@@ -222,6 +222,58 @@ spec withConfig = withConfig baseCfg $ describe "OpenAPI" $ do
|
||||
. nth 0
|
||||
liftIO $ tableTag `shouldBe` Just [aesonQQ|"authors_only"|]
|
||||
|
||||
it "reflects table privileges in the HTTP methods" $ do
|
||||
r <- simpleBody <$> get "/"
|
||||
|
||||
let selectonlyGet = r ^? key "paths" . key "/selectonly" . key "get"
|
||||
selectonlyPost = r ^? key "paths" . key "/selectonly" . key "post"
|
||||
insertonlyGet = r ^? key "paths" . key "/insertonly" . key "get"
|
||||
insertonlyPost = r ^? key "paths" . key "/insertonly" . key "post"
|
||||
insertonlyDelete = r ^? key "paths" . key "/insertonly" . key "delete"
|
||||
limitedStarsGet = r ^? key "paths" . key "/limited_article_stars" . key "get"
|
||||
limitedStarsPost = r ^? key "paths" . key "/limited_article_stars" . key "post"
|
||||
limitedStarsPatch = r ^? key "paths" . key "/limited_article_stars" . key "patch"
|
||||
limitedStarsDelete = r ^? key "paths" . key "/limited_article_stars" . key "delete"
|
||||
|
||||
liftIO $ do
|
||||
selectonlyGet `shouldNotBe` Nothing
|
||||
selectonlyPost `shouldBe` Nothing
|
||||
|
||||
insertonlyGet `shouldBe` Nothing
|
||||
insertonlyPost `shouldNotBe` Nothing
|
||||
insertonlyDelete `shouldBe` Nothing
|
||||
|
||||
limitedStarsGet `shouldNotBe` Nothing
|
||||
limitedStarsPost `shouldNotBe` Nothing
|
||||
limitedStarsPatch `shouldNotBe` Nothing
|
||||
limitedStarsDelete `shouldBe` Nothing
|
||||
|
||||
it "reflects column privileges in the table definition" $ do
|
||||
r <- simpleBody <$> get "/"
|
||||
|
||||
let appUsersId = r ^? key "definitions" . key "app_users" . key "properties" . key "id"
|
||||
appUsersEmail = r ^? key "definitions" . key "app_users" . key "properties" . key "email"
|
||||
appUsersPassword = r ^? key "definitions" . key "app_users" . key "properties" . key "password"
|
||||
appUsersRequired = r ^? key "definitions" . key "app_users" . key "required"
|
||||
|
||||
liftIO $ do
|
||||
appUsersId `shouldNotBe` Nothing
|
||||
appUsersEmail `shouldNotBe` Nothing
|
||||
appUsersPassword `shouldBe` Nothing
|
||||
appUsersRequired `shouldBe` Just [aesonQQ|["id", "email"]|]
|
||||
|
||||
it "reflects column privileges in the rowFilter parameters" $ do
|
||||
r <- simpleBody <$> get "/"
|
||||
|
||||
let filterId = r ^? key "parameters" . key "rowFilter.app_users.id"
|
||||
filterEmail = r ^? key "parameters" . key "rowFilter.app_users.email"
|
||||
filterPassword = r ^? key "parameters" . key "rowFilter.app_users.password"
|
||||
|
||||
liftIO $ do
|
||||
filterId `shouldNotBe` Nothing
|
||||
filterEmail `shouldNotBe` Nothing
|
||||
filterPassword `shouldBe` Nothing
|
||||
|
||||
it "includes a fk description for a O2O relationship" $ do
|
||||
r <- simpleBody <$> get "/"
|
||||
|
||||
|
||||
Vendored
+3
@@ -28,10 +28,13 @@ REVOKE ALL PRIVILEGES ON TABLE
|
||||
, authors_only
|
||||
, insertonly
|
||||
, limited_article_stars
|
||||
, selectonly
|
||||
FROM postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
GRANT SELECT ON TABLE selectonly TO postgrest_test_anonymous;
|
||||
|
||||
GRANT USAGE ON SEQUENCE
|
||||
auto_incrementing_pk_id_seq
|
||||
, items_id_seq
|
||||
|
||||
Vendored
+5
@@ -1926,6 +1926,11 @@ create table app_users (
|
||||
password text not null
|
||||
);
|
||||
|
||||
create table selectonly (
|
||||
id integer primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table private.pages (
|
||||
link int not null unique
|
||||
, url text
|
||||
|
||||
Reference in New Issue
Block a user