mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-05-01 13:35:46 +00:00
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package oauth
|
|
|
|
import "testing"
|
|
|
|
func TestScopesMatch(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stored []string
|
|
desired []string
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "exact match",
|
|
stored: []string{"atproto", "blob:image/png"},
|
|
desired: []string{"atproto", "blob:image/png"},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "different order",
|
|
stored: []string{"blob:image/png", "atproto"},
|
|
desired: []string{"atproto", "blob:image/png"},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "missing scope in stored",
|
|
stored: []string{"atproto"},
|
|
desired: []string{"atproto", "blob:image/png"},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "extra scope in stored",
|
|
stored: []string{"atproto", "blob:image/png", "extra"},
|
|
desired: []string{"atproto", "blob:image/png"},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "both empty",
|
|
stored: []string{},
|
|
desired: []string{},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "nil vs empty",
|
|
stored: nil,
|
|
desired: []string{},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "completely different",
|
|
stored: []string{"foo", "bar"},
|
|
desired: []string{"baz", "qux"},
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := ScopesMatch(tt.stored, tt.desired)
|
|
if result != tt.expected {
|
|
t.Errorf("ScopesMatch(%v, %v) = %v, want %v",
|
|
tt.stored, tt.desired, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|