Esempio n. 1
0
    def test_eduid_invite_mail(self):
        expires_at = datetime.utcnow() + timedelta(days=180)
        discard_at = expires_at + timedelta(days=7)
        sender_info = SenderInfo(hostname='testhost',
                                 node_id='userdb@testhost')
        payload = EduidInviteEmail(
            email='*****@*****.**',
            reference='ref_id',
            invite_link='https://signup.example.com/abc123',
            invite_code='abc123',
            inviter_name='Test Application',
            language='sv',
        )
        item = QueueItem(
            version=1,
            expires_at=expires_at,
            discard_at=discard_at,
            sender_info=sender_info,
            payload_type=payload.get_type(),
            payload=payload,
        )

        loaded_message_dict = QueueItem.from_dict(item.to_dict()).to_dict()
        assert normalised_data(
            item.to_dict()) == normalised_data(loaded_message_dict)
        assert normalised_data(payload.to_dict()) == normalised_data(
            item.payload.to_dict())
Esempio n. 2
0
    def test_save_load(self):
        payload = TestPayload(message='this is a test payload')
        item = self._create_queue_item(payload)
        self.messagedb.save(item)
        assert 1 == self.messagedb.db_count()

        loaded_item = self.messagedb.get_item_by_id(item.item_id)
        assert loaded_item.payload_type == payload.get_type()
        assert isinstance(loaded_item.payload, TestPayload) is True
        assert normalised_data(item.to_dict()) == normalised_data(
            loaded_item.to_dict())
Esempio n. 3
0
 def test_meta(self) -> None:
     meta = Meta(
         location='http://example.org/group/some-id',
         resource_type=SCIMResourceType.GROUP,
         created=datetime.utcnow(),
         last_modified=datetime.utcnow(),
         version=ObjectId(),
     )
     schema = class_schema(Meta)
     meta_dump = schema().dump(meta)
     loaded_meta = schema().load(meta_dump)
     assert normalised_data(asdict(meta)) == normalised_data(
         asdict(loaded_meta))
Esempio n. 4
0
    def _assertUserUpdateSuccess(self, req: Mapping, response,
                                 user: ScimApiUser):
        """ Function to validate successful responses to SCIM calls that update a user according to a request. """

        if response.json.get('schemas') == [SCIMSchema.ERROR.value]:
            self.fail(
                f'Got SCIM error response ({response.status}):\n{response.json}'
            )

        expected_schemas = req.get('schemas', [SCIMSchema.CORE_20_USER.value])
        if SCIMSchema.NUTID_USER_V1.value in response.json and SCIMSchema.NUTID_USER_V1.value not in expected_schemas:
            # The API can always add this extension to the response, even if it was not in the request
            expected_schemas += [SCIMSchema.NUTID_USER_V1.value]

        self._assertScimResponseProperties(response,
                                           resource=user,
                                           expected_schemas=expected_schemas)

        # Validate user update specifics
        assert user.external_id == response.json.get(
            'externalId'), 'user.externalId != response.json.get("externalId")'
        self._assertName(user.name, response.json.get('name'))
        _expected_emails = filter_none(
            normalised_data([email.to_dict() for email in user.emails]))
        _obtained_emails = filter_none(
            normalised_data(response.json.get('emails', [])))
        assert _obtained_emails == _expected_emails, 'response.json.get("email") != user.emails'
        _expected_phones = filter_none(
            normalised_data(
                [number.to_dict() for number in user.phone_numbers]))
        _obtained_phones = filter_none(
            normalised_data(response.json.get('phoneNumbers', [])))
        assert _obtained_phones == _expected_phones, 'response.json.get("phoneNumbers") != user.phone_numbers'
        assert user.preferred_language == response.json.get(
            'preferredLanguage'
        ), 'user.preferred_language != response.json.get("preferredLanguage")'

        # If the request has NUTID profiles, ensure they are present in the response
        if SCIMSchema.NUTID_USER_V1.value in req:
            req_nutid = req[SCIMSchema.NUTID_USER_V1.value]
            resp_nutid = response.json.get(SCIMSchema.NUTID_USER_V1.value)
            self.assertEqual(
                req_nutid,
                resp_nutid,
                'Unexpected NUTID user data in response',
            )
        elif SCIMSchema.NUTID_USER_V1.value in response.json:
            self.fail(
                f'Unexpected {SCIMSchema.NUTID_USER_V1.value} in the response')
Esempio n. 5
0
 def test_base_response(self) -> None:
     meta = Meta(
         location='http://example.org/group/some-id',
         resource_type=SCIMResourceType.GROUP,
         created=datetime.utcnow(),
         last_modified=datetime.utcnow(),
         version=ObjectId(),
     )
     base = BaseResponse(
         id=uuid4(),
         schemas=[SCIMSchema.CORE_20_USER, SCIMSchema.CORE_20_GROUP],
         meta=meta)
     schema = class_schema(BaseResponse)
     base_dump = schema().dump(base)
     loaded_base = schema().load(base_dump)
     assert normalised_data(asdict(base)) == normalised_data(
         asdict(loaded_base))
Esempio n. 6
0
    def test_save_load_eduid_email_invite(self):
        payload = EduidInviteEmail(
            email='*****@*****.**',
            reference='ref_id',
            invite_link='https://signup.example.com/abc123',
            invite_code='abc123',
            inviter_name='Test Application',
            language='sv',
        )
        item = self._create_queue_item(payload)
        self.messagedb.save(item)
        assert 1 == self.messagedb.db_count()

        loaded_item = self.messagedb.get_item_by_id(item.item_id)
        assert normalised_data(item.to_dict()) == normalised_data(
            loaded_item.to_dict())
        assert normalised_data(item.payload.to_dict()), normalised_data(
            loaded_item.payload.to_dict())
Esempio n. 7
0
 def test_queue_item(self):
     expires_at = datetime.utcnow() + timedelta(days=180)
     discard_at = expires_at + timedelta(days=7)
     sender_info = SenderInfo(hostname='testhost',
                              node_id='userdb@testhost')
     payload = TestPayload(message='this is a test payload')
     item = QueueItem(
         version=1,
         expires_at=expires_at,
         discard_at=discard_at,
         sender_info=sender_info,
         payload_type=payload.get_type(),
         payload=payload,
     )
     loaded_message_dict = QueueItem.from_dict(item.to_dict()).to_dict()
     assert normalised_data(
         item.to_dict()) == normalised_data(loaded_message_dict)
     assert normalised_data(payload.to_dict()) == normalised_data(
         item.payload.to_dict())
Esempio n. 8
0
 def test_group(self) -> None:
     schema = class_schema(GroupResponse, base_schema=BaseSchema)
     group = GroupResponse(id=uuid4(),
                           schemas=[SCIMSchema.CORE_20_GROUP],
                           meta=self.meta,
                           display_name='Test Group')
     member_1_id = uuid4()
     member_2_id = uuid4()
     group.members.extend([
         GroupMember(value=member_1_id,
                     display='Member 1',
                     ref=f'https://some_domain/path/Users/{member_1_id}'),
         GroupMember(value=member_2_id,
                     display='Member 2',
                     ref=f'https://some_domain/path/Groups/{member_2_id}'),
     ])
     group_dump = schema().dump(group)
     loaded_group = schema().load(group_dump)
     assert normalised_data(asdict(group)) == normalised_data(
         asdict(loaded_group))