2021-03-18 19:28:47 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-16 20:55:33 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-03-18 19:28:47 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-11-16 20:55:33 +05:30
|
|
|
"code.gitea.io/gitea/services/migrations"
|
2021-03-18 19:28:47 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMigrateLocalPath(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-03-18 19:28:47 +05:30
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User)
|
2021-03-18 19:28:47 +05:30
|
|
|
|
|
|
|
old := setting.ImportLocalPaths
|
|
|
|
setting.ImportLocalPaths = true
|
|
|
|
|
2021-09-22 11:08:34 +05:30
|
|
|
lowercasePath, err := os.MkdirTemp("", "lowercase") // may not be lowercase because MkdirTemp creates a random directory name which may be mixedcase
|
2021-03-18 19:28:47 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
defer os.RemoveAll(lowercasePath)
|
|
|
|
|
|
|
|
err = migrations.IsMigrateURLAllowed(lowercasePath, adminUser)
|
|
|
|
assert.NoError(t, err, "case lowercase path")
|
|
|
|
|
2021-09-22 11:08:34 +05:30
|
|
|
mixedcasePath, err := os.MkdirTemp("", "mIxeDCaSe")
|
2021-03-18 19:28:47 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
defer os.RemoveAll(mixedcasePath)
|
|
|
|
|
|
|
|
err = migrations.IsMigrateURLAllowed(mixedcasePath, adminUser)
|
|
|
|
assert.NoError(t, err, "case mixedcase path")
|
|
|
|
|
|
|
|
setting.ImportLocalPaths = old
|
|
|
|
}
|