dify/api/tests/unit_tests/libs/test_oauth_base.py
林玮 (Jade Lin) 82ff93cbdd
feat(oauth): preserve redirect_url through OAuth state for post-login… (#38900)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-14 08:23:39 +00:00

40 lines
1.1 KiB
Python

import pytest
from libs.oauth import OAuth, decode_oauth_state, encode_oauth_state
def test_oauth_base_methods_raise_not_implemented():
oauth = OAuth(client_id="id", client_secret="sec", redirect_uri="uri")
with pytest.raises(NotImplementedError):
oauth.get_authorization_url()
with pytest.raises(NotImplementedError):
oauth.get_access_token("code")
with pytest.raises(NotImplementedError):
oauth.get_raw_user_info("token")
with pytest.raises(NotImplementedError):
oauth._transform_user_info({})
def test_oauth_state_round_trips_login_context():
state = encode_oauth_state(
invite_token="invite-123",
timezone="Asia/Shanghai",
language="zh-Hans",
redirect_url="/apps?category=workflow",
)
assert decode_oauth_state(state) == {
"invite_token": "invite-123",
"timezone": "Asia/Shanghai",
"language": "zh-Hans",
"redirect_url": "/apps?category=workflow",
}
def test_oauth_state_returns_empty_payload_for_invalid_state():
assert decode_oauth_state("invalid-state") == {}