python-scim / scim2-models

SCIM resources serialization and validation with Pydantic
https://scim2-models.readthedocs.io
Apache License 2.0
11 stars 2 forks source link

Do not restrict to canonical values #34

Open azmeuk opened 5 months ago

azmeuk commented 5 months ago

RFC7643 §2.3.1 indicates that string types with canonical values defined can or cannot have other values, depending on the server configuration:

   Additionally, when "canonicalValues"
   is specified, service providers MAY restrict accepted values to the
   specified values.

In §7 it is indicated that values can be ignored:


      canonicalValues  A collection of suggested canonical values that
         MAY be used (e.g., "work" and "home").  In some cases, service
         providers MAY choose to ignore unsupported values.  OPTIONAL.

Currently scim2_models defines custom enums, but that makes pydantic enforce those values only.

https://github.com/yaal-coop/scim2-models/blob/56287ad73027f6e6825d41e0b0c6ef0a339f4f18/scim2_models/rfc7643/user.py#L44-L48

https://github.com/yaal-coop/scim2-models/blob/56287ad73027f6e6825d41e0b0c6ef0a339f4f18/scim2_models/rfc7643/user.py#L56-L57

In that situation scim2-models should accept both arbitrary and enum values.

Also, when #6 is implemented, scim2-models should generate dynamic enums.

azmeuk commented 5 months ago

This test should pass:

def test_canonical_values():
    class Model(Resource):
        class Foo(str, Enum):
            bar = "bar"
            baz = "baz"

        schemas: List[str] = ["urn:example:2.0:Model"]
        foo: Optional[Foo]

    valid = Model(foo="bar")
    assert valid.foo == "bar"

    valid = Model(foo="invalid")
    assert valid.foo is None