(t *testing.T)
| 48 | } |
| 49 | |
| 50 | func TestToolScopeInfo_HasAcceptedScope(t *testing.T) { |
| 51 | testCases := []struct { |
| 52 | name string |
| 53 | scopeInfo *ToolScopeInfo |
| 54 | userScopes []string |
| 55 | expected bool |
| 56 | }{ |
| 57 | { |
| 58 | name: "has exact required scope", |
| 59 | scopeInfo: &ToolScopeInfo{ |
| 60 | RequiredScopes: []string{"read:org"}, |
| 61 | AcceptedScopes: []string{"read:org", "write:org", "admin:org"}, |
| 62 | }, |
| 63 | userScopes: []string{"read:org"}, |
| 64 | expected: true, |
| 65 | }, |
| 66 | { |
| 67 | name: "has parent scope (admin:org grants read:org)", |
| 68 | scopeInfo: &ToolScopeInfo{ |
| 69 | RequiredScopes: []string{"read:org"}, |
| 70 | AcceptedScopes: []string{"read:org", "write:org", "admin:org"}, |
| 71 | }, |
| 72 | userScopes: []string{"admin:org"}, |
| 73 | expected: true, |
| 74 | }, |
| 75 | { |
| 76 | name: "has parent scope (write:org grants read:org)", |
| 77 | scopeInfo: &ToolScopeInfo{ |
| 78 | RequiredScopes: []string{"read:org"}, |
| 79 | AcceptedScopes: []string{"read:org", "write:org", "admin:org"}, |
| 80 | }, |
| 81 | userScopes: []string{"write:org"}, |
| 82 | expected: true, |
| 83 | }, |
| 84 | { |
| 85 | name: "missing required scope", |
| 86 | scopeInfo: &ToolScopeInfo{ |
| 87 | RequiredScopes: []string{"read:org"}, |
| 88 | AcceptedScopes: []string{"read:org", "write:org", "admin:org"}, |
| 89 | }, |
| 90 | userScopes: []string{"repo"}, |
| 91 | expected: false, |
| 92 | }, |
| 93 | { |
| 94 | name: "no scope required", |
| 95 | scopeInfo: &ToolScopeInfo{ |
| 96 | RequiredScopes: []string{}, |
| 97 | AcceptedScopes: []string{}, |
| 98 | }, |
| 99 | userScopes: []string{}, |
| 100 | expected: true, |
| 101 | }, |
| 102 | { |
| 103 | name: "nil scope info", |
| 104 | scopeInfo: nil, |
| 105 | userScopes: []string{}, |
| 106 | expected: true, |
| 107 | }, |
nothing calls this directly
no test coverage detected