Re-enable authentication

This commit is contained in:
Joe Nelson
2014-12-06 17:42:22 -08:00
parent 13bc9a4510
commit a45718e992
6 changed files with 65 additions and 57 deletions
+7 -12
View File
@@ -8,21 +8,17 @@ import Test.Hspec.Wai.JSON
import SpecHelper
import Network.HTTP.Types
import Codec.Binary.Base64.String (encode)
import Data.Monoid ((<>))
import Data.String.Conversions (cs)
spec :: Spec
spec = around withApp $ do
let uName = "a user"
uPass = "nobody can ever know"
describe "GET /" $
it "lists views in schema" $
request methodGet "/"
[("Authorization", "Basic "<>(uName<>":"<>uPass))] ""
it "lists views in schema" $ do
_ <- post "/dbapi/users" [json| { "id":"jdoe", "pass": "1234", "role": "dbapi_test_author" } |]
let auth = authHeader "jdoe" "1234"
request methodGet "/" [auth] ""
`shouldRespondWith` [json| [
{"schema":"1","name":"authors_only","insertable":true}
, {"schema":"1","name":"auto_incrementing_pk","insertable":true}
{"schema":"1","name":"auto_incrementing_pk","insertable":true}
, {"schema":"1","name":"compound_pk","insertable":true}
, {"schema":"1","name":"has_fk","insertable":true}
, {"schema":"1","name":"items","insertable":true}
@@ -136,8 +132,7 @@ spec = around withApp $ do
|]
it "includes foreign key data" $
request methodOptions "/has_fk"
[("Authorization", "Basic "<>(cs.encode $ cs uName<>":"<>cs uPass))] ""
request methodOptions "/has_fk" [] ""
`shouldRespondWith` [json|
{
"pkey": ["id"],
+7 -5
View File
@@ -27,15 +27,16 @@ import Network.Wai.Middleware.Cors (cors)
import System.Process (readProcess)
import App (app, sqlErrHandler, isSqlError)
import Config (corsPolicy)
import Config (AppConfig(..), corsPolicy)
import Middleware
-- import Auth (addUser)
isLeft :: Either a b -> Bool
isLeft (Left _ ) = True
isLeft _ = False
-- cfg :: AppConfig
-- cfg = AppConfig "postgres://dbapi_test:@localhost:5432/dbapi_test" 9000 "dbapi_anonymous" False 10
cfg :: AppConfig
cfg = AppConfig "postgres://dbapi_test:@localhost:5432/dbapi_test" 9000 "dbapi_anonymous" False 10
testSettings :: SessionSettings
testSettings = fromMaybe (error "bad settings") $ H.sessionSettings 1 30
@@ -48,8 +49,9 @@ withApp perform =
perform $ middle $ \req resp ->
H.session pgSettings testSettings $ do
session' <- flip runReaderT <$> ask
liftIO $ resp =<< catchJust isSqlError (session' $ app req)
sqlErrHandler
liftIO $ resp =<< catchJust isSqlError
(session' $ authenticated (cs $ configAnonRole cfg) app req)
sqlErrHandler
where middle = cors corsPolicy