diff --git a/internal/server/has_server_guard_policies_test.go b/internal/server/has_server_guard_policies_test.go index de8f9d4a..71459b2e 100644 --- a/internal/server/has_server_guard_policies_test.go +++ b/internal/server/has_server_guard_policies_test.go @@ -8,30 +8,32 @@ import ( ) func TestHasServerGuardPolicies(t *testing.T) { + allowOnlyPolicy := map[string]interface{}{ + "allow-only": map[string]interface{}{ + "min-integrity": "approved", + "repos": []interface{}{"github/gh-aw*"}, + }, + } + tests := []struct { name string cfg *config.Config expected bool }{ { - name: "server with guard-policies should return true", + name: "single server with guard-policies returns true", cfg: &config.Config{ Servers: map[string]*config.ServerConfig{ "github": { - Type: "stdio", - GuardPolicies: map[string]interface{}{ - "allow-only": map[string]interface{}{ - "min-integrity": "approved", - "repos": []interface{}{"github/gh-aw*"}, - }, - }, + Type: "stdio", + GuardPolicies: allowOnlyPolicy, }, }, }, expected: true, }, { - name: "server without guard-policies should return false", + name: "single server without guard-policies returns false", cfg: &config.Config{ Servers: map[string]*config.ServerConfig{ "github": { @@ -42,10 +44,70 @@ func TestHasServerGuardPolicies(t *testing.T) { expected: false, }, { - name: "server with empty guard-policies should return false", + name: "single server with empty guard-policies map returns false", + cfg: &config.Config{ + Servers: map[string]*config.ServerConfig{ + "github": { + Type: "stdio", + GuardPolicies: map[string]interface{}{}, + }, + }, + }, + expected: false, + }, + { + name: "no servers returns false", + cfg: &config.Config{ + Servers: map[string]*config.ServerConfig{}, + }, + expected: false, + }, + { + name: "multiple servers all without guard-policies returns false", + cfg: &config.Config{ + Servers: map[string]*config.ServerConfig{ + "github": {Type: "stdio"}, + "slack": {Type: "stdio"}, + "jira": {Type: "stdio"}, + }, + }, + expected: false, + }, + { + name: "multiple servers where one has guard-policies returns true", + cfg: &config.Config{ + Servers: map[string]*config.ServerConfig{ + "github": {Type: "stdio"}, + "slack": { + Type: "stdio", + GuardPolicies: allowOnlyPolicy, + }, + }, + }, + expected: true, + }, + { + name: "multiple servers all with guard-policies returns true", cfg: &config.Config{ Servers: map[string]*config.ServerConfig{ "github": { + Type: "stdio", + GuardPolicies: allowOnlyPolicy, + }, + "slack": { + Type: "stdio", + GuardPolicies: allowOnlyPolicy, + }, + }, + }, + expected: true, + }, + { + name: "mix of servers with and without empty guard-policies returns false", + cfg: &config.Config{ + Servers: map[string]*config.ServerConfig{ + "github": {Type: "stdio"}, + "slack": { Type: "stdio", GuardPolicies: map[string]interface{}{}, }, @@ -58,7 +120,7 @@ func TestHasServerGuardPolicies(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := hasServerGuardPolicies(tt.cfg) - assert.Equal(t, tt.expected, result, "hasServerGuardPolicies should return %v", tt.expected) + assert.Equal(t, tt.expected, result) }) } }