-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcollection_filters_test.go
More file actions
79 lines (67 loc) · 2.41 KB
/
collection_filters_test.go
File metadata and controls
79 lines (67 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package oidfed
import (
"testing"
"github.com/go-oidfed/lib/apimodel"
)
func TestFilterAndTrim_EntityTypesFilter(t *testing.T) {
e1 := &CollectedEntity{EntityID: "e1", EntityTypes: []string{"openid_provider"}}
e2 := &CollectedEntity{EntityID: "e2", EntityTypes: []string{"federation_entity"}}
got := FilterAndTrimEntities([]*CollectedEntity{e1, e2}, apimodel.EntityCollectionRequest{
EntityTypes: []string{"openid_provider"},
})
if len(got) != 1 || got[0].EntityID != "e1" {
t.Fatalf("expected only e1, got %+v", got)
}
}
func TestFilterAndTrim_QueryFuzzy(t *testing.T) {
e := &CollectedEntity{
EntityID: "e1",
EntityTypes: []string{"openid_provider"},
UIInfos: map[string]UIInfo{
"openid_provider": {DisplayName: "Amazing Service", Extra: map[string]any{"display_name#en": "Amazing Service"}},
},
}
got := FilterAndTrimEntities([]*CollectedEntity{e}, apimodel.EntityCollectionRequest{Query: "amaz"})
if len(got) != 1 {
t.Fatalf("expected 1 result, got %d", len(got))
}
}
func TestFilterAndTrim_TrustMarks(t *testing.T) {
e1 := &CollectedEntity{EntityID: "e1", TrustMarks: TrustMarkInfos{{TrustMarkType: "type1"}}}
e2 := &CollectedEntity{EntityID: "e2", TrustMarks: TrustMarkInfos{{TrustMarkType: "type2"}}}
got := FilterAndTrimEntities([]*CollectedEntity{e1, e2}, apimodel.EntityCollectionRequest{TrustMarkTypes: []string{"type1"}})
if len(got) != 1 || got[0].EntityID != "e1" {
t.Fatalf("expected only e1 by trust mark filter, got %+v", got)
}
}
func TestTrim_LanguageFiltering(t *testing.T) {
e := &CollectedEntity{
EntityID: "e1",
UIInfos: map[string]UIInfo{
"openid_provider": {
DisplayName: "Default Name",
Extra: map[string]any{
"display_name#en": "English Name",
"display_name#de": "Deutscher Name",
},
},
},
}
got := FilterAndTrimEntities([]*CollectedEntity{e}, apimodel.EntityCollectionRequest{
UIClaims: []string{"display_name"},
LanguageTags: []string{"en"},
})
if len(got) != 1 {
t.Fatalf("expected 1 result, got %d", len(got))
}
ui := got[0].UIInfos["openid_provider"]
if ui.DisplayName != "Default Name" {
t.Fatalf("expected default display name kept, got %q", ui.DisplayName)
}
if ui.Extra == nil || ui.Extra["display_name#en"] != "English Name" {
t.Fatalf("expected only English extra kept, got %+v", ui.Extra)
}
if _, ok := ui.Extra["display_name#de"]; ok {
t.Fatalf("did not expect German extra to be present: %+v", ui.Extra)
}
}