Skip to content

Commit 9732876

Browse files
smattingfisx
andauthored
Accept any query string for externalId (#1330)
Co-authored-by: fisx <[email protected]>
1 parent ef1fed2 commit 9732876

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

services/spar/src/Spar/Scim/User.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ import Brig.Types.User (ManagedBy (..), Name (..), User (..))
4747
import qualified Brig.Types.User as BT
4848
import qualified Control.Applicative as Applicative (empty)
4949
import Control.Lens (view, (^.))
50-
import Control.Monad.Except (MonadError, throwError)
50+
import Control.Monad.Error.Class (MonadError)
51+
import Control.Monad.Except (runExceptT, throwError)
5152
import Control.Monad.Trans.Except (mapExceptT)
5253
import Control.Monad.Trans.Maybe (MaybeT (MaybeT), runMaybeT)
5354
import Crypto.Hash (Digest, SHA256, hashlazy)
@@ -765,7 +766,13 @@ scimFindUserByHandle mIdpConfig stiTeam hndl = do
765766
-- successful authentication with their SAML credentials.
766767
scimFindUserByEmail :: Maybe IdP -> TeamId -> Text -> MaybeT (Scim.ScimHandler Spar) (Scim.StoredUser ST.SparTag)
767768
scimFindUserByEmail mIdpConfig stiTeam email = do
768-
veid <- mkValidExternalId mIdpConfig (pure email)
769+
-- Azure has been observed to search for externalIds that are not emails, even if the
770+
-- mapping is set up like it should be. This is a problem: if there is no SAML IdP, 'mkValidExternalId'
771+
-- only supports external IDs that are emails. This is a missing feature / bug in spar tracked in
772+
-- https://wearezeta.atlassian.net/browse/SQSERVICES-157; once it is fixed, we should go back to
773+
-- throwing errors returned by 'mkValidExternalId' here, but *not* throw an error if the externalId is
774+
-- a UUID, or any other text that is valid according to SCIM.
775+
veid <- MaybeT (either (const Nothing) Just <$> runExceptT (mkValidExternalId mIdpConfig (pure email)))
769776
uid <- MaybeT . lift $ ST.runValidExternalId withUref withEmailOnly veid
770777
brigUser <- MaybeT . lift . Brig.getBrigUserAccount Brig.WithPendingInvitations $ uid
771778
guard $ userTeam (accountUser brigUser) == Just stiTeam

services/spar/test-integration/Test/Spar/Scim/UserSpec.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,12 +1565,26 @@ specDeleteUser = do
15651565

15661566
-- | Azure sends a request for an unknown user to test out whether your API is online However;
15671567
-- it sends a userName that is not a valid wire handle. So we should treat 'invalid' as 'not
1568-
-- found'.
1568+
-- found'. If we treat it as invalid Azure will put the scim provisioning into quarantine mode,
1569+
-- which requires manual intervention by the customer.
15691570
specAzureQuirks :: SpecWith TestEnv
15701571
specAzureQuirks = do
15711572
describe "Assert that we implement all azure quirks" $ do
1572-
it "GET /Users?filter=randomField eq <invalid value> should return empty list; not error out" $ do
1573-
(tok, (_, _, _)) <- registerIdPAndScimToken
1573+
context "with SAML IDP" $
1574+
it "GET /Users?filter=randomField eq <invalid value> should return empty list; not error out" $ do
1575+
(tok, (_, _, _)) <- registerIdPAndScimToken
1576+
testUUIds tok
1577+
1578+
context "without SAML IdP" $
1579+
it "GET /Users?filter=randomField eq <invalid value> should return empty list; not error out" $ do
1580+
env <- ask
1581+
let brig = env ^. teBrig
1582+
galley = env ^. teGalley
1583+
(_owner, tid) <- call $ createUserWithTeam brig galley
1584+
tok <- registerScimToken tid Nothing
1585+
testUUIds tok
1586+
where
1587+
testUUIds tok = do
15741588
users <- listUsers tok (Just (filterBy "userName" "f52dcb88-9fa1-4ec7-984f-7bc2d4046a9c"))
15751589
liftIO $ users `shouldBe` []
15761590
users' <- listUsers tok (Just (filterBy "externalId" "f52dcb88-9fa1-4ec7-984f-7bc2d4046a9c"))

0 commit comments

Comments
 (0)