mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: remove middleware to request version and entitlement warnings (#12750)
This cleans up `root.go` a bit, adds tests for middleware HTTP transport functions, and removes two HTTP requests we always always performed previously when executing *any* client command. It should improve CLI performance (especially for users with higher latency).
This commit is contained in:
@ -3,6 +3,7 @@ package coderd_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -197,6 +198,40 @@ func TestEntitlements(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestEntitlements_HeaderWarnings(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("ExistForAdmin", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
adminClient, _ := coderdenttest.New(t, &coderdenttest.Options{
|
||||
AuditLogging: true,
|
||||
LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
AllFeatures: false,
|
||||
},
|
||||
})
|
||||
//nolint:gocritic // This isn't actually bypassing any RBAC checks
|
||||
res, err := adminClient.Request(context.Background(), http.MethodGet, "/api/v2/users/me", nil)
|
||||
require.NoError(t, err)
|
||||
defer res.Body.Close()
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
require.NotEmpty(t, res.Header.Values(codersdk.EntitlementsWarningHeader))
|
||||
})
|
||||
t.Run("NoneForNormalUser", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{
|
||||
AuditLogging: true,
|
||||
LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
AllFeatures: false,
|
||||
},
|
||||
})
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
res, err := anotherClient.Request(context.Background(), http.MethodGet, "/api/v2/users/me", nil)
|
||||
require.NoError(t, err)
|
||||
defer res.Body.Close()
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
require.Empty(t, res.Header.Values(codersdk.EntitlementsWarningHeader))
|
||||
})
|
||||
}
|
||||
|
||||
func TestAuditLogging(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Enabled", func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user