Skip to content

Commit f88dea5

Browse files
committed
WPB-23434: Expect echoed SCIM email type "work" in tests
Follow-up to 1406a78 (synthesizeScimUser now echoes type = Just "work" instead of Nothing): update all SCIM email test-expectations to expect type = "work", since every GET/PUT/PATCH response now materializes it. integration framework (Test/Spar.hs): add a scimWorkEmail helper and route the 13 full-email-object assertions/inputs that compare to a response through it. PUT inputs never round-tripped to a response are left typeless, preserving coverage that the server synthesizes the type when omitted. spar test-integration: flip the two expected-email constructions (Util/Scim.hs setDefaultRoleAndEmailsIfEmpty, APISpec.hs scim-user-search) from Nothing to Just "work". Test-only; no production code.
1 parent b3dcbf6 commit f88dea5

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

integration/test/Test/Spar.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,11 @@ testSparMigrateFromExternalIdOnlyToEmail (MkTagged emailUnchanged) = do
526526

527527
-- Verify that updating a user with an empty emails does not change the email
528528
bindResponse (updateScimUser OwnDomain tok userId scimUser) $ \resp -> do
529-
resp.json %. "emails" `shouldMatch` (toJSON [object ["value" .= email]])
529+
resp.json %. "emails" `shouldMatch` (toJSON [scimWorkEmail email])
530530
resp.status `shouldMatchInt` 200
531531

532532
newEmail <- if emailUnchanged then pure email else randomEmail
533-
let newEmails = (toJSON [object ["value" .= newEmail]])
533+
let newEmails = toJSON [scimWorkEmail newEmail]
534534
updatedScimUser <- setField "emails" newEmails scimUser
535535
updateScimUser OwnDomain tok userId updatedScimUser `bindResponse` \resp -> do
536536
resp.status `shouldMatchInt` 200
@@ -562,6 +562,12 @@ checkSparGetUserAndFindByExtId domain tok extId uid k = do
562562

563563
userByUid `shouldMatch` userByIdExtId
564564

565+
-- | Expected SCIM email object. spar synthesizes @type = "work"@ on every stored
566+
-- email (see 'Spar.Scim.User.synthesizeScimUser'), so assertions comparing the
567+
-- server's @emails@ must expect it.
568+
scimWorkEmail :: String -> Value
569+
scimWorkEmail addr = object ["type" .= ("work" :: String), "value" .= addr]
570+
565571
testSparScimTokenLimit :: (HasCallStack) => App ()
566572
testSparScimTokenLimit = withModifiedBackend
567573
def
@@ -1247,7 +1253,7 @@ testScimUpdateEmailAddress (TaggedBool extIdIsEmail) (TaggedBool requireExternal
12471253
res.json %. "id" `shouldMatch` uid
12481254
lookupField res.json "emails"
12491255
`shouldMatch` ( if extIdIsEmail
1250-
then Just [object ["value" .= oldEmail]]
1256+
then Just [scimWorkEmail oldEmail]
12511257
else Nothing
12521258
)
12531259

@@ -1266,11 +1272,11 @@ testScimUpdateEmailAddress (TaggedBool extIdIsEmail) (TaggedBool requireExternal
12661272

12671273
updateScimUser OwnDomain tok uid newScimUser `bindResponse` \res -> do
12681274
res.status `shouldMatchInt` 200
1269-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail]]
1275+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail]
12701276

12711277
getScimUser OwnDomain tok uid `bindResponse` \res -> do
12721278
res.status `shouldMatchInt` 200
1273-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail]]
1279+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail]
12741280

12751281
when requireExternalEmailVerification $ do
12761282
getUsersId OwnDomain [uid] `bindResponse` \res -> do
@@ -1334,7 +1340,7 @@ testScimUpdateEmailAddressAndExternalId = do
13341340
getScimUser OwnDomain tok brigUserId `bindResponse` \res -> do
13351341
res.status `shouldMatchInt` 200
13361342
res.json %. "id" `shouldMatch` brigUserId
1337-
res.json %. "emails" `shouldMatch` [object ["value" .= extId1]]
1343+
res.json %. "emails" `shouldMatch` [scimWorkEmail extId1]
13381344

