Ejemplo n.º 1
0
 def test_multiple_saml_providers(self):
     """
     Test that get_users_by_external_keys returns the expected
     mapping of external keys to users when multiple saml providers
     are configured.
     """
     organization = OrganizationFactory.create(
         short_name=self.organization_key)
     provider_1 = SAMLProviderConfigFactory.create(
         organization=organization)
     provider_2 = SAMLProviderConfigFactory.create(
         organization=organization, slug='test-shib-2', enabled=True)
     self.create_social_auth_entry(self.user_0, provider_1, 'ext-user-0')
     self.create_social_auth_entry(self.user_1, provider_1, 'ext-user-1')
     self.create_social_auth_entry(self.user_1, provider_2, 'ext-user-1')
     self.create_social_auth_entry(self.user_2, provider_2, 'ext-user-2')
     requested_keys = {'ext-user-1', 'ext-user-2', 'ext-user-3'}
     actual = get_users_by_external_keys(self.program_uuid, requested_keys)
     # ext-user-0 not requested, ext-user-3 doesn't exist,
     # ext-user-2 is authorized with secondary provider
     # ext-user-1 has an entry in both providers
     expected = {
         'ext-user-1': self.user_1,
         'ext-user-2': self.user_2,
         'ext-user-3': None,
     }
     assert actual == expected
Ejemplo n.º 2
0
    def test_same_user_key_in_multiple_organizations(self):
        uox_program_enrollment = self._create_waiting_program_enrollment()

        second_organization = OrganizationFactory.create()
        SAMLProviderConfigFactory.create(organization=second_organization,
                                         slug='aiu')
        catalog_org = CatalogOrganizationFactory.create(
            key=second_organization.short_name)
        program_uuid = self._create_catalog_program(catalog_org)['uuid']

        # aiu enrollment with the same student key as our uox user
        aiu_program_enrollment = ProgramEnrollmentFactory.create(
            user=None,
            external_user_key=self.external_id,
            program_uuid=program_uuid)

        UserSocialAuth.objects.create(
            user=UserFactory.create(),
            uid='{0}:{1}'.format('not_used', self.external_id),
        )

        UserSocialAuth.objects.create(
            user=self.user,
            uid='{0}:{1}'.format(self.provider_slug, self.external_id),
        )
        self._assert_program_enrollment_user(uox_program_enrollment, self.user)

        aiu_user = UserFactory.create()
        UserSocialAuth.objects.create(
            user=aiu_user,
            uid='{0}:{1}'.format('aiu', self.external_id),
        )
        self._assert_program_enrollment_user(aiu_program_enrollment, aiu_user)
Ejemplo n.º 3
0
 def test_empty_request(self):
     """
     Test that requesting no external keys does not cause an exception.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     actual = get_users_by_external_keys(self.program_uuid, set())
     assert actual == {}
Ejemplo n.º 4
0
 def test_lms_organization_not_found(self):
     """
     Test an OrganizationDoesNotExistException is thrown if the LMS has no organization
     matching the catalog program's authoring_organization
     """
     organization = OrganizationFactory.create(short_name='some_other_org')
     SAMLProviderConfigFactory.create(organization=organization)
     with pytest.raises(OrganizationDoesNotExistException):
         get_users_by_external_keys(self.program_uuid, [])
Ejemplo n.º 5
0
    def setUp(self):
        super(TestRemoveSocialAuthUsersCommand, self).setUp()
        self.provider_hogwarts = SAMLProviderConfigFactory.create(slug='hogwarts')
        self.provider_durmstrang = SAMLProviderConfigFactory.create(slug='durmstrang')

        self.user_fleur = UserFactory(username='******')      # no social auth
        self.user_harry = UserFactory(username='******')      # social auth for Hogwarts
        self.user_viktor = UserFactory(username='******')    # social auth for Durmstrang

        self.create_social_auth_entry(self.user_harry, self.provider_hogwarts)
        self.create_social_auth_entry(self.user_viktor, self.provider_durmstrang)
Ejemplo n.º 6
0
 def test_extra_saml_provider_disabled(self):
     """
     If multiple samlprovider records exist with the same organization,
     but the extra record is disabled, no exception is raised.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     # create a second active config for the same organization, NOT enabled
     SAMLProviderConfigFactory.create(
         organization=organization, slug='foox', enabled=False
     )
     get_users_by_external_keys(self.program_uuid, [])
