Skip to content

Commit

Permalink
[WPB-8628] Clean up syntax of test cases that occur in BSI audit. (#4041
Browse files Browse the repository at this point in the history
)


Co-authored-by: Leif Battermann <[email protected]>
  • Loading branch information
fisx and battermann authored May 10, 2024
1 parent 4f4891f commit 44a66c5
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 442 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up syntax of test cases that occur in BSI audit.
3 changes: 0 additions & 3 deletions integration/test/Test/AccessUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ testBaz :: HasCallStack => App ()
testBaz = pure ()
-}

-- | @SF.Federation @SF.Separation @TSFI.RESTfulAPI @S2
--
-- The test asserts that, among others, remote users are removed from a
-- conversation when an access update occurs that disallows guests from
Expand Down Expand Up @@ -74,8 +73,6 @@ testAccessUpdateGuestRemoved = do
res.status `shouldMatchInt` 200
res.json %. "members.others.0.qualified_id" `shouldMatch` objQidObject bob

-- @END

testAccessUpdateGuestRemovedUnreachableRemotes :: HasCallStack => App ()
testAccessUpdateGuestRemovedUnreachableRemotes = do
resourcePool <- asks resourcePool
Expand Down
9 changes: 0 additions & 9 deletions integration/test/Test/Login.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ testLoginVerify6DigitEmailCodeSuccess = do
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 ()
Expand All @@ -39,9 +38,6 @@ testLoginVerify6DigitWrongCodeFails = 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 ()
Expand All @@ -54,9 +50,6 @@ testLoginVerify6DigitMissingCodeFails = 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 ()
Expand All @@ -80,8 +73,6 @@ testLoginVerify6DigitExpiredCodeFails = do
resp.status `shouldMatchInt` 403
resp.json %. "label" `shouldMatch` "code-authentication-failed"

-- @END

testLoginVerify6DigitResendCodeSuccessAndRateLimiting :: HasCallStack => App ()
testLoginVerify6DigitResendCodeSuccessAndRateLimiting = do
(owner, team, []) <- createTeam OwnDomain 0
Expand Down
5 changes: 1 addition & 4 deletions libs/zauth/test/ZAuth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tests = do
],
testGroup
"Signing and Verifying"
[ testCase "expired" (runCreate z 1 $ testExpired v),
[ testCase "testExpired - expired" (runCreate z 1 $ testExpired v),
testCase "not expired" (runCreate z 2 $ testNotExpired v),
testCase "signed access-token is valid" (runCreate z 3 $ testSignAndVerify v)
],
Expand Down Expand Up @@ -94,7 +94,6 @@ testNotExpired p = do
liftIO $ assertBool "testNotExpired: validation failed" (isRight x)

-- The testExpired test conforms to the following testing standards:
-- @SF.Channel @TSFI.RESTfulAPI @TSFI.NTP @S2 @S3
--
-- Using an expired access token should fail
testExpired :: V.Env -> Create ()
Expand All @@ -105,8 +104,6 @@ testExpired p = do
x <- liftIO $ runValidate p $ check t
liftIO $ Left Expired @=? x

-- @END

testSignAndVerify :: V.Env -> Create ()
testSignAndVerify p = do
u <- liftIO nextRandom
Expand Down
27 changes: 6 additions & 21 deletions services/brig/test/integration/API/User/Account.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ tests _ at opts p b c ch g aws userJournalWatcher =
testGroup
"account"
[ test p "post /register - 201 (with preverified)" $ testCreateUserWithPreverified opts b userJournalWatcher,
test p "post /register - 400 (with preverified)" $ testCreateUserWithInvalidVerificationCode b,
test p "testCreateUserWithInvalidVerificationCode - post /register - 400 (with preverified)" $ testCreateUserWithInvalidVerificationCode b,
test p "post /register - 201" $ testCreateUser b g,
test p "post /register - 201 + no email" $ testCreateUserNoEmailNoPassword b,
test p "post /register - 201 anonymous" $ testCreateUserAnon b g,
test p "post /register - 400 empty name" $ testCreateUserEmptyName b,
test p "post /register - 400 name too long" $ testCreateUserLongName b,
test p "testCreateUserEmptyName - post /register - 400 empty name" $ testCreateUserEmptyName b,
test p "testCreateUserLongName - post /register - 400 name too long" $ testCreateUserLongName b,
test p "post /register - 201 anonymous expiry" $ testCreateUserAnonExpiry b,
test p "post /register - 201 pending" $ testCreateUserPending opts b,
test p "post /register - 201 existing activation" $ testCreateAccountPendingActivationKey opts b,
test p "post /register - 409 conflict" $ testCreateUserConflict opts b,
test p "post /register - 400 invalid input" $ testCreateUserInvalidEmailOrPhone opts b,
test p "testCreateUserConflict - post /register - 409 conflict" $ testCreateUserConflict opts b,
test p "testCreateUserInvalidEmailOrPhone - post /register - 400 invalid input" $ testCreateUserInvalidEmailOrPhone opts b,
test p "post /register - 403 blacklist" $ testCreateUserBlacklist opts b aws,
test p "post /register - 400 external-SSO" $ testCreateUserExternalSSO b,
test p "post /register - 403 restricted user creation" $ testRestrictedUserCreation opts b,
Expand Down Expand Up @@ -172,7 +172,6 @@ tests _ at opts p b c ch g aws userJournalWatcher =
]

-- The testCreateUserWithInvalidVerificationCode test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- Registering with an invalid verification code and valid account details should fail.
testCreateUserWithInvalidVerificationCode :: Brig -> Http ()
Expand All @@ -197,8 +196,6 @@ testCreateUserWithInvalidVerificationCode brig = do
]
postUserRegister' regEmail brig !!! const 404 === statusCode

