Esempio n. 1
0
def test_callback_with_missing_state(import_by_path, app_setting, OAuth2Session, request_factory):
    request = request_factory.get('/')
    request.session = {}
    app_setting.return_value = 'app-setting'
    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/login/'
Esempio n. 2
0
def test_callback_with_invalid_grant(import_by_path, app_setting, OAuth2Session, request_factory):
    request = request_factory.get('/')
    request.session = {'oauth_state':_state('foo')}
    app_setting.return_value = 'app-setting'
    OAuth2Session.return_value = mock.Mock(fetch_token = mock.Mock(side_effect=InvalidGrantError))
    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/login/'
Esempio n. 3
0
def test_callback_with_missing_state(import_by_path, app_setting,
                                     OAuth2Session, request_factory):
    request = request_factory.get('/')
    request.session = {}
    app_setting.return_value = 'app-setting'
    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/login/'
Esempio n. 4
0
def test_callback_with_invalid_grant(import_by_path, app_setting,
                                     OAuth2Session, request_factory):
    request = request_factory.get('/')
    request.session = {'oauth_state': _state('foo')}
    app_setting.return_value = 'app-setting'
    OAuth2Session.return_value = mock.Mock(fetch_token=mock.Mock(
        side_effect=InvalidGrantError))
    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/login/'
Esempio n. 5
0
def test_callback_redirect_to_next(import_by_path, app_setting, OAuth2Session, request_factory):
    request = request_factory.get(reverse(oauthadmin.views.callback))
    request.session = {'oauth_state': _state('state-variable','/admin/content/')}
    OAuth2Session.return_value = mock.Mock(
        fetch_token = mock.Mock(return_value = 'token')
    )
    app_setting.return_value = 'app-setting'
    ibp = mock.Mock()
    ibp.return_value = 'test-user'
    import_by_path.return_value = ibp

    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/admin/content/'
Esempio n. 6
0
def test_callback(import_by_path, app_setting, OAuth2Session, request_factory):
    request = request_factory.get(reverse(oauthadmin.views.callback))
    request.session = {'oauth_state': _state('state-variable')}
    OAuth2Session.return_value = mock.Mock(fetch_token=mock.Mock(
        return_value='token'))
    app_setting.return_value = 'app-setting'
    ibp = mock.Mock()
    ibp.return_value = 'test-user'
    import_by_path.return_value = ibp

    resp = callback(request)
    assert resp.status_code == 302
    assert resp['location'] == 'http://testserver/callback/app-setting'
    assert request.session.get('oauth_token') == 'token'
    assert request.session.get('user') == 'test-user'