mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
75 lines
2.1 KiB
4 years ago
|
// Copyright 2019 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 migrations
|
||
|
|
||
|
import (
|
||
4 years ago
|
"path/filepath"
|
||
4 years ago
|
"testing"
|
||
|
|
||
4 years ago
|
"code.gitea.io/gitea/models"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
4 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestMigrateWhiteBlocklist(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
4 years ago
|
|
||
3 years ago
|
adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
|
||
|
nonAdminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
|
||
4 years ago
|
|
||
4 years ago
|
setting.Migrations.AllowedDomains = []string{"github.com"}
|
||
|
assert.NoError(t, Init())
|
||
|
|
||
4 years ago
|
err := IsMigrateURLAllowed("https://gitlab.com/gitlab/gitlab.git", nonAdminUser)
|
||
4 years ago
|
assert.Error(t, err)
|
||
|
|
||
4 years ago
|
err = IsMigrateURLAllowed("https://github.com/go-gitea/gitea.git", nonAdminUser)
|
||
4 years ago
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
err = IsMigrateURLAllowed("https://gITHUb.com/go-gitea/gitea.git", nonAdminUser)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
setting.Migrations.AllowedDomains = []string{}
|
||
|
setting.Migrations.BlockedDomains = []string{"github.com"}
|
||
|
assert.NoError(t, Init())
|
||
|
|
||
4 years ago
|
err = IsMigrateURLAllowed("https://gitlab.com/gitlab/gitlab.git", nonAdminUser)
|
||
4 years ago
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
err = IsMigrateURLAllowed("https://github.com/go-gitea/gitea.git", nonAdminUser)
|
||
|
assert.Error(t, err)
|
||
|
|
||
|
err = IsMigrateURLAllowed("https://10.0.0.1/go-gitea/gitea.git", nonAdminUser)
|
||
4 years ago
|
assert.Error(t, err)
|
||
4 years ago
|
|
||
4 years ago
|
setting.Migrations.AllowLocalNetworks = true
|
||
|
err = IsMigrateURLAllowed("https://10.0.0.1/go-gitea/gitea.git", nonAdminUser)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
old := setting.ImportLocalPaths
|
||
|
setting.ImportLocalPaths = false
|
||
|
|
||
4 years ago
|
err = IsMigrateURLAllowed("/home/foo/bar/goo", adminUser)
|
||
4 years ago
|
assert.Error(t, err)
|
||
|
|
||
|
setting.ImportLocalPaths = true
|
||
4 years ago
|
abs, err := filepath.Abs(".")
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
err = IsMigrateURLAllowed(abs, adminUser)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
err = IsMigrateURLAllowed(abs, nonAdminUser)
|
||
|
assert.Error(t, err)
|
||
|
|
||
|
nonAdminUser.AllowImportLocal = true
|
||
|
err = IsMigrateURLAllowed(abs, nonAdminUser)
|
||
4 years ago
|
assert.NoError(t, err)
|
||
|
|
||
|
setting.ImportLocalPaths = old
|
||
4 years ago
|
}
|