-- @END

testUpdateUserEmailByTeamOwner :: Opt.Opts -> Brig -> Http ()
testUpdateUserEmailByTeamOwner opts brig = do
(_, teamOwner, emailOwner : otherTeamMember : _) <- createPopulatedBindingTeamWithNamesAndHandles brig 2
Expand Down Expand Up @@ -336,7 +333,6 @@ assertOnlySelfConversations galley uid = do
liftIO $ cnvType conv @?= SelfConv

-- The testCreateUserEmptyName test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- An empty name is not allowed on registration
testCreateUserEmptyName :: Brig -> Http ()
Expand All @@ -348,10 +344,7 @@ testCreateUserEmptyName brig = do
post (brig . path "/register" . contentJson . body p)
!!! const 400 === statusCode

-- @END

-- The testCreateUserLongName test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- a name with > 128 characters is not allowed.
testCreateUserLongName :: Brig -> Http ()
Expand All @@ -364,8 +357,6 @@ testCreateUserLongName brig = do
post (brig . path "/register" . contentJson . body p)
!!! const 400 === statusCode

-- @END

testCreateUserAnon :: Brig -> Galley -> Http ()
testCreateUserAnon brig galley = do
let p =
Expand Down Expand Up @@ -443,7 +434,6 @@ testCreateUserNoEmailNoPassword brig = do
!!! (const 202 === statusCode)

-- The testCreateUserConflict test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- email address must not be taken on @/register@.
testCreateUserConflict :: Opt.Opts -> Brig -> Http ()
Expand Down Expand Up @@ -475,10 +465,7 @@ testCreateUserConflict _ brig = do
const 409 === statusCode
const (Just "key-exists") === fmap Error.label . responseJsonMaybe

-- @END

-- The testCreateUserInvalidEmailOrPhone test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- Test to make sure a new user cannot be created with an invalid email address or invalid phone number.
testCreateUserInvalidEmailOrPhone :: Opt.Opts -> Brig -> Http ()
Expand Down Expand Up @@ -508,8 +495,6 @@ testCreateUserInvalidEmailOrPhone _ brig = do
post (brig . path "/register" . contentJson . body reqPhone)
!!! const 400 === statusCode

-- @END

