@@ -1061,15 +1061,14 @@ specCRUDIdentityProvider = do
10611061
10621062 describe " replaces an existing idp"
10631063 $ forM_
1064- [ (p, u, e)
1065- | p <- [False , True ], -- are users scim provisioned or via team management invitations?
1066- u <- [False , True ], -- do we use update-by-put or update-by-post? (see below)
1067- (p, u) /= (True , False ), -- scim doesn't not work with more than one idp (https://wearezeta.atlassian.net/browse/WPB-689)
1064+ [ (u, e)
1065+ | u <- [False , True ], -- do we use update-by-put or update-by-post? (see below)
10681066 e <- [False , True ] -- is the externalId an email address? (if not, it's a uuidv4, and the email address is stored in `emails`)
10691067 ]
1070- $ \ (provisionViaScim, updateNotReplace, externalIdIsEmail) -> do
1071- let updateOrReplaceIdps :: (TestEnv , UserId , IdP , SAML. IdPMetadata ) -> TestSpar ()
1072- updateOrReplaceIdps (env, owner1, idp1, idpmeta1) = do
1068+ $ \ (updateNotReplace, externalIdIsEmail) -> do
1069+ let updateOrReplaceIdps :: (UserId , IdP , SAML. IdPMetadata ) -> TestSpar ()
1070+ updateOrReplaceIdps (owner1, idp1, idpmeta1) = do
1071+ env <- ask
10731072 issuer2 <- makeIssuer
10741073 idp2 <- do
10751074 let idpmeta2 = idpmeta1 & edIssuer .~ issuer2
@@ -1117,65 +1116,67 @@ specCRUDIdentityProvider = do
11171116 . (idpExtraInfo . handle .~ (idp1 ^. idpExtraInfo . handle))
11181117 in erase idp1 `shouldBe` erase idp2
11191118
1120- it (" creates new idp, setting old_issuer; sets replaced_by in old idp; scim user search still works: provisionViaScim=" <> show provisionViaScim <> " , updateNotReplace=" <> show updateNotReplace <> " , externalIdIsEmail=" <> show externalIdIsEmail) $ do
1121- env <- ask
1122- (owner1, teamid, idp1, (IdPMetadataValue _ idpmeta1, privcreds)) <- registerTestIdPWithMeta
1119+ -- scim doesn't not work with more than one idp, so we can't test the post variant
1120+ -- that creates a second idp (https://wearezeta.atlassian.net/browse/WPB-689)
1121+ when updateNotReplace . it (" creates new idp, setting old_issuer; sets replaced_by in old idp; scim user search still works: provisionViaScim=True, updateNotReplace=" <> show updateNotReplace <> " , externalIdIsEmail=" <> show externalIdIsEmail) $ do
1122+ (owner1, teamid, idp1, (IdPMetadataValue _ idpmeta1, _)) <- registerTestIdPWithMeta
11231123 let idp1id = idp1 ^. idpId
11241124
1125- (tok, userStuff) :: (ScimToken , Either (UserId , Maybe Text , Text ) (Scim. StoredUser SparTag , Scim. User SparTag )) <- do
1126- if provisionViaScim
1127- then do
1128- tok <- registerScimToken teamid (Just idp1id )
1129- user <-
1130- if externalIdIsEmail
1131- then fst <$> randomScimUserWithEmail
1132- else fst <$> randomScimUserWithNick
1133- scimStoredUser <- createUser tok user
1134- pure (tok, Right (scimStoredUser, user))
1135- else do
1136- stuff <- do
1137- spmeta <- getTestSPMetadata teamid
1138- authnreq <- negotiateAuthnRequest idp1
1139- authnresp <- runSimpleSP $ mkAuthnResponse privcreds idp1 spmeta authnreq True
1140- sparresp <- submitAuthnResponse teamid authnresp
1141- liftIO $ statusCode sparresp `shouldBe` 200
1142- ssoid <- getSsoidViaAuthResp authnresp
1143- Just uid <- ssoToUidSpar teamid ssoid
1144- setRandomHandleBrig uid
1145- Just usr <- getUserBrig uid
1146- let eml = fromEmail <$> (emailIdentity =<< userIdentity usr)
1147- Just hdl = fromHandle <$> userHandle usr
1148- pure (uid, eml, hdl)
1149-
1150- tok <- registerScimToken teamid (Just idp1id )
1151- pure (tok, Left stuff)
1125+ tok <- registerScimToken teamid (Just idp1id )
1126+ scimUser <-
1127+ if externalIdIsEmail
1128+ then fst <$> randomScimUserWithEmail
1129+ else fst <$> randomScimUserWithNick
1130+ scimStoredUser <- createUser tok scimUser
11521131
11531132 let checkScimSearch ::
11541133 HasCallStack =>
1155- Either (UserId , Maybe Text , Text ) (Scim. StoredUser SparTag , Scim. User SparTag ) ->
1134+ Scim. StoredUser SparTag ->
1135+ Scim. User SparTag ->
11561136 ReaderT TestEnv IO ()
1157- -- search users provisioned by scim
1158- checkScimSearch (Right (target, searchKeys)) = do
1137+ checkScimSearch target searchKeys = do
11591138 let Just externalId = Scim. externalId searchKeys
11601139 handle' = Scim. userName searchKeys
11611140 respId <- listUsers tok (Just (filterBy " externalId" externalId))
11621141 respHandle <- listUsers tok (Just (filterBy " userName" handle'))
11631142 liftIO $ do
11641143 respId `shouldBe` [target]
11651144 respHandle `shouldBe` [target]
1166- -- search users provisioned by saml
1167- checkScimSearch (Left (uid, mbEmail, hdl)) = do
1168- respHandle <- listUsers tok (Just (filterBy " userName" hdl))
1169- liftIO $ ((Scim. id . Scim. thing) <$> respHandle) `shouldBe` [uid]
1170- (`mapM_` mbEmail) $ \ eml -> do
1171- respId <- listUsers tok (Just (filterBy " externalId" eml))
1172- liftIO $ ((Scim. id . Scim. thing) <$> respId) `shouldBe` [uid]
1173-
1174- -- if user is created via saml, don't do anything here until we have updated the idp
1175- -- to make things more interesting.
1176- either (const $ pure () ) (checkScimSearch . Right ) userStuff
1177- updateOrReplaceIdps (env, owner1, idp1, idpmeta1)
1178- checkScimSearch userStuff
1145+
1146+ checkScimSearch scimStoredUser scimUser
1147+ updateOrReplaceIdps (owner1, idp1, idpmeta1)
1148+ checkScimSearch scimStoredUser scimUser
1149+
1150+ it (" creates new idp, setting old_issuer; sets replaced_by in old idp; scim user search still works: provisionViaScim=False, updateNotReplace=" <> show updateNotReplace <> " , externalIdIsEmail=" <> show externalIdIsEmail) $ do
1151+ (owner1, teamid, idp1, (IdPMetadataValue _ idpmeta1, privcreds)) <- registerTestIdPWithMeta
1152+ let idp1id = idp1 ^. idpId
1153+
1154+ (uid, mbEmail, hdl) :: (UserId , Maybe Text , Text ) <- do
1155+ spmeta <- getTestSPMetadata teamid
1156+ authnreq <- negotiateAuthnRequest idp1
1157+ authnresp <- runSimpleSP $ mkAuthnResponse privcreds idp1 spmeta authnreq True
1158+ sparresp <- submitAuthnResponse teamid authnresp
1159+ liftIO $ statusCode sparresp `shouldBe` 200
1160+ ssoid <- getSsoidViaAuthResp authnresp
1161+ Just uid <- ssoToUidSpar teamid ssoid
1162+ setRandomHandleBrig uid
1163+ Just usr <- getUserBrig uid
1164+ let eml = fromEmail <$> (emailIdentity =<< userIdentity usr)
1165+ Just hdl = fromHandle <$> userHandle usr
1166+ pure (uid, eml, hdl)
1167+
1168+ -- if user is created via saml, don't call checkScimSearch here until we have
1169+ -- updated the idp; otherwise, the interesting second call would only find a
1170+ -- scim-imported user and this test would be redundant..
1171+ updateOrReplaceIdps (owner1, idp1, idpmeta1)
1172+
1173+ -- checkScimSearch
1174+ tok <- registerScimToken teamid (Just idp1id )
1175+ respHandle <- listUsers tok (Just (filterBy " userName" hdl))
1176+ liftIO $ ((Scim. id . Scim. thing) <$> respHandle) `shouldBe` [uid]
1177+ (`mapM_` mbEmail) $ \ eml -> do
1178+ respId <- listUsers tok (Just (filterBy " externalId" eml))
1179+ liftIO $ ((Scim. id . Scim. thing) <$> respId) `shouldBe` [uid]
11791180
11801181 describe " replaces an existing idp (cont.)" $ do
11811182 it " users can still login on old idp as before" $ do
0 commit comments