Add /dbapi/users route for creating new user

This commit is contained in:
Joe Nelson
2014-10-21 15:01:04 -07:00
parent 5953936c7a
commit 572c235b79
5 changed files with 50 additions and 13 deletions
+8 -6
View File
@@ -1,9 +1,10 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
module Feature.AuthSpec where
-- {{{ Imports
import Test.Hspec
import Test.Hspec.Wai
import Test.Hspec.Wai.JSON
import Network.HTTP.Types
import SpecHelper
@@ -15,10 +16,11 @@ spec = around appWithFixture $
it "hides tables that anonymous does not own" $
get "/authors_only" `shouldRespondWith` 400 -- TODO: should be 404
it "indicates login failure" $ do
let auth = authHeader "dbapi_test_author_a" "fakefake"
let auth = authHeader "dbapi_test_author" "fakefake"
request methodGet "/authors_only" [auth] ""
`shouldRespondWith` 401
-- it "allows users with permissions to see their tables" $ do
-- let auth = authHeader "dbapi_test_author_a" ""
-- request methodGet "/authors_only" [auth] ""
-- `shouldRespondWith` 200
it "allows users with permissions to see their tables" $ do
_ <- post "/dbapi/users" [json| { "id":"jdoe", "pass": "1234", "role": "dbapi_test_author" } |]
let auth = authHeader "jdoe" "1234"
request methodGet "/authors_only" [auth] ""
`shouldRespondWith` 200
-2
View File
@@ -15,5 +15,3 @@ select pg_temp.create_role_if_not_exists('dbapi_anonymous', 'with nologin');
select pg_temp.create_role_if_not_exists('test_default_role', 'with nologin');
select pg_temp.create_role_if_not_exists('dbapi_test_author', 'with nologin');
select pg_temp.create_role_if_not_exists('dbapi_test_author_a', 'with nologin in role dbapi_test_author');
select pg_temp.create_role_if_not_exists('dbapi_test_author_b', 'with nologin in role dbapi_test_author');
+10
View File
@@ -291,6 +291,9 @@ CREATE TABLE auth (
ALTER TABLE dbapi.auth OWNER TO dbapi_test;
REVOKE ALL ON TABLE dbapi.auth FROM dbapi_anonymous;
GRANT INSERT ON TABLE dbapi.auth TO dbapi_anonymous;
SET search_path = private, pg_catalog;
--
@@ -597,8 +600,15 @@ ALTER TABLE ONLY has_fk
REVOKE ALL ON SCHEMA "1" FROM dbapi_test;
GRANT ALL ON SCHEMA "1" TO dbapi_test;
REVOKE ALL ON SCHEMA "1" FROM dbapi_anonymous;
GRANT USAGE ON SCHEMA "1" TO dbapi_anonymous;
REVOKE ALL ON SCHEMA "dbapi" FROM dbapi_anonymous;
GRANT USAGE ON SCHEMA "dbapi" TO dbapi_anonymous;
REVOKE ALL ON SCHEMA "1" FROM dbapi_test_author;
GRANT USAGE ON SCHEMA "1" TO dbapi_test_author;
--
-- TOC entry 2036 (class 0 OID 0)