|
|
|
@ -9,6 +9,7 @@ import ( |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
"code.gitea.io/gitea/modules/test" |
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
) |
|
|
|
@ -92,20 +93,8 @@ func Test_isGitRawOrLFSPath(t *testing.T) { |
|
|
|
|
true, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
lfsTests := []string{ |
|
|
|
|
"/owner/repo/info/lfs/", |
|
|
|
|
"/owner/repo/info/lfs/objects/batch", |
|
|
|
|
"/owner/repo/info/lfs/objects/oid/filename", |
|
|
|
|
"/owner/repo/info/lfs/objects/oid", |
|
|
|
|
"/owner/repo/info/lfs/objects", |
|
|
|
|
"/owner/repo/info/lfs/verify", |
|
|
|
|
"/owner/repo/info/lfs/locks", |
|
|
|
|
"/owner/repo/info/lfs/locks/verify", |
|
|
|
|
"/owner/repo/info/lfs/locks/123/unlock", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
origLFSStartServer := setting.LFS.StartServer |
|
|
|
|
|
|
|
|
|
defer test.MockVariableValue(&setting.LFS.StartServer)() |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.path, func(t *testing.T) { |
|
|
|
|
req, _ := http.NewRequest("POST", "http://localhost"+tt.path, nil) |
|
|
|
@ -116,6 +105,18 @@ func Test_isGitRawOrLFSPath(t *testing.T) { |
|
|
|
|
assert.Equal(t, tt.want, newAuthPathDetector(req).isGitRawOrAttachOrLFSPath()) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lfsTests := []string{ |
|
|
|
|
"/owner/repo/info/lfs/", |
|
|
|
|
"/owner/repo/info/lfs/objects/batch", |
|
|
|
|
"/owner/repo/info/lfs/objects/oid/filename", |
|
|
|
|
"/owner/repo/info/lfs/objects/oid", |
|
|
|
|
"/owner/repo/info/lfs/objects", |
|
|
|
|
"/owner/repo/info/lfs/verify", |
|
|
|
|
"/owner/repo/info/lfs/locks", |
|
|
|
|
"/owner/repo/info/lfs/locks/verify", |
|
|
|
|
"/owner/repo/info/lfs/locks/123/unlock", |
|
|
|
|
} |
|
|
|
|
for _, tt := range lfsTests { |
|
|
|
|
t.Run(tt, func(t *testing.T) { |
|
|
|
|
req, _ := http.NewRequest("POST", tt, nil) |
|
|
|
@ -128,5 +129,27 @@ func Test_isGitRawOrLFSPath(t *testing.T) { |
|
|
|
|
assert.Equalf(t, setting.LFS.StartServer, got, "isGitOrLFSPath(%q) = %v, want %v", tt, got, setting.LFS.StartServer) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
setting.LFS.StartServer = origLFSStartServer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Test_isFeedRequest(t *testing.T) { |
|
|
|
|
tests := []struct { |
|
|
|
|
want bool |
|
|
|
|
path string |
|
|
|
|
}{ |
|
|
|
|
{true, "/user.rss"}, |
|
|
|
|
{true, "/user/repo.atom"}, |
|
|
|
|
{false, "/user/repo"}, |
|
|
|
|
{false, "/use/repo/file.rss"}, |
|
|
|
|
|
|
|
|
|
{true, "/org/repo/rss/branch/xxx"}, |
|
|
|
|
{true, "/org/repo/atom/tag/xxx"}, |
|
|
|
|
{false, "/org/repo/branch/main/rss/any"}, |
|
|
|
|
{false, "/org/atom/any"}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.path, func(t *testing.T) { |
|
|
|
|
req, _ := http.NewRequest("GET", "http://localhost"+tt.path, nil) |
|
|
|
|
assert.Equal(t, tt.want, newAuthPathDetector(req).isFeedRequest(req)) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|