Skip to content
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

Re-introduce test case tags for BSI audit (revert #4041). #4192

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4-docs/revert-wpb8628
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-introduce test case tags for BSI audit (revert #4041)
3 changes: 3 additions & 0 deletions integration/test/Test/AccessUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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 @@ -73,6 +74,8 @@ 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: 9 additions & 0 deletions integration/test/Test/Login.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 @@ -38,6 +39,9 @@ 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 @@ -50,6 +54,9 @@ 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 @@ -73,6 +80,8 @@ 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: 4 additions & 1 deletion 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 "testExpired - expired" (runCreate z 1 $ testExpired v),
[ testCase "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,6 +94,7 @@ 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 @@ -104,6 +105,8 @@ 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
32 changes: 32 additions & 0 deletions services/brig/test/integration/API/User/Account.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ 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 "testCreateUserWithInvalidVerificationCode - post /register - 400 (with preverified)" $ testCreateUserWithInvalidVerificationCode b,
test p "post /register - 201" $ testCreateUser b g,
test p "post /register - 201 anonymous" $ testCreateUserAnon b g,
test p "testCreateUserEmptyName - post /register - 400 empty name" $ testCreateUserEmptyName b,
Expand Down Expand Up @@ -160,6 +161,25 @@ 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 ()
testCreateUserWithInvalidVerificationCode brig = do
-- Attempt to register (pre verified) user with email
e <- randomEmail
code <- randomActivationCode -- incorrect but syntactically valid activation code
let Object regEmail =
object
[ "name" .= Name "Alice",
"email" .= fromEmail e,
"email_code" .= code
]
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 @@ -270,6 +290,7 @@ 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 @@ -281,7 +302,10 @@ 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 @@ -294,6 +318,8 @@ 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 @@ -351,6 +377,7 @@ testCreateUserPending _ brig = do
Search.assertCan'tFind brig suid quid "Mr. Pink"

-- 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 @@ -382,7 +409,10 @@ testCreateUserConflict _ brig = do
const 409 === statusCode
const (Just "key-exists") === fmap Error.label . responseJsonMaybe

-- @END

-- The testCreateUserInvalidEmail 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.
testCreateUserInvalidEmail :: Opt.Opts -> Brig -> Http ()
Expand Down Expand Up @@ -412,6 +442,8 @@ testCreateUserInvalidEmail _ 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
12 changes: 12 additions & 0 deletions services/brig/test/integration/API/User/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ testLoginUntrustedDomain brig = do
!!! const 200 === statusCode

-- 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 @@ -397,6 +398,8 @@ 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 @@ -422,6 +425,7 @@ 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 @@ -476,6 +480,8 @@ testLimitRetries conf brig = do
liftIO $ threadDelay (1000000 * 2)
login brig (defEmailLogin email) SessionCookie !!! const 200 === statusCode

-- @END

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

Expand Down Expand Up @@ -602,6 +608,7 @@ 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 @@ -619,6 +626,8 @@ 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 @@ -1131,6 +1140,7 @@ 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 @@ -1180,6 +1190,8 @@ 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
24 changes: 24 additions & 0 deletions services/brig/test/integration/API/User/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ testAddGetClientVerificationCode db brig galley = do
const 200 === statusCode
const (Just c) === responseJsonMaybe

-- @SF.Channel @TSFI.RESTfulAPI @S2
--
-- Test that device cannot be added with missing second factor email verification code when this feature is enabled
testAddGetClientMissingCode :: Brig -> Galley -> Http ()
Expand All @@ -178,6 +179,9 @@ testAddGetClientMissingCode brig galley = do
const 403 === statusCode
const (Just "code-authentication-required") === fmap Error.label . responseJsonMaybe

-- @END

-- @SF.Channel @TSFI.RESTfulAPI @S2
--
-- Test that device cannot be added with wrong second factor email verification code when this feature is enabled
testAddGetClientWrongCode :: Brig -> Galley -> Http ()
Expand All @@ -195,6 +199,9 @@ testAddGetClientWrongCode brig galley = do
const 403 === statusCode
const (Just "code-authentication-failed") === fmap Error.label . responseJsonMaybe

-- @END

-- @SF.Channel @TSFI.RESTfulAPI @S2
--
-- Test that device cannot be added with expired second factor email verification code when this feature is enabled
testAddGetClientCodeExpired :: DB.ClientState -> Opt.Opts -> Brig -> Galley -> Http ()
Expand All @@ -218,6 +225,8 @@ testAddGetClientCodeExpired db opts brig galley = do
const 403 === statusCode
const (Just "code-authentication-failed") === fmap Error.label . responseJsonMaybe

-- @END

data AddGetClient = AddGetClient
{ addWithPassword :: Bool,
addWithMLSKeys :: Bool
Expand Down Expand Up @@ -895,6 +904,7 @@ testMultiUserGetPrekeysQualifiedV4 brig opts = do
const (Right $ expectedUserClientMap) === responseJsonEither

-- The testTooManyClients test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- The test validates the upper bound on the number of permanent clients per
-- user. It does so by trying to create one permanent client more than allowed.
Expand Down Expand Up @@ -975,7 +985,10 @@ testRegularPrekeysCannotBeSentAsLastPrekeysDuringUpdate brig = do
!!! const 400
=== statusCode

-- @END

-- The testRemoveClient test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- This test validates creating and deleting a client. A client is created and
-- consequently deleted. Deleting a second time yields response 404 not found.
Expand Down Expand Up @@ -1021,7 +1034,10 @@ testRemoveClient hasPwd brig cannon = do
newClientCookie = Just defCookieLabel
}

-- @END

-- The testRemoveClientShortPwd test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- The test checks if a client can be deleted by providing a too short password.
-- This is done by using a single-character password, whereas the minimum is 6
Expand Down Expand Up @@ -1054,7 +1070,10 @@ testRemoveClientShortPwd brig = do
newClientCookie = Just defCookieLabel
}

-- @END

-- The testRemoveClientIncorrectPwd test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- The test checks if a client can be deleted by providing a syntax-valid, but
-- incorrect password. The client deletion attempt fails with a 403 error
Expand Down Expand Up @@ -1087,6 +1106,8 @@ testRemoveClientIncorrectPwd brig = do
newClientCookie = Just defCookieLabel
}

-- @END

testUpdateClient :: Opt.Opts -> Brig -> Http ()
testUpdateClient opts brig = do
uid <- userId <$> randomUser brig
Expand Down Expand Up @@ -1279,6 +1300,7 @@ testMissingClient brig = do
. responseHeaders

-- The testAddMultipleTemporary test conforms to the following testing standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
-- Legacy (galley)
--
-- Add temporary client, check that all services (both galley and
Expand Down Expand Up @@ -1336,6 +1358,8 @@ testAddMultipleTemporary brig galley cannon = do
. zUser u
pure $ Vec.length <$> (preview _Array =<< responseJsonMaybe @Value r)

-- @END

testPreKeyRace :: Brig -> Http ()
testPreKeyRace brig = do
uid <- userId <$> randomUser brig
Expand Down
3 changes: 3 additions & 0 deletions services/brig/test/integration/API/User/Handles.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ tests _cl _at conf p b c g =
]

-- The next line contains a mapping from the testHandleUpdate test to the following test standards:
-- @SF.Provisioning @TSFI.RESTfulAPI @S2
--
-- The test validates various updates to the user's handle. First, it attempts
-- to set invalid handles. This fails. Then it successfully sets a valid handle.
Expand Down Expand Up @@ -139,6 +140,8 @@ testHandleUpdate brig cannon = do
put (brig . path "/self/handle" . contentJson . zUser uid2 . zConn "c" . body update)
!!! const 200 === statusCode

-- @END

testHandleRace :: Brig -> Http ()
testHandleRace brig = do
us <- replicateM 10 (userId <$> randomUser brig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ spec env = do

it "testRejectRequestsWithoutClientCertIngress" (testRejectRequestsWithoutClientCertIngress env)

-- @SF.Federation @TSFI.RESTfulAPI @S2 @S3 @S7
--
-- This test was primarily intended to test that federator is using the API right (header
-- name etc.), but it is also effectively testing that federator rejects clients without
Expand Down Expand Up @@ -110,6 +111,8 @@ testRejectRequestsWithoutClientCertIngress env = runTestFederator env $ do
expectationFailure "Expected client certificate error, got remote error"
Left (RemoteErrorResponse _ _ status _) -> status `shouldBe` HTTP.status400

-- @END

liftToCodensity :: (Member (Embed (Codensity IO)) r) => Sem (Embed IO ': r) a -> Sem r a
liftToCodensity = runEmbedded @IO @(Codensity IO) lift

Expand Down
Loading
Loading