From 480800edbd7376b3e688435121953ddb976c98f4 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Tue, 25 Aug 2015 00:22:23 -0700 Subject: [PATCH] Problem after exceptions when authed Reproduces #264 --- test/Feature/AuthSpec.hs | 17 ++++++++++++----- test/fixtures/schema.sql | 13 +++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/test/Feature/AuthSpec.hs b/test/Feature/AuthSpec.hs index ae94f4f8f..915526f06 100644 --- a/test/Feature/AuthSpec.hs +++ b/test/Feature/AuthSpec.hs @@ -28,19 +28,26 @@ spec = beforeAll let auth = authHeaderBasic "jdoe" "1234" request methodGet "/authors_only" [auth] "" `shouldRespondWith` 200 - + + it "recovers after 400 error with logged in user" $ do + _ <- post "/postgrest/users" [json| { "id":"jdoe", "pass": "1234", "role": "postgrest_test_author" } |] + let auth = authHeaderBasic "jdoe" "1234" + _ <- request methodPost "/rpc/problem" [auth] "" + request methodGet "/authors_only" [auth] "" + `shouldRespondWith` 200 + it "allows users to login (JWT)" $ do _ <- post "/postgrest/users" [json| { "id":"jdoe", "pass": "1234", "role": "postgrest_test_author" } |] - post "/postgrest/tokens" [json| { "id":"jdoe", "pass": "1234" } |] + post "/postgrest/tokens" [json| { "id":"jdoe", "pass": "1234" } |] `shouldRespondWith` ResponseMatcher { matchBody = Just [json| {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIiwiaWQiOiJqZG9lIn0.y4vZuu1dDdwAl0-S00MCRWRYMlJ5YAMSir6Es6WtWx0"} |] , matchStatus = 201 , matchHeaders = ["Content-Type" <:> "application/json"] } - + it "indicates login failure (JWT)" $ do _ <- post "/postgrest/users" [json| { "id":"jdoe", "pass": "1234", "role": "postgrest_test_author" } |] - post "/postgrest/tokens" [json| { "id":"jdoe", "pass": "NOPE" } |] + post "/postgrest/tokens" [json| { "id":"jdoe", "pass": "NOPE" } |] `shouldRespondWith` ResponseMatcher { matchBody = Just [json| {"message":"Failed authentication."} |] , matchStatus = 401 @@ -51,4 +58,4 @@ spec = beforeAll _ <- post "/postgrest/users" [json| { "id":"jdoe", "pass": "1234", "role": "postgrest_test_author" } |] let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIiwiaWQiOiJqZG9lIn0.y4vZuu1dDdwAl0-S00MCRWRYMlJ5YAMSir6Es6WtWx0" request methodGet "/authors_only" [auth] "" - `shouldRespondWith` 200 \ No newline at end of file + `shouldRespondWith` 200 diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 3d705f9ef..6796d2167 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -228,6 +228,14 @@ CREATE FUNCTION "1".sayhello(name text) RETURNS text AS $$ $$ LANGUAGE SQL; +CREATE FUNCTION "1".problem() RETURNS void LANGUAGE plpgsql AS +$$ +BEGIN + RAISE 'bad thing'; +END; +$$; + + CREATE TABLE menagerie ( "integer" integer NOT NULL, double double precision NOT NULL, @@ -544,6 +552,11 @@ GRANT EXECUTE ON FUNCTION sayhello(text) TO postgrest_test; GRANT EXECUTE ON FUNCTION sayhello(text) TO postgrest_anonymous; +REVOKE ALL ON FUNCTION problem() FROM PUBLIC; +REVOKE ALL ON FUNCTION problem() FROM postgrest_test_author; +GRANT EXECUTE ON FUNCTION problem() TO postgrest_test_author; + + REVOKE ALL ON SEQUENCE items_id_seq FROM PUBLIC; REVOKE ALL ON SEQUENCE items_id_seq FROM postgrest_test; GRANT ALL ON SEQUENCE items_id_seq TO postgrest_test;