+18


![dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)

![autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)




FFXN
GitHub
yyh
盐粒 Yanli
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Tianle
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Yunlu Wen
zyssyz123
Claude Opus 4.7
chariri
Asuka Minato
Copilot Autofix powered by AI
Nian
非法操作
Carmen Fernández Ruiz
wangxiaolei
QuantumGhost
L1nSn0w
Evan
Escape0707
Jingyi
Amr Sherif
ZHOU ZHICHEN
unknown
JzoNg
Xiyuan Chen
-LAN-
107bba0116
Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: EvanYao826 <[email protected]> Co-authored-by: yyh <[email protected]> Co-authored-by: 盐粒 Yanli <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tianle <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yunlu Wen <[email protected]> Co-authored-by: zyssyz123 <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: chariri <[email protected]> Co-authored-by: Asuka Minato <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]> Co-authored-by: Nian <[email protected]> Co-authored-by: 非法操作 <[email protected]> Co-authored-by: Carmen Fernández Ruiz <[email protected]> Co-authored-by: wangxiaolei <[email protected]> Co-authored-by: QuantumGhost <[email protected]> Co-authored-by: L1nSn0w <[email protected]> Co-authored-by: Evan <[email protected]> Co-authored-by: Escape0707 <[email protected]> Co-authored-by: Jingyi <[email protected]> Co-authored-by: Amr Sherif <[email protected]> Co-authored-by: ZHOU ZHICHEN <[email protected]> Co-authored-by: unknown <[email protected]> Co-authored-by: JzoNg <[email protected]> Co-authored-by: Xiyuan Chen <[email protected]> Co-authored-by: -LAN- <[email protected]>
118 lines
3.1 KiB
Python
118 lines
3.1 KiB
Python
import uuid
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from controllers.openapi.auth.data import (
|
|
AuthData,
|
|
Edition,
|
|
ExternalIdentity,
|
|
RequestContext,
|
|
current_edition,
|
|
)
|
|
from libs.oauth_bearer import Scope, TokenType
|
|
|
|
|
|
def test_current_edition_saas():
|
|
with patch("controllers.openapi.auth.data.dify_config") as cfg:
|
|
cfg.EDITION = "CLOUD"
|
|
cfg.ENTERPRISE_ENABLED = True
|
|
assert current_edition() == Edition.SAAS
|
|
|
|
|
|
def test_current_edition_ee():
|
|
with patch("controllers.openapi.auth.data.dify_config") as cfg:
|
|
cfg.EDITION = "SELF_HOSTED"
|
|
cfg.ENTERPRISE_ENABLED = True
|
|
assert current_edition() == Edition.EE
|
|
|
|
|
|
def test_current_edition_ce():
|
|
with patch("controllers.openapi.auth.data.dify_config") as cfg:
|
|
cfg.EDITION = "SELF_HOSTED"
|
|
cfg.ENTERPRISE_ENABLED = False
|
|
assert current_edition() == Edition.CE
|
|
|
|
|
|
def test_external_identity_frozen():
|
|
ei = ExternalIdentity(email="[email protected]", issuer="idp")
|
|
with pytest.raises(ValidationError):
|
|
ei.email = "[email protected]" # type: ignore[misc]
|
|
|
|
|
|
def test_external_identity_issuer_optional():
|
|
ei = ExternalIdentity(email="[email protected]")
|
|
assert ei.issuer is None
|
|
|
|
|
|
def test_request_context_frozen():
|
|
ctx = RequestContext(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
path_params={"app_id": "123"},
|
|
)
|
|
with pytest.raises(ValidationError):
|
|
ctx.token_type = TokenType.OAUTH_EXTERNAL_SSO # type: ignore[misc]
|
|
|
|
|
|
def test_request_context_scope_optional():
|
|
ctx = RequestContext(token_type=TokenType.OAUTH_ACCOUNT, path_params={})
|
|
assert ctx.scope is None
|
|
|
|
|
|
def test_auth_data_is_mutable():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
token_hash="abc",
|
|
scopes=frozenset({Scope.FULL}),
|
|
)
|
|
data.token_type = TokenType.OAUTH_EXTERNAL_SSO
|
|
assert data.token_type == TokenType.OAUTH_EXTERNAL_SSO
|
|
|
|
|
|
def test_auth_data_path_params_defaults_empty():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
token_hash="abc",
|
|
scopes=frozenset(),
|
|
)
|
|
assert data.path_params == {}
|
|
|
|
|
|
def test_auth_data_account_id_optional():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_EXTERNAL_SSO,
|
|
token_hash="abc",
|
|
scopes=frozenset({Scope.APPS_RUN}),
|
|
external_identity=ExternalIdentity(email="[email protected]"),
|
|
)
|
|
assert data.account_id is None
|
|
|
|
|
|
def test_auth_data_external_identity_none_for_account():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
account_id=uuid.uuid4(),
|
|
token_hash="abc",
|
|
scopes=frozenset({Scope.FULL}),
|
|
)
|
|
assert data.external_identity is None
|
|
|
|
|
|
def test_auth_data_tenants_default_empty():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
token_hash="abc",
|
|
scopes=frozenset(),
|
|
)
|
|
assert data.tenants == {}
|
|
|
|
|
|
def test_auth_data_token_id_optional():
|
|
data = AuthData(
|
|
token_type=TokenType.OAUTH_ACCOUNT,
|
|
token_hash="abc",
|
|
scopes=frozenset(),
|
|
)
|
|
assert data.token_id is None
|