Skip to content
Merged
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
84 changes: 73 additions & 11 deletions internal/server/has_server_guard_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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{}{},
},
Expand All @@ -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)
})
}
}
Loading