testCreateUserBlacklist :: Opt.Opts -> Brig -> AWS.Env -> Http ()
testCreateUserBlacklist (Opt.setRestrictUserCreation . Opt.optSettings -> Just True) _ _ = pure ()
testCreateUserBlacklist _ brig aws =
Expand Down Expand Up @@ -893,7 +878,7 @@ testCreateUserAnonExpiry b = do
let diff = diffUTCTime a now
minExp = 1 :: Integer -- 1 second
maxExp = 60 * 60 * 24 * 10 :: Integer -- 10 days
liftIO $ assertBool "expiry must in be the future" (diff >= fromIntegral minExp)
liftIO $ assertBool "expiry must be in the future" (diff >= fromIntegral minExp)
liftIO $ assertBool "expiry must be less than 10 days" (diff < fromIntegral maxExp)
expire :: ResponseLBS -> Maybe UTCTime
expire r = field "expires_at" =<< responseJsonMaybe r
Expand Down
22 changes: 5 additions & 17 deletions services/brig/test/integration/API/User/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ tests conf m z db b g n =
test m "handle" (testHandleLogin b),
test m "email-untrusted-domain" (testLoginUntrustedDomain b),
test m "send-phone-code" (testSendLoginCode b),
test m "failure" (testLoginFailure b),
test m "testLoginFailure - failure" (testLoginFailure b),
test m "throttle" (testThrottleLogins conf b),
test m "limit-retry" (testLimitRetries conf b),
test m "testLimitRetries - limit-retry" (testLimitRetries conf b),
test m "login with 6 character password" (testLoginWith6CharPassword b db),
testGroup
"sso-login"
Expand All @@ -129,8 +129,8 @@ tests conf m z db b g n =
],
testGroup
"refresh /access"
[ test m "invalid-cookie" (testInvalidCookie @ZAuth.User z b),
test m "invalid-cookie legalhold" (testInvalidCookie @ZAuth.LegalHoldUser z b),
[ test m "testInvalidCookie - invalid-cookie" (testInvalidCookie @ZAuth.User z b),
test m "testInvalidCookie - invalid-cookie legalhold" (testInvalidCookie @ZAuth.LegalHoldUser z b),
test m "invalid-token" (testInvalidToken z b),
test m "missing-cookie" (testMissingCookie @ZAuth.User @ZAuth.Access z b),
test m "missing-cookie legalhold" (testMissingCookie @ZAuth.LegalHoldUser @ZAuth.LegalHoldAccess z b),
Expand Down Expand Up @@ -161,7 +161,7 @@ tests conf m z db b g n =
[ test m "list" (testListCookies b),
test m "remove-by-label" (testRemoveCookiesByLabel b),
test m "remove-by-label-id" (testRemoveCookiesByLabelAndId b),
test m "limit" (testTooManyCookies conf b),
test m "testTooManyCookies - limit" (testTooManyCookies conf b),
test m "logout" (testLogout b)
],
testGroup
Expand Down Expand Up @@ -423,7 +423,6 @@ testSendLoginCode brig = do
liftIO $ assertEqual "timeout" (Just (Code.Timeout 600)) _timeout

-- The testLoginFailure test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- Test that trying to log in with a wrong password or non-existent email fails.
testLoginFailure :: Brig -> Http ()
Expand All @@ -446,8 +445,6 @@ testLoginFailure brig = do
PersistentCookie
!!! const 403 === statusCode

-- @END

testThrottleLogins :: Opts.Opts -> Brig -> Http ()
testThrottleLogins conf b = do
-- Get the maximum amount of times we are allowed to login before
Expand All @@ -473,7 +470,6 @@ testThrottleLogins conf b = do
login b (defEmailLogin e) SessionCookie !!! const 200 === statusCode

-- The testLimitRetries test conforms to the following testing standards:
-- @SF.Channel @TSFI.RESTfulAPI @TSFI.NTP @S2
--
-- The following test tests the login retries. It checks that a user can make
-- only a prespecified number of attempts to log in with an invalid password,
Expand Down Expand Up @@ -528,8 +524,6 @@ testLimitRetries conf brig = do
liftIO $ threadDelay (1000000 * 2)
login brig (defEmailLogin email) SessionCookie !!! const 200 === statusCode

-- @END

-------------------------------------------------------------------------------
-- LegalHold Login

Expand Down Expand Up @@ -656,7 +650,6 @@ testNoUserSsoLogin brig = do
-- Token Refresh

-- The testInvalidCookie test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @TSFI.NTP @S2
--
-- Test that invalid and expired tokens do not work.
testInvalidCookie :: forall u. ZAuth.UserTokenLike u => ZAuth.Env -> Brig -> Http ()
Expand All @@ -674,8 +667,6 @@ testInvalidCookie z b = do
const 403 === statusCode
const (Just "expired") =~= responseBody

-- @END

testInvalidToken :: ZAuth.Env -> Brig -> Http ()
testInvalidToken z b = do
user <- Public.userId <$> randomUser b
Expand Down Expand Up @@ -1188,7 +1179,6 @@ testRemoveCookiesByLabelAndId b = do
listCookies b (userId u) >>= liftIO . ([lbl] @=?) . map cookieLabel

-- The testTooManyCookies test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- The test asserts that there is an upper limit for the number of user cookies
-- per cookie type. It does that by concurrently attempting to create more
Expand Down Expand Up @@ -1238,8 +1228,6 @@ testTooManyCookies config b = do
)
xxx -> error ("Unexpected status code when logging in: " ++ show xxx)

-- @END

testLogout :: Brig -> Http ()
testLogout b = do
Just email <- userEmail <$> randomUser b
Expand Down
Loading

0 comments on commit 44a66c5

Please sign in to comment.