module Test.TOTP.Nginz where
import qualified API.Brig as Brig
import API.Common (defPassword)
import SetupHelpers
import Testlib.Prelude
testTotpThroughNginz :: (HasCallStack) => App ()
testTotpThroughNginz :: HasCallStack => App ()
testTotpThroughNginz = do
alice <- Domain -> CreateUser -> App Value
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> CreateUser -> App Value
randomUser Domain
OwnDomain CreateUser
forall a. Default a => a
def
email <- asString (alice %. "email")
token <- do
resp <- Brig.login alice email defPassword >>= getJSON 200
asString (resp %. "access_token")
do
req <-
rawBaseRequest alice Nginz Versioned "/self/totp"
<&> addHeader "Authorization" ("Bearer " <> token)
bindResponse (submit "GET" req) $ \Response
resp -> do
Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
App [Value] -> App ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (App [Value] -> App ()) -> App [Value] -> App ()
forall a b. (a -> b) -> a -> b
$ Maybe Value -> App [Value]
forall a. (HasCallStack, MakesValue a) => a -> App [Value]
asList Response
resp.json
do
req <-
rawBaseRequest alice Nginz Versioned "/self/totp"
<&> addHeader "Authorization" "Bearer not-a-token"
submit "GET" req >>= assertStatus 401
do
req <- rawBaseRequest alice Nginz Versioned "/self/totp"
bindResponse (submit "GET" req) $ \Response
resp ->
HasCallStack => String -> Bool -> App ()
String -> Bool -> App ()
assertBool
(String
"unauthenticated request was not rejected: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Response
resp.status)
(Response
resp.status Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
400 Bool -> Bool -> Bool
&& Response
resp.status Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
500)