2021-03-18 14:58:47 +01:00
|
|
|
// 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"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-19 13:49:59 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-03-18 14:58:47 +01:00
|
|
|
"code.gitea.io/gitea/modules/migrations"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMigrateLocalPath(t *testing.T) {
|
2021-09-19 13:49:59 +02:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2021-03-18 14:58:47 +01:00
|
|
|
|
2021-09-19 13:49:59 +02:00
|
|
|
adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
|
2021-03-18 14:58:47 +01:00
|
|
|
|
|
|
|
old := setting.ImportLocalPaths
|
|
|
|
setting.ImportLocalPaths = true
|
|
|
|
|
2021-09-22 07:38:34 +02:00
|
|
|
lowercasePath, err := os.MkdirTemp("", "lowercase") // may not be lowercase because MkdirTemp creates a random directory name which may be mixedcase
|
2021-03-18 14:58:47 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer os.RemoveAll(lowercasePath)
|
|
|
|
|
|
|
|
err = migrations.IsMigrateURLAllowed(lowercasePath, adminUser)
|
|
|
|
assert.NoError(t, err, "case lowercase path")
|
|
|
|
|
2021-09-22 07:38:34 +02:00
|
|
|
mixedcasePath, err := os.MkdirTemp("", "mIxeDCaSe")
|
2021-03-18 14:58:47 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer os.RemoveAll(mixedcasePath)
|
|
|
|
|
|
|
|
err = migrations.IsMigrateURLAllowed(mixedcasePath, adminUser)
|
|
|
|
assert.NoError(t, err, "case mixedcase path")
|
|
|
|
|
|
|
|
setting.ImportLocalPaths = old
|
|
|
|
}
|