コード例 #1
0
    def test_oidc_user_created_signal_is_sent_during_new_user_authentication(
            self, rf):
        self.signal_was_called = False

        def handler(sender, request, oidc_user, **kwargs):
            self.request = request
            self.oidc_user = oidc_user
            self.signal_was_called = True

        oidc_user_created.connect(handler)

        request = rf.get('/oidc/cb/', {
            'state': 'state',
            'code': 'authcode',
        })
        SessionMiddleware().process_request(request)
        request.session.save()
        backend = OIDCAuthBackend()
        backend.authenticate(request, 'nonce')

        assert self.signal_was_called is True
        assert type(self.request) is WSGIRequest
        assert self.oidc_user.userinfo['email'] == '*****@*****.**'
        assert self.oidc_user.userinfo['sub'] == '1234'

        oidc_user_created.disconnect(handler)
コード例 #2
0
    def test_oidc_user_created_signal_is_sent_during_new_user_authentication(
            self, rf):
        self.signal_was_called = False

        def handler(sender, request, oidc_user, **kwargs):
            self.request = request
            self.oidc_user = oidc_user
            self.signal_was_called = True

        oidc_user_created.connect(handler)

        request = rf.get('/', HTTP_AUTHORIZATION='Bearer accesstoken')
        SessionMiddleware().process_request(request)
        request.session.save()
        backend = BearerTokenAuthentication()
        user, _ = backend.authenticate(request)

        assert self.signal_was_called is True
        assert user.email == '*****@*****.**'
        assert user.oidc_user.sub == '1234'

        oidc_user_created.disconnect(handler)