Skip to content

Commit

Permalink
fix: auth tenant user not match id field (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Nov 20, 2023
1 parent 2de1ee2 commit f3cac33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/bk-user/bkuser/biz/idp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class AuthenticationMatcher:
def __init__(self, tenant_id: str, idp_id: str):
# TODO: 后续支持协同租户的数据源用户匹配
self.idp = Idp.objects.get(id=idp_id, owner_tenant_id=tenant_id)
# 内置字段
self.builtin_field_data_type_map = dict(UserBuiltinField.objects.all().values_list("name", "data_type"))
# Note: Local登录允许匹配ID
self.builtin_field_data_type_map["id"] = UserFieldDataType.NUMBER
# 自定义字段
self.custom_field_data_type_map = dict(
TenantUserCustomField.objects.filter(tenant_id=tenant_id).values_list("name", "data_type")
)
Expand Down
18 changes: 17 additions & 1 deletion src/bk-user/tests/biz/test_idp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def _initialize(self, default_tenant, tenant_user_custom_fields):
@pytest.mark.parametrize(
("field", "excepted_filter_key"),
[
("id", "id"),
("username", "username"),
("full_name", "full_name"),
("phone_country_code", "phone_country_code"),
Expand Down Expand Up @@ -107,10 +108,25 @@ def test_convert_one_rule_to_queryset_filter_for_source_data(self, source_data,
& Q(extras__region="[email protected]")
),
),
# ID Field Compare rule
(
DataSourceMatchRule(
data_source_id=1,
field_compare_rules=[FieldCompareRule(source_field="id", target_field="id")],
),
(Q(data_source_id=1) & Q(id=100)),
),
(
DataSourceMatchRule(
data_source_id=1,
field_compare_rules=[FieldCompareRule(source_field="user_id", target_field="id")],
),
(Q(data_source_id=1) & Q(id="test_username")),
),
],
)
def test_convert_one_rule_to_queryset_filter_for_rule(self, rule, excepted_queryset):
source_data = {"user_id": "test_username", "phone": "1234567890123", "email": "[email protected]"}
source_data = {"id": 100, "user_id": "test_username", "phone": "1234567890123", "email": "[email protected]"}

queryset = self.matcher._convert_one_rule_to_queryset_filter(rule, source_data)

Expand Down

0 comments on commit f3cac33

Please sign in to comment.