mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
feat: OAuth2StoreTokenCommand (#32546)
This commit is contained in:
@@ -41,7 +41,9 @@ from superset.db_engine_specs.sqlite import SqliteEngineSpec
|
||||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
|
||||
from superset.exceptions import OAuth2RedirectError, SupersetSecurityException
|
||||
from superset.sql_parse import Table
|
||||
from superset.superset_typing import OAuth2State
|
||||
from superset.utils import json
|
||||
from superset.utils.oauth2 import encode_oauth2_state
|
||||
from tests.unit_tests.fixtures.common import (
|
||||
create_columnar_file,
|
||||
create_csv_file,
|
||||
@@ -752,6 +754,7 @@ def test_oauth2_happy_path(
|
||||
Database.metadata.create_all(session.get_bind()) # pylint: disable=no-member
|
||||
db.session.add(
|
||||
Database(
|
||||
id=1,
|
||||
database_name="my_db",
|
||||
sqlalchemy_uri="sqlite://",
|
||||
uuid=UUID("7c1b7880-a59d-47cd-8bf1-f1eb8d2863cb"),
|
||||
@@ -771,13 +774,12 @@ def test_oauth2_happy_path(
|
||||
"refresh_token": "ZZZ",
|
||||
}
|
||||
|
||||
state = {
|
||||
state: OAuth2State = {
|
||||
"user_id": 1,
|
||||
"database_id": 1,
|
||||
"tab_id": 42,
|
||||
"tab_id": "42",
|
||||
"default_redirect_uri": "http://localhost:8088/api/v1/oauth2/",
|
||||
}
|
||||
decode_oauth2_state = mocker.patch("superset.databases.api.decode_oauth2_state")
|
||||
decode_oauth2_state.return_value = state
|
||||
|
||||
mocker.patch("superset.databases.api.render_template", return_value="OK")
|
||||
|
||||
@@ -785,13 +787,12 @@ def test_oauth2_happy_path(
|
||||
response = client.get(
|
||||
"/api/v1/database/oauth2/",
|
||||
query_string={
|
||||
"state": "some%2Estate",
|
||||
"state": encode_oauth2_state(state),
|
||||
"code": "XXX",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
decode_oauth2_state.assert_called_with("some%2Estate")
|
||||
get_oauth2_token.assert_called_with({"id": "one", "secret": "two"}, "XXX")
|
||||
|
||||
token = db.session.query(DatabaseUserOAuth2Tokens).one()
|
||||
@@ -841,13 +842,12 @@ def test_oauth2_permissions(
|
||||
"refresh_token": "ZZZ",
|
||||
}
|
||||
|
||||
state = {
|
||||
state: OAuth2State = {
|
||||
"user_id": 1,
|
||||
"database_id": 1,
|
||||
"tab_id": 42,
|
||||
"tab_id": "42",
|
||||
"default_redirect_uri": "http://localhost:8088/api/v1/oauth2/",
|
||||
}
|
||||
decode_oauth2_state = mocker.patch("superset.databases.api.decode_oauth2_state")
|
||||
decode_oauth2_state.return_value = state
|
||||
|
||||
mocker.patch("superset.databases.api.render_template", return_value="OK")
|
||||
|
||||
@@ -855,13 +855,12 @@ def test_oauth2_permissions(
|
||||
response = client.get(
|
||||
"/api/v1/database/oauth2/",
|
||||
query_string={
|
||||
"state": "some%2Estate",
|
||||
"state": encode_oauth2_state(state),
|
||||
"code": "XXX",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
decode_oauth2_state.assert_called_with("some%2Estate")
|
||||
get_oauth2_token.assert_called_with({"id": "one", "secret": "two"}, "XXX")
|
||||
|
||||
token = db.session.query(DatabaseUserOAuth2Tokens).one()
|
||||
@@ -916,13 +915,12 @@ def test_oauth2_multiple_tokens(
|
||||
},
|
||||
]
|
||||
|
||||
state = {
|
||||
state: OAuth2State = {
|
||||
"user_id": 1,
|
||||
"database_id": 1,
|
||||
"tab_id": 42,
|
||||
"tab_id": "42",
|
||||
"default_redirect_uri": "http://localhost:8088/api/v1/oauth2/",
|
||||
}
|
||||
decode_oauth2_state = mocker.patch("superset.databases.api.decode_oauth2_state")
|
||||
decode_oauth2_state.return_value = state
|
||||
|
||||
mocker.patch("superset.databases.api.render_template", return_value="OK")
|
||||
|
||||
@@ -930,7 +928,7 @@ def test_oauth2_multiple_tokens(
|
||||
response = client.get(
|
||||
"/api/v1/database/oauth2/",
|
||||
query_string={
|
||||
"state": "some%2Estate",
|
||||
"state": encode_oauth2_state(state),
|
||||
"code": "XXX",
|
||||
},
|
||||
)
|
||||
@@ -939,7 +937,7 @@ def test_oauth2_multiple_tokens(
|
||||
response = client.get(
|
||||
"/api/v1/database/oauth2/",
|
||||
query_string={
|
||||
"state": "some%2Estate",
|
||||
"state": encode_oauth2_state(state),
|
||||
"code": "XXX",
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user