Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package lfs
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
perm_model "code.gitcaddy.com/server/v3/models/perm"
|
|
repo_model "code.gitcaddy.com/server/v3/models/repo"
|
|
"code.gitcaddy.com/server/v3/models/unittest"
|
|
"code.gitcaddy.com/server/v3/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
unittest.MainTest(m)
|
|
}
|
|
|
|
func TestAuthenticate(t *testing.T) {
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
token2, _ := GetLFSAuthTokenWithBearer(AuthTokenOptions{Op: "download", UserID: 2, RepoID: 1})
|
|
_, token2, _ = strings.Cut(token2, " ")
|
|
ctx, _ := contexttest.MockContext(t, "/")
|
|
|
|
t.Run("handleLFSToken", func(t *testing.T) {
|
|
u, err := handleLFSToken(ctx, "", repo1, perm_model.AccessModeRead)
|
|
require.Error(t, err)
|
|
assert.Nil(t, u)
|
|
|
|
u, err = handleLFSToken(ctx, "invalid", repo1, perm_model.AccessModeRead)
|
|
require.Error(t, err)
|
|
assert.Nil(t, u)
|
|
|
|
u, err = handleLFSToken(ctx, token2, repo1, perm_model.AccessModeRead)
|
|
require.NoError(t, err)
|
|
assert.EqualValues(t, 2, u.ID)
|
|
})
|
|
|
|
t.Run("authenticate", func(t *testing.T) {
|
|
const prefixBearer = "Bearer "
|
|
assert.False(t, authenticate(ctx, repo1, "", true, false))
|
|
assert.False(t, authenticate(ctx, repo1, prefixBearer+"invalid", true, false))
|
|
assert.True(t, authenticate(ctx, repo1, prefixBearer+token2, true, false))
|
|
})
|
|
}
|