Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复label值为空时,跳过验证 (#272) #273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/datasource/auth/decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func FilterLabel(targetResourceLabel []map[string]string, permLabelList []map[st

func LabelMatched(targetResourceLabel map[string]string, permLabel map[string]string) bool {
for k, v := range permLabel {
if vv := targetResourceLabel[k]; vv != v {
if vv, ok := targetResourceLabel[k]; !ok || vv != v {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/datasource/auth/filter_kvdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func FilterKVs(kvs []*model.KVDoc, labelsList []map[string]string) []*model.KVDo

func matchOne(kv *model.KVDoc, labels map[string]string) bool {
for lk, lv := range labels {
if v := kv.Labels[lk]; v != lv {
if v, ok := kv.Labels[lk]; !ok || v != lv {
return false
}
}
Expand Down
29 changes: 29 additions & 0 deletions server/datasource/auth/filter_kvdoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ func TestFilterKVs(t *testing.T) {
r := FilterKVs(kvs, permResourceLabel)
assert.Equal(t, 1, len(r))
}

func TestFilterKVsNull(t *testing.T) {
permResourceLabel := []map[string]string{
{"environment": ""},
}

var kvs []*model.KVDoc

kv1 := new(model.KVDoc)
kv1.Key = "k1"
kv1.Value = "v1"
kv1.Labels = map[string]string{"environment": "production", "appId": "default", "service": "s1"}
kvs = append(kvs, kv1)

kv2 := new(model.KVDoc)
kv2.Key = "k2"
kv2.Value = "v2"
kv2.Labels = map[string]string{"environment": "", "appId": "default"}
kvs = append(kvs, kv2)

kv3 := new(model.KVDoc)
kv3.Key = "k3"
kv3.Value = "v3"
kv3.Labels = map[string]string{"version": "xxx"}
kvs = append(kvs, kv3)

r := FilterKVs(kvs, permResourceLabel)
assert.Equal(t, 1, len(r))
}