(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestExternalScopeNames(t *testing.T) { |
| 12 | t.Parallel() |
| 13 | |
| 14 | names := ExternalScopeNames() |
| 15 | require.NotEmpty(t, names) |
| 16 | |
| 17 | // Ensure sorted ascending |
| 18 | sorted := append([]string(nil), names...) |
| 19 | slices.Sort(sorted) |
| 20 | require.Equal(t, sorted, names) |
| 21 | |
| 22 | // Ensure each entry expands to site-only |
| 23 | for _, name := range names { |
| 24 | // Skip `all` and `application_connect` since they do not |
| 25 | // expand into a low level scope. |
| 26 | // They are handled differently. |
| 27 | if name == string(ScopeAll) || name == string(ScopeApplicationConnect) { |
| 28 | continue |
| 29 | } |
| 30 | |
| 31 | // Composite coder:* scopes expand to one or more site permissions. |
| 32 | if strings.HasPrefix(name, "coder:") { |
| 33 | s, err := ScopeName(name).Expand() |
| 34 | require.NoErrorf(t, err, "catalog entry should expand: %s", name) |
| 35 | require.NotEmpty(t, s.Site) |
| 36 | expected, ok := CompositeSitePermissions(ScopeName(name)) |
| 37 | require.Truef(t, ok, "expected composite scope definition: %s", name) |
| 38 | require.ElementsMatchf(t, expected, s.Site, "unexpected expanded permissions for %s", name) |
| 39 | require.Empty(t, s.ByOrgID) |
| 40 | require.Empty(t, s.User) |
| 41 | continue |
| 42 | } |
| 43 | |
| 44 | // Low-level scopes must parse to a single permission. |
| 45 | res, act, ok := parseLowLevelScope(ScopeName(name)) |
| 46 | require.Truef(t, ok, "catalog entry should parse: %s", name) |
| 47 | |
| 48 | s, err := ScopeName(name).Expand() |
| 49 | require.NoErrorf(t, err, "catalog entry should expand: %s", name) |
| 50 | require.Len(t, s.Site, 1) |
| 51 | require.Equal(t, res, s.Site[0].ResourceType) |
| 52 | require.Equal(t, act, s.Site[0].Action) |
| 53 | require.Empty(t, s.ByOrgID) |
| 54 | require.Empty(t, s.User) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestIsExternalScope(t *testing.T) { |
| 59 | t.Parallel() |
nothing calls this directly
no test coverage detected