@@ -8,30 +8,32 @@ import (
88)
99
1010func TestHasServerGuardPolicies (t * testing.T ) {
11+ allowOnlyPolicy := map [string ]interface {}{
12+ "allow-only" : map [string ]interface {}{
13+ "min-integrity" : "approved" ,
14+ "repos" : []interface {}{"github/gh-aw*" },
15+ },
16+ }
17+
1118 tests := []struct {
1219 name string
1320 cfg * config.Config
1421 expected bool
1522 }{
1623 {
17- name : "server with guard-policies should return true" ,
24+ name : "single server with guard-policies returns true" ,
1825 cfg : & config.Config {
1926 Servers : map [string ]* config.ServerConfig {
2027 "github" : {
21- Type : "stdio" ,
22- GuardPolicies : map [string ]interface {}{
23- "allow-only" : map [string ]interface {}{
24- "min-integrity" : "approved" ,
25- "repos" : []interface {}{"github/gh-aw*" },
26- },
27- },
28+ Type : "stdio" ,
29+ GuardPolicies : allowOnlyPolicy ,
2830 },
2931 },
3032 },
3133 expected : true ,
3234 },
3335 {
34- name : "server without guard-policies should return false" ,
36+ name : "single server without guard-policies returns false" ,
3537 cfg : & config.Config {
3638 Servers : map [string ]* config.ServerConfig {
3739 "github" : {
@@ -42,10 +44,70 @@ func TestHasServerGuardPolicies(t *testing.T) {
4244 expected : false ,
4345 },
4446 {
45- name : "server with empty guard-policies should return false" ,
47+ name : "single server with empty guard-policies map returns false" ,
48+ cfg : & config.Config {
49+ Servers : map [string ]* config.ServerConfig {
50+ "github" : {
51+ Type : "stdio" ,
52+ GuardPolicies : map [string ]interface {}{},
53+ },
54+ },
55+ },
56+ expected : false ,
57+ },
58+ {
59+ name : "no servers returns false" ,
60+ cfg : & config.Config {
61+ Servers : map [string ]* config.ServerConfig {},
62+ },
63+ expected : false ,
64+ },
65+ {
66+ name : "multiple servers all without guard-policies returns false" ,
67+ cfg : & config.Config {
68+ Servers : map [string ]* config.ServerConfig {
69+ "github" : {Type : "stdio" },
70+ "slack" : {Type : "stdio" },
71+ "jira" : {Type : "stdio" },
72+ },
73+ },
74+ expected : false ,
75+ },
76+ {
77+ name : "multiple servers where one has guard-policies returns true" ,
78+ cfg : & config.Config {
79+ Servers : map [string ]* config.ServerConfig {
80+ "github" : {Type : "stdio" },
81+ "slack" : {
82+ Type : "stdio" ,
83+ GuardPolicies : allowOnlyPolicy ,
84+ },
85+ },
86+ },
87+ expected : true ,
88+ },
89+ {
90+ name : "multiple servers all with guard-policies returns true" ,
4691 cfg : & config.Config {
4792 Servers : map [string ]* config.ServerConfig {
4893 "github" : {
94+ Type : "stdio" ,
95+ GuardPolicies : allowOnlyPolicy ,
96+ },
97+ "slack" : {
98+ Type : "stdio" ,
99+ GuardPolicies : allowOnlyPolicy ,
100+ },
101+ },
102+ },
103+ expected : true ,
104+ },
105+ {
106+ name : "mix of servers with and without empty guard-policies returns false" ,
107+ cfg : & config.Config {
108+ Servers : map [string ]* config.ServerConfig {
109+ "github" : {Type : "stdio" },
110+ "slack" : {
49111 Type : "stdio" ,
50112 GuardPolicies : map [string ]interface {}{},
51113 },
@@ -58,7 +120,7 @@ func TestHasServerGuardPolicies(t *testing.T) {
58120 for _ , tt := range tests {
59121 t .Run (tt .name , func (t * testing.T ) {
60122 result := hasServerGuardPolicies (tt .cfg )
61- assert .Equal (t , tt .expected , result , "hasServerGuardPolicies should return %v" , tt . expected )
123+ assert .Equal (t , tt .expected , result )
62124 })
63125 }
64126}
0 commit comments