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')
 def test_catalog_program_does_not_exist(self):
     """
     Test ProgramDoesNotExistException is thrown if the program cache does
     not include the requested program uuid.
     """
     with pytest.raises(ProgramDoesNotExistException):
         get_user_by_program_id('school-id-1234', uuid4())
Exemple #3
0
 def test_catalog_program_does_not_exist(self):
     """
     Test ProgramDoesNotExistException is thrown if the program cache does
     not include the requested program uuid.
     """
     with pytest.raises(ProgramDoesNotExistException):
         get_user_by_program_id('school-id-1234', uuid4())
    def test_saml_provider_not_found(self):
        """
        Test an exception is thrown if no SAML provider exists for this program's organization
        """
        OrganizationFactory.create(short_name=self.organization_key)

        with pytest.raises(ProviderDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Exemple #5
0
    def test_saml_provider_not_found(self):
        """
        Test an exception is thrown if no SAML provider exists for this program's organization
        """
        OrganizationFactory.create(short_name=self.organization_key)

        with pytest.raises(ProviderDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Exemple #6
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)
Exemple #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')
        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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
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)
    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)
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)