diff options
author | 6543 <6543@obermui.de> | 2021-03-01 01:47:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 01:47:30 +0100 |
commit | a4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8 (patch) | |
tree | 92edf61ff2447e067a676832844a129050b4ec0f /models/repo_transfer_test.go | |
parent | e0900310c4354311362ef69d15c302c215eaa2a2 (diff) | |
download | gitea-a4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8.tar.gz gitea-a4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8.zip |
Repository transfer has to be confirmed, if user can not create repo for new owner (#14792)
* make repo as "pending transfer" if on transfer start doer has no right to create repo in new destination
* if new pending transfer ocured, create UI & Mail notifications
Diffstat (limited to 'models/repo_transfer_test.go')
-rw-r--r-- | models/repo_transfer_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/models/repo_transfer_test.go b/models/repo_transfer_test.go new file mode 100644 index 0000000000..55aedac95d --- /dev/null +++ b/models/repo_transfer_test.go @@ -0,0 +1,54 @@ +// 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 models + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRepositoryTransfer(t *testing.T) { + + assert.NoError(t, PrepareTestDatabase()) + + doer := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + + transfer, err := GetPendingRepositoryTransfer(repo) + assert.NoError(t, err) + assert.NotNil(t, transfer) + + // Cancel transfer + assert.NoError(t, CancelRepositoryTransfer(repo)) + + transfer, err = GetPendingRepositoryTransfer(repo) + assert.Error(t, err) + assert.Nil(t, transfer) + assert.True(t, IsErrNoPendingTransfer(err)) + + user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + + assert.NoError(t, CreatePendingRepositoryTransfer(doer, user2, repo.ID, nil)) + + transfer, err = GetPendingRepositoryTransfer(repo) + assert.Nil(t, err) + assert.NoError(t, transfer.LoadAttributes()) + assert.Equal(t, "user2", transfer.Recipient.Name) + + user6 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + + // Only transfer can be started at any given time + err = CreatePendingRepositoryTransfer(doer, user6, repo.ID, nil) + assert.Error(t, err) + assert.True(t, IsErrRepoTransferInProgress(err)) + + // Unknown user + err = CreatePendingRepositoryTransfer(doer, &User{ID: 1000, LowerName: "user1000"}, repo.ID, nil) + assert.Error(t, err) + + // Cancel transfer + assert.NoError(t, CancelRepositoryTransfer(repo)) +} |