Ejemplo n.º 7
0
 def test_extra_saml_provider_enabled(self):
     """
     If multiple enabled samlprovider records exist with the same organization
     an exception is raised.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     # create a second active config for the same organizationm, IS enabled
     SAMLProviderConfigFactory.create(
         organization=organization, slug='foox', enabled=True
     )
     with self.assertRaises(ProviderConfigurationException):
         get_users_by_external_keys(self.program_uuid, [])
Ejemplo n.º 8
0
    def setUp(self):
        """
        Setup operations for saml configurations. these operations contain
        creation of SAMLConfiguration and SAMLProviderConfig records in database.
        """
        super().setUp()

        self.stdout = StringIO()

        # We are creating SAMLConfiguration instance here so that there is always at-least one
        # disabled saml configuration instance, this is done to verify that disabled configurations are
        # not processed.
        SAMLConfigurationFactory.create(enabled=False, site__domain='testserver.fake', site__name='testserver.fake')
        SAMLProviderConfigFactory.create(site__domain='testserver.fake', site__name='testserver.fake')
Ejemplo n.º 9
0
 def __create_saml_configurations__(self,
                                    saml_config=None,
                                    saml_provider_config=None):
     """
     Helper method to create SAMLConfiguration and AMLProviderConfig.
     """
     SAMLConfigurationFactory.create(enabled=True,
                                     **(saml_config or {
                                         'site__domain': 'testserver.fake',
                                         'site__name': 'testserver.fake'
                                     }))
     SAMLProviderConfigFactory.create(enabled=True,
                                      **(saml_provider_config or {
                                          'site__domain': 'testserver.fake',
                                          'site__name': 'testserver.fake'
                                      }))
Ejemplo n.º 10
0
 def test_create_social_auth_provider_has_no_organization(self):
     """
     No exceptions should be raised if provider is not linked to an organization
     """
     provider = SAMLProviderConfigFactory.create()
     UserSocialAuth.objects.create(
         user=self.user, uid=f'{provider.slug}:{self.external_id}')
Ejemplo n.º 11
0
    def setUpClass(cls):
        """
        Set up test data
        """
        super().setUpClass()
        catalog_org = CatalogOrganizationFactory.create(
            key=cls.organization_key)
        cls.program = ProgramFactory.create(
            uuid=cls.program_uuid, authoring_organizations=[catalog_org])
        organization = OrganizationFactory.create(
            short_name=cls.organization_key)
        SAMLProviderConfigFactory.create(organization=organization)

        catalog_course_id_str = 'course-v1:edX+ToyX'
        course_run_id_str = f'{catalog_course_id_str}+Toy_Course'
        cls.course_id = CourseKey.from_string(course_run_id_str)
        CourseOverviewFactory(id=cls.course_id)
        course_run = CourseRunFactory(key=course_run_id_str)
        cls.course = CourseFactory(key=catalog_course_id_str,
                                   course_runs=[course_run])
        cls.student_1 = UserFactory(username='******')
        cls.student_2 = UserFactory(username='******')
Ejemplo n.º 12
0
    def setUpClass(cls):
        super(SocialAuthEnrollmentCompletionSignalTest, cls).setUpClass()

        cls.external_id = '0000'
        cls.provider_slug = 'uox'
        cls.course_keys = [
            CourseKey.from_string('course-v1:edX+DemoX+Test_Course'),
            CourseKey.from_string('course-v1:edX+DemoX+Another_Test_Course'),
        ]
        cls.organization = OrganizationFactory.create(short_name='UoX')
        cls.user = UserFactory.create()

        for course_key in cls.course_keys:
            CourseOverviewFactory(id=course_key)
        cls.provider_config = SAMLProviderConfigFactory.create(
            organization=cls.organization, slug=cls.provider_slug)
Ejemplo n.º 13
0
 def test_happy_path(self):
     """
     Test that get_users_by_external_keys returns the expected
     mapping of external keys to users.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     provider = SAMLProviderConfigFactory.create(organization=organization)
     self.create_social_auth_entry(self.user_0, provider, 'ext-user-0')
     self.create_social_auth_entry(self.user_1, provider, 'ext-user-1')
     self.create_social_auth_entry(self.user_2, provider, 'ext-user-2')
     requested_keys = {'ext-user-1', 'ext-user-2', 'ext-user-3'}
     actual = get_users_by_external_keys(self.program_uuid, requested_keys)
     # ext-user-0 not requested, ext-user-3 doesn't exist
     expected = {
         'ext-user-1': self.user_1,
         'ext-user-2': self.user_2,
         'ext-user-3': None,
     }
     assert actual == expected