Skip to content

Commit 63c5b7d

Browse files
committed
Lower SCIM-users-only constraint for /sso/get-by-email
1 parent 1ef73af commit 63c5b7d

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

integration/test/Test/Spar/MultiIngressCrossIdpSso.hs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Test.Spar.MultiIngressCrossIdpSso where
2020
import API.BrigInternal (getUsersId)
2121
import API.Common (randomEmail)
2222
import API.GalleyInternal (setTeamFeatureStatus)
23-
import API.Spar (createIdpWithZHostV2)
23+
import API.Spar (createIdpWithZHostV2, getSsoCodeByEmailWithZHost)
2424
import Data.List.NonEmpty (NonEmpty ((:|)))
2525
import Data.Text (pack)
2626
import GHC.Stack
@@ -90,6 +90,7 @@ testCrossIdpSsoCreatesDistinctUsers = do
9090
]
9191
]
9292
)
93+
>=> setField "enableIdPByEmailDiscovery" True
9394
}
9495
$ \domain -> do
9596
-- Create team and enable SSO
@@ -252,6 +253,7 @@ testCrossIdpSsoEmailConflict = do
252253
]
253254
]
254255
)
256+
>=> setField "enableIdPByEmailDiscovery" True
255257
}
256258
$ \domain -> do
257259
-- Create team and enable SSO
@@ -301,6 +303,12 @@ testCrossIdpSsoEmailConflict = do
301303
ssoIdTenant `shouldContain` ernieIssuer
302304
ssoIdTenant `shouldNotMatch` bertIssuer
303305

306+
-- Verify sso/get-by-email returns Ernie's IdP
307+
getSsoCodeByEmailWithZHost domain (Just ernieZHost) biboEmail `bindResponse` \resp -> do
308+
resp.status `shouldMatchInt` 200
309+
ssoCodeStr <- resp.json %. "sso_code" >>= asString
310+
ssoCodeStr `shouldMatch` idpId1
311+
304312
-- Step 1.5: Bibo re-logs in on Ernie (should succeed - proves SSO works on same ingress)
305313
(mUserIdErnieAgain, _) <-
306314
loginWithSamlWithZHost
@@ -342,6 +350,12 @@ testCrossIdpSsoEmailConflict = do
342350
ssoIdTenant `shouldContain` bertIssuer
343351
ssoIdTenant `shouldNotMatch` ernieIssuer
344352

353+
-- Verify sso/get-by-email returns Bert's IdP after migration
354+
getSsoCodeByEmailWithZHost domain (Just bertZHost) biboEmail `bindResponse` \resp -> do
355+
resp.status `shouldMatchInt` 200
356+
ssoCodeStr <- resp.json %. "sso_code" >>= asString
357+
ssoCodeStr `shouldMatch` idpId2
358+
345359
-- Step 3: Login on Ernie again to show back-and-forth migration works
346360
(mUserIdErnieFinal, _) <-
347361
loginWithSamlWithZHost
@@ -365,3 +379,9 @@ testCrossIdpSsoEmailConflict = do
365379
bertIssuer <- _idp2.json %. "metadata.issuer" >>= asString
366380
ssoIdTenant `shouldContain` ernieIssuer
367381
ssoIdTenant `shouldNotMatch` bertIssuer
382+
383+
-- Verify sso/get-by-email returns Ernie's IdP after migration back
384+
getSsoCodeByEmailWithZHost domain (Just ernieZHost) biboEmail `bindResponse` \resp -> do
385+
resp.status `shouldMatchInt` 200
386+
ssoCodeStr <- resp.json %. "sso_code" >>= asString
387+
ssoCodeStr `shouldMatch` idpId1

libs/wire-subsystems/src/Wire/IdPSubsystem/Interpreter.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ getSsoCodeByEmailImpl enableIdPByEmailDiscovery mbHost email =
123123

124124
isScimOrSsoUser :: User -> Bool
125125
isScimOrSsoUser user =
126-
userManagedBy user == ManagedByScim && isJust (userSSOId user)
126+
-- TODO: This used to check if the user is SCIM AND SSO! The RFC not
127+
-- really unambiguous about this. The customer currently provisions
128+
-- non-SCIM. So, that would fit. However, this change needs a sing-off by
129+
-- security.
130+
isJust (userSSOId user)
127131

128132
findIdPByDomain :: (Member (Logger (Log.Msg -> Log.Msg)) r) => [IP.IdP] -> Sem r (Maybe SAML.IdPId)
129133
findIdPByDomain idps = do

libs/wire-subsystems/test/unit/Wire/IdPSubsystem/InterpreterSpec.hs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import System.Logger.Message qualified as Log
3737
import Test.Hspec
3838
import Test.Hspec.QuickCheck
3939
import Test.QuickCheck
40-
import Test.QuickCheck.Gen
4140
import Wire.API.Team.Member
4241
import Wire.API.User
4342
import Wire.API.User.IdentityProvider
@@ -313,19 +312,12 @@ spec = describe "IdPSubsystem.Interpreter" $ do
313312
result `shouldBe` Right Nothing
314313
expectedSevereLogs logs mempty
315314

316-
prop "returns Nothing for non SCIM/SSO user" $ \(teamMember :: TeamMember) user idp userRef email teamId -> do
317-
(userIdentity, userManagedBy) <-
318-
generate $
319-
( do
320-
ui <- Test.QuickCheck.Gen.elements [Just (SSOIdentity (UserSSOId userRef) (Just email)), Nothing]
321-
mngtBy :: ManagedBy <- arbitrary
322-
pure (ui, mngtBy)
323-
)
324-
`suchThat` (\(ui, mngtBy) -> isNothing ui || mngtBy == ManagedByWire)
315+
prop "returns Nothing for non SSO user" $ \(teamMember :: TeamMember) user idp email teamId -> do
316+
userManagedBy <- generate (arbitrary :: Gen ManagedBy)
325317

326318
let userWithEmail =
327319
user
328-
{ userIdentity = userIdentity,
320+
{ userIdentity = Nothing, -- No SSO identity
329321
userEmailUnvalidated = Just email,
330322
userTeam = Just teamId,
331323
userManagedBy = userManagedBy

0 commit comments

Comments
 (0)