|
| 1 | +module Test.BlockedDomains where |
| 2 | + |
| 3 | +import API.Brig as Brig |
| 4 | +import API.Brig as BrigAddUser (AddUser (..)) |
| 5 | +import API.Common |
| 6 | +import Data.Yaml (array) |
| 7 | +import SetupHelpers |
| 8 | +import Testlib.Prelude |
| 9 | + |
| 10 | +testCannotSendActivationCodeToBlockedDomain :: (HasCallStack) => App () |
| 11 | +testCannotSendActivationCodeToBlockedDomain = do |
| 12 | + let blockedDomain = "blocked.example.com" |
| 13 | + validDomain = "valid.example.com" |
| 14 | + withModifiedBackend |
| 15 | + def |
| 16 | + { brigCfg = |
| 17 | + setField |
| 18 | + "optSettings.setCustomerExtensions.domainsBlockedForRegistration" |
| 19 | + (array [fromString blockedDomain]) |
| 20 | + } |
| 21 | + $ \domain -> do |
| 22 | + username <- randomName |
| 23 | + let validEmail = username <> "@" <> validDomain |
| 24 | + addUser domain def {BrigAddUser.email = Just validEmail} `bindResponse` \resp -> do |
| 25 | + resp.status `shouldMatchInt` 201 |
| 26 | + |
| 27 | + let blockedEmail = username <> "@" <> blockedDomain |
| 28 | + bindResponse (activateSend domain blockedEmail Nothing) $ \resp -> do |
| 29 | + resp.status `shouldMatchInt` 451 |
| 30 | + resp.json %. "label" `shouldMatch` "domain-blocked-for-registration" |
| 31 | + |
| 32 | + let otherValidEmail = username <> "-1@" <> validDomain |
| 33 | + activateSend domain otherValidEmail Nothing >>= assertSuccess |
| 34 | + |
| 35 | +testCannotChangeOwnEmailWithBlockedDomain :: (HasCallStack) => App () |
| 36 | +testCannotChangeOwnEmailWithBlockedDomain = do |
| 37 | + let blockedDomain = "blocked.example.com" |
| 38 | + validDomain = "valid.example.com" |
| 39 | + withModifiedBackend |
| 40 | + def |
| 41 | + { brigCfg = |
| 42 | + setField |
| 43 | + "optSettings.setCustomerExtensions.domainsBlockedForRegistration" |
| 44 | + (array [fromString blockedDomain]) |
| 45 | + } |
| 46 | + $ \domain -> do |
| 47 | + validUser <- randomUser domain def |
| 48 | + validUserEmail <- validUser %. "email" & asString |
| 49 | + (cookie, token) <- |
| 50 | + login domain validUserEmail defPassword `bindResponse` \resp -> do |
| 51 | + resp.status `shouldMatchInt` 200 |
| 52 | + token <- resp.json %. "access_token" & asString |
| 53 | + let cookie = fromJust $ getCookie "zuid" resp |
| 54 | + pure ("zuid=" <> cookie, token) |
| 55 | + |
| 56 | + username2 <- randomName |
| 57 | + bindResponse (putSelfEmail validUser cookie token (username2 <> "@" <> blockedDomain)) $ \resp -> do |
| 58 | + resp.status `shouldMatchInt` 451 |
| 59 | + resp.json %. "label" `shouldMatch` "domain-blocked-for-registration" |
| 60 | + |
| 61 | + putSelfEmail validUser cookie token (username2 <> "@" <> validDomain) >>= assertSuccess |
| 62 | + |
| 63 | +testCannotChangeTeamMemberEmailWithBlockedDomain :: (HasCallStack) => App () |
| 64 | +testCannotChangeTeamMemberEmailWithBlockedDomain = do |
| 65 | + let blockedDomain = "blocked.example.com" |
| 66 | + validDomain = "valid.example.com" |
| 67 | + withModifiedBackend |
| 68 | + def |
| 69 | + { brigCfg = |
| 70 | + setField |
| 71 | + "optSettings.setCustomerExtensions.domainsBlockedForRegistration" |
| 72 | + (array [fromString blockedDomain]) |
| 73 | + } |
| 74 | + $ \domain -> do |
| 75 | + (owner, _team, [mem1]) <- createTeam domain 2 |
| 76 | + |
| 77 | + username <- randomName |
| 78 | + bindResponse (putUserEmail owner mem1 (username <> "@" <> blockedDomain)) $ \resp -> do |
| 79 | + resp.status `shouldMatchInt` 451 |
| 80 | + resp.json %. "label" `shouldMatch` "domain-blocked-for-registration" |
| 81 | + |
| 82 | + putUserEmail owner mem1 (username <> "@" <> validDomain) >>= assertSuccess |
| 83 | + |
| 84 | + ownerUsername <- randomName |
| 85 | + bindResponse (putUserEmail owner owner (ownerUsername <> "@" <> blockedDomain)) $ \resp -> do |
| 86 | + resp.status `shouldMatchInt` 451 |
| 87 | + resp.json %. "label" `shouldMatch` "domain-blocked-for-registration" |
| 88 | + |
| 89 | + putUserEmail owner owner (ownerUsername <> "@" <> validDomain) >>= assertSuccess |
| 90 | + |
| 91 | +testCannotCreateTeamInvitationWithBlockedDomain :: (HasCallStack) => App () |
| 92 | +testCannotCreateTeamInvitationWithBlockedDomain = do |
| 93 | + let blockedDomain = "blocked.example.com" |
| 94 | + validDomain = "valid.example.com" |
| 95 | + withModifiedBackend |
| 96 | + def |
| 97 | + { brigCfg = |
| 98 | + setField |
| 99 | + "optSettings.setCustomerExtensions.domainsBlockedForRegistration" |
| 100 | + (array [fromString blockedDomain]) |
| 101 | + } |
| 102 | + $ \domain -> do |
| 103 | + (owner, _team, []) <- createTeam domain 1 |
| 104 | + |
| 105 | + username <- randomName |
| 106 | + bindResponse (postInvitation owner (PostInvitation (Just (username <> "@" <> blockedDomain)) Nothing)) |
| 107 | + $ \resp -> do |
| 108 | + resp.status `shouldMatchInt` 451 |
| 109 | + resp.json %. "label" `shouldMatch` "domain-blocked-for-registration" |
| 110 | + |
| 111 | + void $ postInvitation owner (PostInvitation (Just (username <> "@" <> validDomain)) Nothing) >>= getJSON 201 |
0 commit comments