-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize scim data before responding to
POST /scim/v2/Users
.
- Loading branch information
Showing
6 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,17 +68,20 @@ import Imports | |
import qualified SAML2.WebSSO as SAML | ||
import SAML2.WebSSO.Test.Arbitrary () | ||
import Servant.API (FromHttpApiData (..), ToHttpApiData (..)) | ||
import qualified Test.QuickCheck as QC | ||
import Web.HttpApiData (parseHeaderWithPrefix) | ||
import Web.Scim.AttrName (AttrName (..)) | ||
import qualified Web.Scim.Class.Auth as Scim.Auth | ||
import qualified Web.Scim.Class.Group as Scim.Group | ||
import qualified Web.Scim.Class.User as Scim.User | ||
import Web.Scim.Filter (AttrPath (..)) | ||
import qualified Web.Scim.Schema.Common as Scim | ||
import qualified Web.Scim.Schema.Error as Scim | ||
import Web.Scim.Schema.PatchOp (Operation (..), Path (NormalPath)) | ||
import qualified Web.Scim.Schema.PatchOp as Scim | ||
import Web.Scim.Schema.Schema (Schema (CustomSchema)) | ||
import qualified Web.Scim.Schema.Schema as Scim | ||
import qualified Web.Scim.Schema.User as Scim | ||
import qualified Web.Scim.Schema.User as Scim.User | ||
import Wire.API.User.Identity (Email) | ||
import Wire.API.User.Profile as BT | ||
|
@@ -238,6 +241,41 @@ instance A.FromJSON ScimUserExtra where | |
instance A.ToJSON ScimUserExtra where | ||
toJSON (ScimUserExtra rif) = A.toJSON rif | ||
|
||
instance QC.Arbitrary ScimUserExtra where | ||
arbitrary = ScimUserExtra <$> QC.arbitrary | ||
|
||
instance QC.Arbitrary (RI.WithNormalizedRichFields ScimUserExtra) where | ||
arbitrary = do | ||
RI.WithNormalizedRichFields ri <- QC.arbitrary | ||
pure . RI.WithNormalizedRichFields . ScimUserExtra $ ri | ||
|
||
instance QC.Arbitrary (RI.WithNormalizedRichFields (Scim.User SparTag)) where | ||
arbitrary = | ||
RI.WithNormalizedRichFields <$> (addFields =<< (Scim.empty <$> genSchemas <*> genUserName <*> genExtra)) | ||
where | ||
addFields :: Scim.User.User tag -> QC.Gen (Scim.User.User tag) | ||
addFields usr = do | ||
gexternalId <- cs . QC.getPrintableString <$$> QC.arbitrary | ||
gdisplayName <- cs . QC.getPrintableString <$$> QC.arbitrary | ||
gactive <- Scim.ScimBool <$$> QC.arbitrary | ||
gemails <- catMaybes <$> (A.decode <$$> QC.listOf (QC.elements ["[email protected]", "x@y,z", "[email protected]"])) | ||
pure | ||
usr | ||
{ Scim.User.externalId = gexternalId, | ||
Scim.User.displayName = gdisplayName, | ||
Scim.User.active = gactive, | ||
Scim.User.emails = gemails | ||
} | ||
|
||
genSchemas :: QC.Gen [Scim.Schema] | ||
genSchemas = QC.listOf1 $ QC.elements Scim.fakeEnumSchema | ||
|
||
genUserName :: QC.Gen Text | ||
genUserName = cs . QC.getPrintableString <$> QC.arbitrary | ||
|
||
genExtra :: QC.Gen ScimUserExtra | ||
genExtra = RI.fromWithNormalizedRichFields <$> QC.arbitrary | ||
|
||
instance Scim.Patchable ScimUserExtra where | ||
applyOperation (ScimUserExtra (RI.RichInfo rinfRaw)) (Operation o (Just (NormalPath (AttrPath (Just (CustomSchema sch)) (AttrName (CI.mk -> ciAttrName)) Nothing))) val) | ||
| sch == RI.richInfoMapURN = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters