Ejemplo n.º 1
0
def test_sqlite_reading_bad_token_data():
    adapter = SQLiteAdapter(":memory:")
    # inject bad data (array, needs to be dict)
    adapter._connection.execute(
        """\
INSERT INTO token_storage(namespace, resource_server, token_data_json)
VALUES (?, ?, ?)""",
        (adapter.namespace, "foo_rs", "[]"),
    )
    with pytest.raises(ValueError,
                       match="data error: token data was not saved as a dict"):
        adapter.get_token_data("foo_rs")
Ejemplo n.º 2
0
def test_store_and_refresh(mock_response, mock_refresh_response):
    adapter = SQLiteAdapter(MEMORY_DBNAME)
    adapter.store(mock_response)

    # rs1 and rs2 data was stored correctly
    data = adapter.get_token_data("resource_server_1")
    assert data["access_token"] == "access_token_1"
    data = adapter.get_token_data("resource_server_2")
    assert data["access_token"] == "access_token_2"

    # "refresh" happens, this should change rs2 but not rs1
    adapter.store(mock_refresh_response)
    data = adapter.get_token_data("resource_server_1")
    assert data["access_token"] == "access_token_1"
    data = adapter.get_token_data("resource_server_2")
    assert data["access_token"] == "access_token_2_refreshed"
Ejemplo n.º 3
0
def test_load_missing_token_data():
    adapter = SQLiteAdapter(MEMORY_DBNAME)
    assert adapter.get_by_resource_server() == {}
    assert adapter.get_token_data("resource_server_1") is None