module Test.TOTP.OtherRequestBodies where
import qualified API.Brig as Brig
import API.Common (defPassword)
import SetupHelpers
import Test.TOTP.MockBodies
import Testlib.Prelude
testMockTotpChangePassword :: (HasCallStack) => App ()
testMockTotpChangePassword :: HasCallStack => App ()
testMockTotpChangePassword =
ServiceOverrides -> (HasCallStack => String -> App ()) -> App ()
forall a.
HasCallStack =>
ServiceOverrides -> (HasCallStack => String -> App a) -> App a
withModifiedBackend
ServiceOverrides
forall a. Default a => a
def
{ brigCfg =
setField "optSettings.setPasswordHashingRateLimit.userLimit.inverseRate" (0 :: Int)
}
((HasCallStack => String -> App ()) -> App ())
-> (HasCallStack => String -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \String
domain -> do
alice <- String -> CreateUser -> App Value
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> CreateUser -> App Value
randomUser String
domain CreateUser
forall a. Default a => a
def
email <- asString (alice %. "email")
let newPassword = String
"new-test-password"
body =
[Pair] -> Value
object
[ String
"old_password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
defPassword,
String
"new_password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newPassword,
String
"totp_code" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
mockLoginTotpCode
]
request = Value -> Value -> App Response
forall user.
(HasCallStack, MakesValue user) =>
user -> Value -> App Response
Brig.putPasswordWithBody Value
alice
for_ [toJSON ("123456" :: String), toJSON ("totp:abc" :: String), toJSON ("recovery:invalid" :: String), Number 123456, Bool True] $ \Value
code ->
String -> Value -> Value -> App Value
forall a b.
(HasCallStack, MakesValue a, ToJSON b) =>
String -> b -> a -> App Value
setField String
"totp_code" Value
code Value
body App Value -> (Value -> App Response) -> App Response
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> App Response
request App Response -> (Response -> App ()) -> App ()
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= HasCallStack => Int -> Response -> App ()
Int -> Response -> App ()
assertStatus Int
400
setField "old_password" ("wrong-password" :: String) body >>= request >>= assertStatus 403
request body >>= assertStatus 200
Brig.login alice email newPassword >>= assertStatus 200