aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-12-15 16:21:16 +0000
committerGitHub <noreply@github.com>2019-12-15 16:21:16 +0000
commit60b31c8f01cbfdad5435510a9b8b05f84fe38a78 (patch)
tree388b4f789866e6908f4ad9444e08ee1e982272b4 /integrations
parentf6b29012e09d5f7770a0b1ea8659da5172e155b3 (diff)
downloadgitea-60b31c8f01cbfdad5435510a9b8b05f84fe38a78.tar.gz
gitea-60b31c8f01cbfdad5435510a9b8b05f84fe38a78.zip
Fix the intermittent TestGPGGit failures (#9360)
* Fix the intermittent TestGPGGit failures Reattempt to open the listener if the port is busy with a delay up to a second Switch from generating a private key each time, just use a known good key
Diffstat (limited to 'integrations')
-rw-r--r--integrations/git_helper_for_declarative_test.go6
-rw-r--r--integrations/gpg_git_test.go66
-rw-r--r--integrations/private-testing.key81
3 files changed, 124 insertions, 29 deletions
diff --git a/integrations/git_helper_for_declarative_test.go b/integrations/git_helper_for_declarative_test.go
index b334c55d3c..5838b9e512 100644
--- a/integrations/git_helper_for_declarative_test.go
+++ b/integrations/git_helper_for_declarative_test.go
@@ -87,6 +87,12 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
u, err := url.Parse(setting.AppURL)
assert.NoError(t, err)
listener, err := net.Listen("tcp", u.Host)
+ i := 0
+ for err != nil && i <= 10 {
+ time.Sleep(100 * time.Millisecond)
+ listener, err = net.Listen("tcp", u.Host)
+ i++
+ }
assert.NoError(t, err)
u.Host = listener.Addr().String()
diff --git a/integrations/gpg_git_test.go b/integrations/gpg_git_test.go
index a31dec29bb..e01f0f31c1 100644
--- a/integrations/gpg_git_test.go
+++ b/integrations/gpg_git_test.go
@@ -10,7 +10,6 @@ import (
"io/ioutil"
"net/url"
"os"
- "path/filepath"
"testing"
"code.gitea.io/gitea/models"
@@ -40,8 +39,11 @@ func TestGPGGit(t *testing.T) {
defer os.Setenv("GNUPGHOME", oldGNUPGHome)
// Need to create a root key
- rootKeyPair, err := createGPGKey(tmpDir, "gitea", "gitea@fake.local")
+ rootKeyPair, err := importTestingKey(tmpDir, "gitea", "gitea@fake.local")
assert.NoError(t, err)
+ if err != nil {
+ assert.FailNow(t, "Unable to import rootKeyPair")
+ }
rootKeyID := rootKeyPair.PrimaryKey.KeyIdShortString()
@@ -125,6 +127,11 @@ func TestGPGGit(t *testing.T) {
testCtx := NewAPITestContext(t, username, "initial-unsigned")
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
+ assert.NotNil(t, response.Verification)
+ if response.Verification == nil {
+ assert.FailNow(t, "no verification provided with response! %v", response)
+ return
+ }
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
@@ -134,6 +141,11 @@ func TestGPGGit(t *testing.T) {
}))
t.Run("CreateCRUDFile-ParentSigned-always", crudActionCreateFile(
t, testCtx, user, "parentsigned", "parentsigned-always", "signed-parent2.txt", func(t *testing.T, response api.FileResponse) {
+ assert.NotNil(t, response.Verification)
+ if response.Verification == nil {
+ assert.FailNow(t, "no verification provided with response! %v", response)
+ return
+ }
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
@@ -152,6 +164,11 @@ func TestGPGGit(t *testing.T) {
testCtx := NewAPITestContext(t, username, "initial-unsigned")
t.Run("CreateCRUDFile-Always-ParentSigned", crudActionCreateFile(
t, testCtx, user, "always", "always-parentsigned", "signed-always-parentsigned.txt", func(t *testing.T, response api.FileResponse) {
+ assert.NotNil(t, response.Verification)
+ if response.Verification == nil {
+ assert.FailNow(t, "no verification provided with response! %v", response)
+ return
+ }
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
@@ -171,7 +188,15 @@ func TestGPGGit(t *testing.T) {
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
t.Run("CheckMasterBranchSigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
assert.NotNil(t, branch.Commit)
+ if branch.Commit == nil {
+ assert.FailNow(t, "no commit provided with branch! %v", branch)
+ return
+ }
assert.NotNil(t, branch.Commit.Verification)
+ if branch.Commit.Verification == nil {
+ assert.FailNow(t, "no verification provided with branch commit! %v", branch.Commit)
+ return
+ }
assert.True(t, branch.Commit.Verification.Verified)
if !branch.Commit.Verification.Verified {
t.FailNow()
@@ -318,43 +343,26 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *models.User, f
}, callback...)
}
-func createGPGKey(tmpDir, name, email string) (*openpgp.Entity, error) {
- keyPair, err := openpgp.NewEntity(name, "test", email, nil)
- if err != nil {
+func importTestingKey(tmpDir, name, email string) (*openpgp.Entity, error) {
+ if _, _, err := process.GetManager().Exec("gpg --import integrations/private-testing.key", "gpg", "--import", "integrations/private-testing.key"); err != nil {
return nil, err
}
-
- for _, id := range keyPair.Identities {
- err := id.SelfSignature.SignUserId(id.UserId.Id, keyPair.PrimaryKey, keyPair.PrivateKey, nil)
- if err != nil {
- return nil, err
- }
- }
-
- keyFile := filepath.Join(tmpDir, "temporary.key")
- keyWriter, err := os.Create(keyFile)
+ keyringFile, err := os.Open("integrations/private-testing.key")
if err != nil {
return nil, err
}
- defer keyWriter.Close()
- defer os.Remove(keyFile)
+ defer keyringFile.Close()
- w, err := armor.Encode(keyWriter, openpgp.PrivateKeyType, nil)
+ block, err := armor.Decode(keyringFile)
if err != nil {
return nil, err
}
- defer w.Close()
- keyPair.SerializePrivate(w, nil)
- if err := w.Close(); err != nil {
- return nil, err
- }
- if err := keyWriter.Close(); err != nil {
- return nil, err
+ keyring, err := openpgp.ReadKeyRing(block.Body)
+ if err != nil {
+ return nil, fmt.Errorf("Keyring access failed: '%v'", err)
}
- if _, _, err := process.GetManager().Exec("gpg --import temporary.key", "gpg", "--import", keyFile); err != nil {
- return nil, err
- }
- return keyPair, nil
+ // There should only be one entity in this file.
+ return keyring[0], nil
}
diff --git a/integrations/private-testing.key b/integrations/private-testing.key
new file mode 100644
index 0000000000..c39a08d38f
--- /dev/null
+++ b/integrations/private-testing.key
@@ -0,0 +1,81 @@
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+
+lQVYBF3190cBDADpfh1CvNtLl8N6lJQ03jymeE8h2ocvT61stAj31eefiOvZPDyx
+n0kRztBcrQ1OITBEslYqKiYHVfVptscIWf+5bARoHnLQIgpJEio00ggqO3AP8lIZ
+uiy9/ARDVgyPl3WgMza/J3Z7W0sBJTtN/6W35i+eNEY4Q0mScmNIVc75oo5ey/pL
+JSF0qumiy94o38dy6Vk2dPEf5LyxJWoA4dLvj49LL/QGPqnsAXAQXr1zULaRuwf2
+a8oKebr3m9wVkZcaH86duUmkU822k6OZSSxWCxZFFGVkC/VaA0uUjIL4a6SQqOOr
+PPOttmCLXJrtvpFdRwJ4PNwr9r2nPDDLwoajLJ8zo5jRumzwvkK9vALkY0BPuVoC
+qFdGY+2SGYKa4FTE7Mri/5j0NhWplhbcdGRe5doGDxJHbIN2UO21XjDlTBcscKep
+mWPVE2cdJrspYaZ9O0L6vhMVwGyyk+Qxmf6NbDw0q63AtqVe9qwbr2O3Irxseftw
+uWuSuLXzp+SMh/0AEQEAAQAL/2ExopuDwuNSHsh5bcIeGnAPV51Xentqtt2viaYk
+0AB8PfTVGsyzafa0OM7DKG0z6oRGGhD+L4tRMFGbiHlFAWqdeK4gsplJ+i8VlSUc
+otJ1oH262IsmEPban6mp+ZuSKCASAYGLu0m5JF0rMucSeli1RHAeAXbtJ4SDAin7
+sib/EDWMwjkikS0f8hZWt7kbAcqnMQA2qKKmlBdHZDtOxX/8KeFZ6kHpNtFrfcsK
+rOECIaVDDhr5HobCyl3E7tW5nrlrvSUkLVFl0IjcypqfzDlZp04PMdswhkdfBhu+
+0iY4K+d4uMPMzcpF1+mcn8C+7XK7jOqZysQa42bqgFHWEqljjJiUCuXfHbxnZWls
+0R2j9FLgTqtPQ33f3zMjhOyvdiy1DmfzU9MSu/I0VqCJnq6AwlW5rBQ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