コード例 #1
0
ファイル: test_models.py プロジェクト: Ivip/django-oidc-auth
    def test_discover_existing_provider(self, get_mock):
        existing_provider = OpenIDProvider.objects.create(issuer='http://example.it')
        get_mock.return_value = self.response_mock

        found_provider = OpenIDProvider.discover(issuer='http://example.it')

        tools.assert_equal(found_provider.id, existing_provider.id)
コード例 #2
0
ファイル: test_models.py プロジェクト: Ivip/django-oidc-auth
    def test_discover_by_url(self, get_mock):
        get_mock.return_value = self.response_mock

        provider = OpenIDProvider.discover(issuer=self.issuer)

        get_mock.assert_called_with(urljoin(self.issuer, '.well-known/openid-configuration'), verify=True)
        self.assert_provider_valid(provider)
コード例 #3
0
    def test_discover_existing_provider(self, get_mock):
        existing_provider = OpenIDProvider.objects.create(
            issuer='http://example.it')
        get_mock.return_value = self.response_mock

        found_provider = OpenIDProvider.discover(issuer='http://example.it')

        tools.assert_equal(found_provider.id, existing_provider.id)
コード例 #4
0
    def test_discover_by_url(self, get_mock):
        get_mock.return_value = self.response_mock

        provider = OpenIDProvider.discover(issuer=self.issuer)

        get_mock.assert_called_with(urljoin(
            self.issuer, '.well-known/openid-configuration'),
                                    verify=True)
        self.assert_provider_valid(provider)
コード例 #5
0
    def test_discover_by_credentials(self, get_mock):
        credentials = {'id_token': 'imagine this is a hash'}

        get_mock.return_value = self.response_mock

        with mock.patch.object(OpenIDProvider, '_get_issuer') as _get_issuer:
            _get_issuer.return_value = self.issuer
            provider = OpenIDProvider.discover(credentials=credentials)
            _get_issuer.assert_called_with(credentials['id_token'])

        self.assert_provider_valid(provider)
コード例 #6
0
ファイル: test_models.py プロジェクト: Ivip/django-oidc-auth
    def test_discover_by_credentials(self, get_mock):
        credentials = {
            'id_token': 'imagine this is a hash'
        }

        get_mock.return_value = self.response_mock

        with mock.patch.object(OpenIDProvider, '_get_issuer') as _get_issuer:
            _get_issuer.return_value = self.issuer
            provider = OpenIDProvider.discover(credentials=credentials)
            _get_issuer.assert_called_with(credentials['id_token'])

        self.assert_provider_valid(provider)
コード例 #7
0
    def test_override_data_existing_user(self, get_mock):
        get_mock.return_value = self.response_mock
        provider = OpenIDProvider.discover(issuer=self.issuer)
        user = User.objects.create_superuser('admin', '*****@*****.**',
                                             'admin password')

        with mock.patch.object(OpenIDUser, '_get_userinfo') as get_userinfo:
            get_userinfo.return_value = {
                'preferred_username': '******',
                'email': '*****@*****.**',
                'given_name': 'foo',
                'family_name': 'bar'
            }

            oidc_user = OpenIDUser.get_or_create(id_token={'sub': 'admin'},
                                                 access_token='foo',
                                                 refresh_token='bar',
                                                 provider=provider)

        user = User.objects.get(username='******')
        self.assertEqual(user.email, '*****@*****.**')
コード例 #8
0
    def test_create_new_superuser(self, get_mock):
        get_mock.return_value = self.response_mock
        provider = OpenIDProvider.discover(issuer=self.issuer)

        with mock.patch.object(OpenIDUser, '_get_userinfo') as get_userinfo:
            get_userinfo.return_value = {
                'preferred_username': '******',
                'email': '*****@*****.**',
                'given_name': 'foo',
                'family_name': 'bar',
                'is_superuser': True,
                'is_staff': True
            }

            oidc_user = OpenIDUser.get_or_create(id_token={'sub': 'admin'},
                                                 access_token='foo',
                                                 refresh_token='bar',
                                                 provider=provider)

        user = User.objects.get(username='******')
        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)