Store user plugin in db & allow bypassing when using dummy-auth
This commit is contained in:
parent
03bde7a464
commit
514829dc25
13
models
13
models
@ -1,16 +1,7 @@
|
|||||||
User
|
User
|
||||||
|
plugin Text
|
||||||
ident Text
|
ident Text
|
||||||
password Text Maybe
|
UniqueAuthentication plugin ident
|
||||||
UniqueUser ident
|
|
||||||
deriving Typeable
|
|
||||||
Email
|
|
||||||
email Text
|
|
||||||
userId UserId Maybe
|
|
||||||
verkey Text Maybe
|
|
||||||
UniqueEmail email
|
|
||||||
--
|
|
||||||
-- above from Template, needs editing
|
|
||||||
--
|
|
||||||
Term json
|
Term json
|
||||||
name Text
|
name Text
|
||||||
shorthand Text
|
shorthand Text
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
{-# LANGUAGE PatternGuards #-}
|
||||||
|
|
||||||
module Foundation where
|
module Foundation where
|
||||||
|
|
||||||
@ -228,13 +230,19 @@ instance YesodAuth UniWorX where
|
|||||||
-- Override the above two destinations when a Referer: header is present
|
-- Override the above two destinations when a Referer: header is present
|
||||||
redirectToReferer _ = True
|
redirectToReferer _ = True
|
||||||
|
|
||||||
authenticate creds = runDB $ do
|
authenticate Creds{..} = runDB $ do
|
||||||
x <- getBy $ UniqueUser $ credsIdent creds
|
let auth
|
||||||
|
| credsPlugin == "dummy"
|
||||||
|
, [ dummyPlugin, dummyIdent] <- Text.splitOn ":" credsIdent
|
||||||
|
= UniqueAuthentication dummyPlugin dummyIdent
|
||||||
|
| otherwise
|
||||||
|
= UniqueAuthentication credsPlugin credsIdent
|
||||||
|
x <- getBy auth
|
||||||
case x of
|
case x of
|
||||||
Just (Entity uid _) -> return $ Authenticated uid
|
Just (Entity uid _) -> return $ Authenticated uid
|
||||||
Nothing -> Authenticated <$> insert User
|
Nothing -> Authenticated <$> insert User
|
||||||
{ userIdent = credsIdent creds
|
{ userPlugin = credsPlugin
|
||||||
, userPassword = Nothing
|
, userIdent = credsIdent
|
||||||
}
|
}
|
||||||
|
|
||||||
-- You can add other plugins like Google Email, email or OAuth here
|
-- You can add other plugins like Google Email, email or OAuth here
|
||||||
|
|||||||
@ -13,14 +13,14 @@ spec = withApp $ do
|
|||||||
statusIs 403
|
statusIs 403
|
||||||
|
|
||||||
it "asserts access to my-account for authenticated users" $ do
|
it "asserts access to my-account for authenticated users" $ do
|
||||||
userEntity <- createUser "foo"
|
userEntity <- createUser "dummy" "foo"
|
||||||
authenticateAs userEntity
|
authenticateAs userEntity
|
||||||
|
|
||||||
get ProfileR
|
get ProfileR
|
||||||
statusIs 200
|
statusIs 200
|
||||||
|
|
||||||
it "asserts user's information is shown" $ do
|
it "asserts user's information is shown" $ do
|
||||||
userEntity <- createUser "bar"
|
userEntity <- createUser "dummy" "bar"
|
||||||
authenticateAs userEntity
|
authenticateAs userEntity
|
||||||
|
|
||||||
get ProfileR
|
get ProfileR
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE NoImplicitPrelude #-}
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
module TestImport
|
module TestImport
|
||||||
( module TestImport
|
( module TestImport
|
||||||
, module X
|
, module X
|
||||||
@ -70,23 +72,13 @@ getTables = do
|
|||||||
-- being set in test-settings.yaml, which enables dummy authentication in
|
-- being set in test-settings.yaml, which enables dummy authentication in
|
||||||
-- Foundation.hs
|
-- Foundation.hs
|
||||||
authenticateAs :: Entity User -> YesodExample UniWorX ()
|
authenticateAs :: Entity User -> YesodExample UniWorX ()
|
||||||
authenticateAs (Entity _ u) = do
|
authenticateAs (Entity _ User{..}) = do
|
||||||
request $ do
|
request $ do
|
||||||
setMethod "POST"
|
setMethod "POST"
|
||||||
addPostParam "ident" $ userIdent u
|
addPostParam "ident" $ userPlugin <> ":" <> userIdent
|
||||||
setUrl $ AuthR $ PluginR "dummy" []
|
setUrl $ AuthR $ PluginR "dummy" []
|
||||||
|
|
||||||
-- | Create a user. The dummy email entry helps to confirm that foreign-key
|
-- | Create a user. The dummy email entry helps to confirm that foreign-key
|
||||||
-- checking is switched off in wipeDB for those database backends which need it.
|
-- checking is switched off in wipeDB for those database backends which need it.
|
||||||
createUser :: Text -> YesodExample UniWorX (Entity User)
|
createUser :: Text -> Text -> YesodExample UniWorX (Entity User)
|
||||||
createUser ident = runDB $ do
|
createUser userPlugin userIdent = runDB $ insertEntity User{..}
|
||||||
user <- insertEntity User
|
|
||||||
{ userIdent = ident
|
|
||||||
, userPassword = Nothing
|
|
||||||
}
|
|
||||||
_ <- insert Email
|
|
||||||
{ emailEmail = ident
|
|
||||||
, emailUserId = Just $ entityKey user
|
|
||||||
, emailVerkey = Nothing
|
|
||||||
}
|
|
||||||
return user
|
|
||||||
|
|||||||
Reference in New Issue
Block a user