Skip to content

Commit

Permalink
WIP: integration: Move provider password reset test
Browse files Browse the repository at this point in the history
No clue how to get password reset code
  • Loading branch information
akshaymankar committed Feb 5, 2025
1 parent c87be1e commit c0b0696
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions integration/test/API/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,26 @@ loginProvider dom email pass = do
setCookieHeader = CI.mk (T.encodeUtf8 . T.pack $ "Set-Cookie")
pure . fromJust . foldMap (\(k, v) -> guard (k == setCookieHeader) $> v) $ hs

requestProviderPasswordResetCode ::
(HasCallStack, MakesValue domain) =>
domain ->
String ->
App Response
requestProviderPasswordResetCode domain email = do
req <- rawBaseRequest domain Brig Versioned $ joinHttpPath ["provider", "password-reset"]
submit "POST" $ req & addJSONObject ["email" .= email]

completeProviderPasswordReset ::
(HasCallStack, MakesValue domain) =>
domain ->
Value ->
String ->
App Response
completeProviderPasswordReset domain resetCode newPassword = do
req <- rawBaseRequest domain Brig Versioned $ joinHttpPath ["provider", "password-reset", "complete"]
body <- make (setField "password" newPassword resetCode)
submit "POST" $ req & addJSON body

newService ::
( HasCallStack,
MakesValue dom
Expand Down
23 changes: 23 additions & 0 deletions integration/test/Test/Provider.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Test.Provider where

import API.Brig
import API.BrigInternal
import qualified API.Cargohold as Cargohold
import API.Common
import qualified API.Nginz as Nginz
Expand All @@ -23,6 +24,28 @@ testProviderUploadAsset = do
bindResponse (Nginz.uploadProviderAsset OwnDomain (cs cookie) "another profile pic") $ \resp -> do
resp.status `shouldMatchInt` 201

testProviderPasswordReset :: (HasCallStack) => App ()
testProviderPasswordReset = do
withModifiedBackend
def
{ brigCfg =
-- Disable password hashing rate limiting, so we can create enable services quickly
setField @_ @Int "optSettings.setPasswordHashingRateLimit.userLimit.inverseRate" 0
}
$ \domain -> do
provider <- setupProvider domain def {newProviderPassword = Just defPassword}
pid <- asString $ provider %. "id"
email <- asString $ provider %. "email"
requestProviderPasswordResetCode domain email >>= assertSuccess
resetCode <- getPasswordResetCode domain email >>= getJSON 200

completeProviderPasswordReset domain resetCode defPassword `bindResponse` \resp -> do
resp.status `shouldMatchInt` 403
resp.json %. "label" `shouldMatch` "something"

completeProviderPasswordReset domain resetCode "shiny-new-password" >>= assertSuccess
undefined pid email

testProviderSearchWhitelist :: (HasCallStack) => App ()
testProviderSearchWhitelist =
withModifiedBackend
Expand Down

0 comments on commit c0b0696

Please sign in to comment.