-
Notifications
You must be signed in to change notification settings - Fork 332
[chore] Port 2FA tests #3986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[chore] Port 2FA tests #3986
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0c5481
ported 2FA tests
battermann 8d81b67
changelog
battermann 6d224a1
linter
battermann 32a91c2
addressed comments
battermann 31569b7
fix test
battermann 3582136
ported 2FA tests
battermann 53efc14
linter
battermann 113efd0
hi ci
battermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Ported 2FA tests to the new integration test suite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| {-# OPTIONS_GHC -Wno-ambiguous-fields #-} | ||
|
|
||
| module Test.Login where | ||
|
|
||
| import API.BrigInternal (getVerificationCode) | ||
| import API.Common (defPassword) | ||
| import API.GalleyInternal | ||
| import API.Nginz (login, loginWith2ndFactor) | ||
| import Control.Concurrent (threadDelay) | ||
| import qualified Data.Aeson as Aeson | ||
| import SetupHelpers | ||
| import Testlib.Prelude | ||
| import Text.Printf (printf) | ||
|
|
||
| testLoginVerify6DigitEmailCodeSuccess :: HasCallStack => App () | ||
| testLoginVerify6DigitEmailCodeSuccess = do | ||
| (owner, team, []) <- createTeam OwnDomain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| generateVerificationCode owner email | ||
| code <- getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
| bindResponse (loginWith2ndFactor owner email defPassword code) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
|
|
||
| -- @SF.Channel @TSFI.RESTfulAPI @S2 | ||
| -- | ||
| -- Test that login fails with wrong second factor email verification code | ||
| testLoginVerify6DigitWrongCodeFails :: HasCallStack => App () | ||
| testLoginVerify6DigitWrongCodeFails = do | ||
| (owner, team, []) <- createTeam OwnDomain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| generateVerificationCode owner email | ||
| correctCode <- getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
| let wrongCode :: String = printf "%06d" $ (read @Int correctCode) + 1 `mod` 1000000 | ||
| bindResponse (loginWith2ndFactor owner email defPassword wrongCode) $ \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-failed" | ||
|
|
||
| -- @END | ||
|
|
||
| -- @SF.Channel @TSFI.RESTfulAPI @S2 | ||
| -- | ||
| -- Test that login without verification code fails if SndFactorPasswordChallenge feature is enabled in team | ||
| testLoginVerify6DigitMissingCodeFails :: HasCallStack => App () | ||
| testLoginVerify6DigitMissingCodeFails = do | ||
| (owner, team, []) <- createTeam OwnDomain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| bindResponse (login owner email defPassword) $ \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-required" | ||
|
|
||
| -- @END | ||
|
|
||
| -- @SF.Channel @TSFI.RESTfulAPI @S2 | ||
| -- | ||
| -- Test that login fails with expired second factor email verification code | ||
| testLoginVerify6DigitExpiredCodeFails :: HasCallStack => App () | ||
| testLoginVerify6DigitExpiredCodeFails = do | ||
| withModifiedBackend | ||
| (def {brigCfg = setField "optSettings.setVerificationTimeout" (Aeson.Number 1)}) | ||
| $ \domain -> do | ||
| (owner, team, []) <- createTeam domain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| generateVerificationCode owner email | ||
| code <- getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
| liftIO $ threadDelay 2_000_100 | ||
| bindResponse (loginWith2ndFactor owner email defPassword code) \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-failed" | ||
|
|
||
| -- @END | ||
|
|
||
| testLoginVerify6DigitResendCodeSuccessAndRateLimiting :: HasCallStack => App () | ||
| testLoginVerify6DigitResendCodeSuccessAndRateLimiting = do | ||
| (owner, team, []) <- createTeam OwnDomain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| generateVerificationCode owner email | ||
| fstCode <- getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
| bindResponse (generateVerificationCode' owner email) $ \resp -> do | ||
| resp.status `shouldMatchInt` 429 | ||
| mostRecentCode <- retryT $ do | ||
| resp <- generateVerificationCode' owner email | ||
| resp.status `shouldMatchInt` 200 | ||
| getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
|
|
||
| bindResponse (loginWith2ndFactor owner email defPassword fstCode) \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-failed" | ||
|
|
||
| bindResponse (loginWith2ndFactor owner email defPassword mostRecentCode) \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
|
|
||
| testLoginVerify6DigitLimitRetries :: HasCallStack => App () | ||
| testLoginVerify6DigitLimitRetries = do | ||
| (owner, team, []) <- createTeam OwnDomain 0 | ||
| email <- owner %. "email" | ||
| setTeamFeatureLockStatus owner team "sndFactorPasswordChallenge" "unlocked" | ||
| setTeamFeatureStatus owner team "sndFactorPasswordChallenge" "enabled" | ||
| generateVerificationCode owner email | ||
| correctCode <- getVerificationCode owner "login" >>= getJSON 200 >>= asString | ||
| let wrongCode :: String = printf "%06d" $ (read @Int correctCode) + 1 `mod` 1000000 | ||
| -- try login with wrong code should fail 3 times | ||
| forM_ [1 .. 3] $ \(_ :: Int) -> do | ||
| bindResponse (loginWith2ndFactor owner email defPassword wrongCode) \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-failed" | ||
| -- after 3 failed attempts, login with correct code should fail as well | ||
| bindResponse (loginWith2ndFactor owner email defPassword correctCode) \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "code-authentication-failed" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the old test, we were checking the json content as well, i think that was useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't find it, can you point me to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/wireapp/wire-server/pull/3986/files#diff-5d67659df46f564af0bf4bf2cfa2977d5be77b859c66c70cb18fe7c6571b9393L449-L455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i was reading it wrong. all good!