mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-17 00:06:35 +00:00
Followup to https://codeberg.org/forgejo/forgejo/pulls/9830, which greatly simplified the tests that previously had to supply a csrf token in values map, but left behind the more complex funcs with empty maps. Also fixed a few typos which popped up in the diff. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10119 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
92 lines
3.1 KiB
Go
92 lines
3.1 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"forgejo.org/models/admin"
|
|
repo_model "forgejo.org/models/repo"
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/structs"
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/services/migrations"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRepoMigrateWithCredentials(t *testing.T) {
|
|
onApplicationRun(t, func(t *testing.T, u *url.URL) {
|
|
defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)()
|
|
require.NoError(t, migrations.Init())
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
session := loginUser(t, "user2")
|
|
|
|
t.Run("Incorrect credentials", func(t *testing.T) {
|
|
session.MakeRequest(t, NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{
|
|
"clone_addr": u.JoinPath("/user2/repo2").String(),
|
|
"auth_username": "user2",
|
|
"auth_password": userPassword + "1",
|
|
"uid": "2",
|
|
"repo_name": "migrating-with-credentials",
|
|
"service": "1",
|
|
}), http.StatusSeeOther)
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "migrating-with-credentials"}, "is_empty = true")
|
|
unittest.AssertExistsAndLoadBean(t, &admin.Task{
|
|
RepoID: repo.ID,
|
|
Type: structs.TaskTypeMigrateRepo,
|
|
Status: structs.TaskStatusFailed,
|
|
})
|
|
})
|
|
|
|
t.Run("Normal", func(t *testing.T) {
|
|
session.MakeRequest(t, NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{
|
|
"clone_addr": u.JoinPath("/user2/repo2").String(),
|
|
"auth_username": "user2",
|
|
"auth_password": userPassword,
|
|
"uid": "2",
|
|
"repo_name": "migrating-with-credentials-2",
|
|
"service": "1",
|
|
}), http.StatusSeeOther)
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "migrating-with-credentials-2"}, "is_empty = false")
|
|
unittest.AssertExistsAndLoadBean(t, &admin.Task{
|
|
RepoID: repo.ID,
|
|
Type: structs.TaskTypeMigrateRepo,
|
|
Status: structs.TaskStatusFinished,
|
|
})
|
|
})
|
|
|
|
t.Run("Dangerous credential", func(t *testing.T) {
|
|
// Temporarily change the password
|
|
dangerousPassword := "some`echo foo`thing"
|
|
require.NoError(t, user2.SetPassword(dangerousPassword))
|
|
require.NoError(t, user_model.UpdateUserCols(t.Context(), user2, "passwd", "passwd_hash_algo", "salt"))
|
|
|
|
session = loginUserWithPassword(t, "user2", dangerousPassword)
|
|
|
|
session.MakeRequest(t, NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{
|
|
"clone_addr": u.JoinPath("/user2/repo2").String(),
|
|
"auth_username": "user2",
|
|
"auth_password": dangerousPassword,
|
|
"uid": "2",
|
|
"repo_name": "migrating-with-credentials-3",
|
|
"service": "1",
|
|
}), http.StatusSeeOther)
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "migrating-with-credentials-3"}, "is_empty = false")
|
|
unittest.AssertExistsAndLoadBean(t, &admin.Task{
|
|
RepoID: repo.ID,
|
|
Type: structs.TaskTypeMigrateRepo,
|
|
Status: structs.TaskStatusFinished,
|
|
})
|
|
})
|
|
})
|
|
}
|