mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 18:58:35 +08:00
40 lines
1.1 KiB
Python
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") == {}
|