Пример #1
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)
Пример #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)
Пример #3
0
    def test_multiple_saml_providers(self, second_config_enabled):
        """
        If multiple samlprovider records exist with the same organization
        an exception is raised
        """
        organization = OrganizationFactory.create(
            short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)

        self.create_social_auth_entry(self.user, provider,
                                      self.external_user_id)

        # create a second active config for the same organization
        SAMLProviderConfigFactory.create(organization=organization,
                                         slug='foox',
                                         enabled=second_config_enabled)

        try:
            get_user_by_program_id(self.external_user_id, self.program_uuid)
        except ProviderConfigurationException:
            self.assertTrue(second_config_enabled,
                            'Unexpected error when second config is disabled')
        else:
            self.assertFalse(
                second_config_enabled,
                'Expected error was not raised when second config is enabled')
Пример #4
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 == {}
Пример #5
0
    def test_social_auth_user_not_created(self):
        """
        None should be returned if no lms user exists for an external id
        """
        organization = OrganizationFactory.create(short_name=self.organization_key)
        SAMLProviderConfigFactory.create(organization=organization)

        user = get_user_by_program_id(self.external_user_id, self.program_uuid)
        self.assertIsNone(user)
Пример #6
0
    def test_social_auth_user_not_created(self):
        """
        None should be returned if no lms user exists for an external id
        """
        organization = OrganizationFactory.create(short_name=self.organization_key)
        SAMLProviderConfigFactory.create(organization=organization)

        user = get_user_by_program_id(self.external_user_id, self.program_uuid)
        self.assertIsNone(user)
Пример #7
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 self.assertRaises(OrganizationDoesNotExistException):
         get_users_by_external_keys(self.program_uuid, [])
    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)
Пример #9
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, [])
Пример #10
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, [])
Пример #11
0
    def setUp(self):
        """
        Setup operations for saml configurations. these operations contain
        creation of SAMLConfiguration and SAMLProviderConfig records in database.
        """
        super(TestSAMLCommand, self).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')
Пример #12
0
    def setUp(self):
        """
        Setup operations for saml configurations. these operations contain
        creation of SAMLConfiguration and SAMLProviderConfig records in database.
        """
        super(TestSAMLCommand, self).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')
Пример #13
0
 def setUp(self):
     """
     Set up test data
     """
     super(WritingProgramEnrollmentTest, self).setUp()
     catalog_org = CatalogOrganizationFactory.create(
         key=self.organization_key)
     program = ProgramFactory.create(uuid=self.program_uuid_x,
                                     authoring_organizations=[catalog_org])
     organization = OrganizationFactory.create(
         short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid_x),
               program, None)
Пример #14
0
    def test_multiple_active_saml_providers(self):
        """
        If multiple samlprovider records exist with the same organization
        an exception is raised
        """
        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)

        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        # create a second active config for the same organization
        SAMLProviderConfigFactory.create(organization=organization, slug='foox')

        with pytest.raises(UserLookupException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #15
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'
         }
     ))
Пример #16
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()
        cls.user = UserFactory.create()

        for course_key in cls.course_keys:
            CourseOverviewFactory(id=course_key)
        SAMLProviderConfigFactory.create(organization=cls.organization,
                                         slug=cls.provider_slug)
Пример #17
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'
         }
     ))
Пример #18
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='{0}:{1}'.format(
                                       provider.slug, self.external_id))
Пример #19
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='{0}:{1}'.format(provider.slug, self.external_id)
     )
Пример #20
0
    def test_multiple_active_saml_providers(self):
        """
        If multiple samlprovider records exist with the same organization
        an exception is raised
        """
        organization = OrganizationFactory.create(
            short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)

        self.create_social_auth_entry(self.user, provider,
                                      self.external_user_id)

        # create a second active config for the same organization
        SAMLProviderConfigFactory.create(organization=organization,
                                         slug='foox')

        with pytest.raises(UserLookupException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #21
0
    def test_get_user_success(self):
        """
        Test lms user is successfully found
        """
        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        user = get_user_by_program_id(self.external_user_id, self.program_uuid)
        self.assertEquals(user, self.user)
Пример #22
0
    def test_get_user_success(self):
        """
        Test lms user is successfully found
        """
        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        user = get_user_by_program_id(self.external_user_id, self.program_uuid)
        self.assertEquals(user, self.user)
Пример #23
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')
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #24
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')
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #25
0
    def setUpClass(cls):
        """
        Set up test data
        """
        super(EnrollmentTestMixin, cls).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 = '{}+Toy_Course'.format(catalog_course_id_str)
        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='******')
Пример #26
0
 def setUp(self):
     """Make the user support staff"""
     super(SsoRecordsTests, self).setUp()
     SupportStaffRole().add_users(self.user)
     self.student = UserFactory.create(username='******', email='*****@*****.**', password='******')
     self.url = reverse("support:sso_records", kwargs={'username_or_email': self.student.username})
     self.org_key_list = ['test_org']
     for org_key in self.org_key_list:
         lms_org = OrganizationFactory(
             short_name=org_key
         )
         SAMLProviderConfigFactory(
             organization=lms_org,
             slug=org_key,
             enabled=True,
         )
Пример #27
0
    def test_catalog_program_missing_org(self):
        """
        Test OrganizationDoesNotExistException is thrown if the cached program does not
        have an authoring organization.
        """
        program = ProgramFactory.create(
            uuid=self.program_uuid,
            authoring_organizations=[]
        )
        cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)

        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #28
0
    def test_catalog_program_missing_org(self):
        """
        Test OrganizationDoesNotExistException is thrown if the cached program does not
        have an authoring organization.
        """
        program = ProgramFactory.create(
            uuid=self.program_uuid,
            authoring_organizations=[]
        )
        cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)

        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Пример #29
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)
Пример #30
0
 def setUp(self):
     super(ProgramEnrollmentsInspectorViewTests, self).setUp()
     self.url = reverse("support:program_enrollments_inspector")
     SupportStaffRole().add_users(self.user)
     self.program_uuid = str(uuid4())
     self.external_user_key = 'abcaaa'
     # Setup three orgs and their SAML providers
     self.org_key_list = ['test_org', 'donut_org', 'tri_org']
     for org_key in self.org_key_list:
         lms_org = OrganizationFactory(short_name=org_key)
         SAMLProviderConfigFactory(
             organization=lms_org,
             slug=org_key,
             enabled=True,
         )
     self.no_saml_org_key = 'no_saml_org'
     self.no_saml_lms_org = OrganizationFactory(
         short_name=self.no_saml_org_key)
Пример #31
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
Пример #32
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 {}))
     SAMLProviderConfigFactory.create(enabled=True, **(saml_provider_config or {}))
Пример #33
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 {}))
     SAMLProviderConfigFactory.create(enabled=True, **(saml_provider_config or {}))