-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport #33840 by wxiaoguang Fix #33839 --------- Co-authored-by: wxiaoguang <[email protected]>
- Loading branch information
1 parent
523a84e
commit a2c6ecc
Showing
11 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package backend | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/test" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestToInternalLFSURL(t *testing.T) { | ||
defer test.MockVariableValue(&setting.LocalURL, "http://localurl/")() | ||
defer test.MockVariableValue(&setting.AppSubURL, "/sub")() | ||
cases := []struct { | ||
url string | ||
expected string | ||
}{ | ||
{"http://appurl/any", ""}, | ||
{"http://appurl/sub/any", ""}, | ||
{"http://appurl/sub/owner/repo/any", ""}, | ||
{"http://appurl/sub/owner/repo/info/any", ""}, | ||
{"http://appurl/sub/owner/repo/info/lfs/any", "http://localurl/api/internal/repo/owner/repo/info/lfs/any"}, | ||
} | ||
for _, c := range cases { | ||
assert.Equal(t, c.expected, toInternalLFSURL(c.url), c.url) | ||
} | ||
} | ||
|
||
func TestIsInternalLFSURL(t *testing.T) { | ||
defer test.MockVariableValue(&setting.LocalURL, "http://localurl/")() | ||
defer test.MockVariableValue(&setting.InternalToken, "mock-token")() | ||
cases := []struct { | ||
url string | ||
expected bool | ||
}{ | ||
{"", false}, | ||
{"http://otherurl/api/internal/repo/owner/repo/info/lfs/any", false}, | ||
{"http://localurl/api/internal/repo/owner/repo/info/lfs/any", true}, | ||
{"http://localurl/api/internal/repo/owner/repo/info", false}, | ||
{"http://localurl/api/internal/misc/owner/repo/info/lfs/any", false}, | ||
{"http://localurl/api/internal/owner/repo/info/lfs/any", false}, | ||
{"http://localurl/api/internal/foo/bar", false}, | ||
} | ||
for _, c := range cases { | ||
req := newInternalRequestLFS(context.Background(), c.url, "GET", nil, nil) | ||
assert.Equal(t, c.expected, req != nil, c.url) | ||
assert.Equal(t, c.expected, isInternalLFSURL(c.url), c.url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters