feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
This commit is contained in:
commit
bb7968b612
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newTokenAutoGroupsContext() *gin.Context {
|
||||
gin.SetMode(gin.TestMode)
|
||||
ctx, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
return ctx
|
||||
}
|
||||
|
||||
func TestSetupContextForTokenPreservesCustomAutoGroupsOrder(t *testing.T) {
|
||||
ctx := newTokenAutoGroupsContext()
|
||||
token := &model.Token{Id: 1, UserId: 2, AutoGroups: `["vip","default"]`}
|
||||
|
||||
require.NoError(t, SetupContextForToken(ctx, token))
|
||||
value, ok := common.GetContextKey(ctx, constant.ContextKeyTokenAutoGroups)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, []string{"vip", "default"}, value)
|
||||
}
|
||||
|
||||
func TestSetupContextForTokenTreatsStoredEmptyArrayAsInheritance(t *testing.T) {
|
||||
ctx := newTokenAutoGroupsContext()
|
||||
token := &model.Token{Id: 1, UserId: 2, AutoGroups: `[]`}
|
||||
|
||||
require.NoError(t, SetupContextForToken(ctx, token))
|
||||
_, ok := common.GetContextKey(ctx, constant.ContextKeyTokenAutoGroups)
|
||||
assert.False(t, ok)
|
||||
}
|
||||
|
||||
func TestSetupContextForTokenMalformedAutoGroupsFailsClosed(t *testing.T) {
|
||||
ctx := newTokenAutoGroupsContext()
|
||||
token := &model.Token{Id: 1, UserId: 2, AutoGroups: `not-json`}
|
||||
|
||||
require.NoError(t, SetupContextForToken(ctx, token))
|
||||
value, ok := common.GetContextKey(ctx, constant.ContextKeyTokenAutoGroups)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, []string{}, value)
|
||||
}
|
||||
Reference in new issue
Block a user