Ejemplo n.º 1
0
def test_load_tokens_with_invalid_refresh_token(
        mem_storage, expired_tokens_with_refresh,
        refresh_authorizer_raises_invalid_grant):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    mem_storage.tokens = expired_tokens_with_refresh
    with pytest.raises(TokensExpired):
        cli.load_tokens()
Ejemplo n.º 2
0
def test_client_token_calls_with_no_storage_raise_error(mock_tokens):
    cli = NativeClient(client_id=str(uuid4()), token_storage=None)
    with pytest.raises(LoadError):
        cli.load_tokens()
    with pytest.raises(LoadError):
        cli.save_tokens(mock_tokens)
    with pytest.raises(LoadError):
        cli.logout()
Ejemplo n.º 3
0
def test_client_load_auto_refresh(expired_tokens_with_refresh, mem_storage,
                                  mock_refresh_token_authorizer):
    mem_storage.tokens = expired_tokens_with_refresh
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    tokens = cli.load_tokens()
    for tset in tokens.values():
        assert tset['access_token'] == '<Refreshed Access Token>'
Ejemplo n.º 4
0
def test_load_accepts_string_or_iterable_requested_scopes(
        mem_storage, mock_tokens):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    mem_storage.tokens = mock_tokens
    scopes = ('openid profile email custom_scope '
              'urn:globus:auth:scope:transfer.api.globus.org:all')
    tokens = cli.load_tokens(scopes)
    assert len(tokens) == 3
    authorizers = cli.get_authorizers(scopes)
    assert len(authorizers) == 3
Ejemplo n.º 5
0
def test_authorizer_refresh_hook(mock_tokens, mock_refresh_token_authorizer,
                                 mem_storage):
    mock_tokens['resource.server.org']['refresh_token'] = '<Refresh Token>'
    mem_storage.tokens = mock_tokens
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    rs_auth = cli.get_authorizers()['resource.server.org']
    rs_auth.expires_at = 0
    rs_auth.check_expiration_time()

    tokens = cli.load_tokens()
    assert 'example.on.refresh.success' in tokens.keys()
Ejemplo n.º 6
0
def test_client_token_refresh_with_requested_scope_subset(
        mem_storage, expired_tokens_with_refresh,
        mock_refresh_token_authorizer):
    mem_storage.tokens = expired_tokens_with_refresh
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    tokens = cli.load_tokens(requested_scopes=['profile'])
    assert tokens
    for tset in mem_storage.tokens.values():
        if tset['resource_server'] == 'auth.globus.org':
            assert tset['access_token'] == '<Refreshed Access Token>'
        else:
            assert tset['access_token'] != '<Refreshed Access Token>'
Ejemplo n.º 7
0
def test_non_requested_token_does_not_cancel_load(mem_storage, mock_tokens,
                                                  mock_expired_tokens):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    good = [
        'openid', 'profile',
        'urn:globus:auth:scope:transfer.api.globus.org:all'
    ]
    exp = 'custom_scope'
    exprs = 'resource.server.org'
    mem_storage.tokens = mock_tokens
    mem_storage.tokens[exprs] = mock_expired_tokens[exprs]

    # should not raise
    cli.load_tokens(requested_scopes=good)
    cli.load_tokens()
    with pytest.raises(TokensExpired):
        cli.load_tokens(requested_scopes=exp)
Ejemplo n.º 8
0
def test_client_when_cannot_refresh(mock_expired_tokens, mem_storage,
                                    mock_refresh_token_authorizer):
    mem_storage.tokens = mock_expired_tokens
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    with pytest.raises(TokensExpired):
        cli.load_tokens()
Ejemplo n.º 9
0
def test_load_raises_scopes_mismatch(mem_storage, mock_tokens):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    mem_storage.tokens = mock_tokens
    with pytest.raises(ScopesMismatch):
        cli.load_tokens(requested_scopes=['foo'])
Ejemplo n.º 10
0
def test_load_no_tokens_raises_error(mem_storage):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    with pytest.raises(LoadError):
        cli.load_tokens()
Ejemplo n.º 11
0
def test_load_tokens(mem_storage, mock_tokens):
    cli = NativeClient(client_id=str(uuid4()), token_storage=mem_storage)
    mem_storage.tokens = mock_tokens
    assert cli.load_tokens() == mock_tokens