mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Dbauthz is now default, remove out of experimental (#6650)
* feat: dbauthz always on, out of experimental * Add ability to do rbac checks in unit tests * Remove AuthorizeAllEndpoints * Remove duplicate rbac checks
This commit is contained in:
@@ -2,34 +2,15 @@ package coderdtest_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/coderd/coderdtest"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
func TestAuthorizeAllEndpoints(t *testing.T) {
|
||||
if strings.Contains(os.Getenv("CODER_EXPERIMENTS_TEST"), string(codersdk.ExperimentAuthzQuerier)) {
|
||||
t.Skip("Skipping TestAuthorizeAllEndpoints for authz_querier experiment")
|
||||
}
|
||||
t.Parallel()
|
||||
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
|
||||
// Required for any subdomain-based proxy tests to pass.
|
||||
AppHostname: "*.test.coder.com",
|
||||
Authorizer: &coderdtest.RecordingAuthorizer{Wrapped: &coderdtest.FakeAuthorizer{}},
|
||||
IncludeProvisionerDaemon: true,
|
||||
})
|
||||
admin := coderdtest.CreateFirstUser(t, client)
|
||||
a := coderdtest.NewAuthTester(context.Background(), t, client, api, admin)
|
||||
skipRoute, assertRoute := coderdtest.AGPLRoutes(a)
|
||||
a.Test(context.Background(), assertRoute, skipRoute)
|
||||
}
|
||||
|
||||
func TestAuthzRecorder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -81,6 +62,42 @@ func TestAuthzRecorder(t *testing.T) {
|
||||
rec.AssertActor(t, a, aPairs...)
|
||||
require.NoError(t, rec.AllAsserted(), "all assertions should have been made")
|
||||
})
|
||||
|
||||
t.Run("AuthorizeOutOfOrder", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rec := &coderdtest.RecordingAuthorizer{
|
||||
Wrapped: &coderdtest.FakeAuthorizer{},
|
||||
}
|
||||
sub := coderdtest.RandomRBACSubject()
|
||||
pairs := fuzzAuthz(t, sub, rec, 10)
|
||||
rand.Shuffle(len(pairs), func(i, j int) {
|
||||
pairs[i], pairs[j] = pairs[j], pairs[i]
|
||||
})
|
||||
|
||||
rec.AssertOutOfOrder(t, sub, pairs...)
|
||||
require.NoError(t, rec.AllAsserted(), "all assertions should have been made")
|
||||
})
|
||||
|
||||
t.Run("AllCalls", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rec := &coderdtest.RecordingAuthorizer{
|
||||
Wrapped: &coderdtest.FakeAuthorizer{},
|
||||
}
|
||||
sub := coderdtest.RandomRBACSubject()
|
||||
calls := rec.AllCalls(&sub)
|
||||
pairs := make([]coderdtest.ActionObjectPair, 0, len(calls))
|
||||
for _, call := range calls {
|
||||
pairs = append(pairs, coderdtest.ActionObjectPair{
|
||||
Action: call.Action,
|
||||
Object: call.Object,
|
||||
})
|
||||
}
|
||||
|
||||
rec.AssertActor(t, sub, pairs...)
|
||||
require.NoError(t, rec.AllAsserted(), "all assertions should have been made")
|
||||
})
|
||||
}
|
||||
|
||||
// fuzzAuthzPrep has same action and object types for all calls.
|
||||
|
||||
Reference in New Issue
Block a user