13391345
findUsersByExternalId OwnDomain tok extId1 `bindResponse` \res -> do
13401346
res.status `shouldMatchInt` 200
@@ -1357,11 +1363,11 @@ testScimUpdateEmailAddressAndExternalId = do
13571363
updateScimUser OwnDomain tok brigUserId newScimUser1 `bindResponse` \res -> do
13581364
res.status `shouldMatchInt` 200
13591365
res.json %. "externalId" `shouldMatch` extId1
1360-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1366+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
13611367

13621368
getScimUser OwnDomain tok brigUserId `bindResponse` \res -> do
13631369
res.status `shouldMatchInt` 200
1364-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1370+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
13651371

13661372
findUsersByExternalId OwnDomain tok extId1 `bindResponse` \res -> do
13671373
res.status `shouldMatchInt` 200
@@ -1390,11 +1396,11 @@ testScimUpdateEmailAddressAndExternalId = do
13901396
updateScimUser OwnDomain tok brigUserId newScimUser2 `bindResponse` \res -> do
13911397
res.status `shouldMatchInt` 200
13921398
res.json %. "externalId" `shouldMatch` newExtId2
1393-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1399+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
13941400

13951401
getScimUser OwnDomain tok brigUserId `bindResponse` \res -> do
13961402
res.status `shouldMatchInt` 200
1397-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1403+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
13981404

13991405
findUsersByExternalId OwnDomain tok newExtId2 `bindResponse` \res -> do
14001406
res.status `shouldMatchInt` 200
@@ -1423,11 +1429,11 @@ testScimUpdateEmailAddressAndExternalId = do
14231429
updateScimUser OwnDomain tok brigUserId newScimUser3 `bindResponse` \res -> do
14241430
res.status `shouldMatchInt` 200
14251431
res.json %. "externalId" `shouldMatch` newEmail3
1426-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1432+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
14271433

14281434
getScimUser OwnDomain tok brigUserId `bindResponse` \res -> do
14291435
res.status `shouldMatchInt` 200
1430-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail1]]
1436+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail1]
14311437

14321438
findUsersByExternalId OwnDomain tok newEmail3 `bindResponse` \res -> do
14331439
res.status `shouldMatchInt` 200
@@ -1639,7 +1645,7 @@ testAllowUpdatesBySCIMWhenE2EIdEnabled (TaggedBool ssoEnabled) = do
16391645
su <- setField "emails" [object ["value" .= newEmail]] scimUser
16401646
bindResponse (updateScimUser OwnDomain tok uid su) $ \res -> do
16411647
res.status `shouldMatchInt` 200
1642-
res.json %. "emails" `shouldMatch` [object ["value" .= newEmail]]
1648+
res.json %. "emails" `shouldMatch` [scimWorkEmail newEmail]
16431649
activateEmail OwnDomain newEmail
16441650
bindResponse (getUsersId OwnDomain [uid]) $ \res -> do
16451651
res.status `shouldMatchInt` 200

services/spar/test-integration/Test/Spar/APISpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ specCRUDIdentityProvider = do
10681068
-- if the externalId is an email, and the email field was
10691069
-- empty, the scim response from spar contains the externalId
10701070
-- (parsed) in the emails field.
1071-
Just e -> u {Scim.emails = [Scim.Email Nothing (Scim.EmailAddress e) Nothing]}
1071+
Just e -> u {Scim.emails = [Scim.Email (Just "work") (Scim.EmailAddress e) Nothing]}
10721072
Nothing -> u
10731073
in -- don't compare meta, or you need to update the ETag in version because email may have changed.
10741074
Scim.WithId i u'

services/spar/test-integration/Util/Scim.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ setDefaultRoleAndEmailsIfEmpty u =
739739
xs -> xs,
740740
-- when the emails field is empty, we try to populate it with the externalId
741741
Scim.User.emails = case Scim.User.emails u of
742-
[] -> maybeToList ((\e -> Scim.Email.Email Nothing (Scim.Email.EmailAddress e) Nothing) <$> (emailAddressText =<< (Scim.User.externalId u)))
742+
[] -> maybeToList ((\e -> Scim.Email.Email (Just "work") (Scim.Email.EmailAddress e) Nothing) <$> (emailAddressText =<< (Scim.User.externalId u)))
743743
xs -> xs
744744
}
745745

0 commit comments

Comments
 (0)