mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Fix object storage path handling (#27024)
Object storage path rules: * No single `/` or `.`, use empty string for root path * Need to use trailing `/` for a list prefix to distinguish a "dir/"
This commit is contained in:
		| @@ -31,6 +31,40 @@ func TestMinioStorageIterator(t *testing.T) { | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func TestMinioStoragePath(t *testing.T) { | ||||
| 	m := &MinioStorage{basePath: ""} | ||||
| 	assert.Equal(t, "", m.buildMinioPath("/")) | ||||
| 	assert.Equal(t, "", m.buildMinioPath(".")) | ||||
| 	assert.Equal(t, "a", m.buildMinioPath("/a")) | ||||
| 	assert.Equal(t, "a/b", m.buildMinioPath("/a/b/")) | ||||
| 	assert.Equal(t, "", m.buildMinioDirPrefix("")) | ||||
| 	assert.Equal(t, "a/", m.buildMinioDirPrefix("/a/")) | ||||
|  | ||||
| 	m = &MinioStorage{basePath: "/"} | ||||
| 	assert.Equal(t, "", m.buildMinioPath("/")) | ||||
| 	assert.Equal(t, "", m.buildMinioPath(".")) | ||||
| 	assert.Equal(t, "a", m.buildMinioPath("/a")) | ||||
| 	assert.Equal(t, "a/b", m.buildMinioPath("/a/b/")) | ||||
| 	assert.Equal(t, "", m.buildMinioDirPrefix("")) | ||||
| 	assert.Equal(t, "a/", m.buildMinioDirPrefix("/a/")) | ||||
|  | ||||
| 	m = &MinioStorage{basePath: "/base"} | ||||
| 	assert.Equal(t, "base", m.buildMinioPath("/")) | ||||
| 	assert.Equal(t, "base", m.buildMinioPath(".")) | ||||
| 	assert.Equal(t, "base/a", m.buildMinioPath("/a")) | ||||
| 	assert.Equal(t, "base/a/b", m.buildMinioPath("/a/b/")) | ||||
| 	assert.Equal(t, "base/", m.buildMinioDirPrefix("")) | ||||
| 	assert.Equal(t, "base/a/", m.buildMinioDirPrefix("/a/")) | ||||
|  | ||||
| 	m = &MinioStorage{basePath: "/base/"} | ||||
| 	assert.Equal(t, "base", m.buildMinioPath("/")) | ||||
| 	assert.Equal(t, "base", m.buildMinioPath(".")) | ||||
| 	assert.Equal(t, "base/a", m.buildMinioPath("/a")) | ||||
| 	assert.Equal(t, "base/a/b", m.buildMinioPath("/a/b/")) | ||||
| 	assert.Equal(t, "base/", m.buildMinioDirPrefix("")) | ||||
| 	assert.Equal(t, "base/a/", m.buildMinioDirPrefix("/a/")) | ||||
| } | ||||
|  | ||||
| func TestS3StorageBadRequest(t *testing.T) { | ||||
| 	if os.Getenv("CI") == "" { | ||||
| 		t.Skip("S3Storage not present outside of CI") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user