mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
4bda39585d
# Add support for low-level API key scopes This PR adds support for fine-grained API key scopes based on RBAC resource:action pairs. It includes: 1. A new endpoint `/api/v2/auth/scopes` to list all public low-level API key scopes 2. Generated constants in the SDK for all public scopes 3. Tests to verify scope validation during token creation 4. Updated API documentation to reflect the expanded scope options The implementation allows users to create API keys with specific permissions like `workspace:read` or `template:use` instead of only the legacy `all` or `application_connect` scopes. Fixes #19847
31 lines
680 B
Go
31 lines
680 B
Go
package coderd_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
|
)
|
|
|
|
func TestListPublicLowLevelScopes(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t, nil)
|
|
|
|
res, err := client.Request(t.Context(), http.MethodGet, "/api/v2/auth/scopes", nil)
|
|
require.NoError(t, err)
|
|
defer res.Body.Close()
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
|
var got struct {
|
|
External []string `json:"external"`
|
|
}
|
|
require.NoError(t, json.NewDecoder(res.Body).Decode(&got))
|
|
|
|
want := rbac.ExternalScopeNames()
|
|
require.Equal(t, want, got.External)
|
|
}
|