Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integrations/git_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
assert.NoError(t, err)
listener, err := net.Listen("tcp", u.Host)
assert.NoError(t, err)
u.Host = listener.Addr().String()

defer func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
Expand Down
37 changes: 32 additions & 5 deletions integrations/gpg_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

func TestGPGGit(t *testing.T) {
prepareTestEnv(t)
username := "user2"

// OK Set a new GPG home
Expand Down Expand Up @@ -125,11 +126,19 @@ func TestGPGGit(t *testing.T) {
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
}))
t.Run("CreateCRUDFile-ParentSigned-always", crudActionCreateFile(
t, testCtx, user, "parentsigned", "parentsigned-always", "signed-parent2.txt", func(t *testing.T, response api.FileResponse) {
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
}))
})
Expand All @@ -144,6 +153,10 @@ func TestGPGGit(t *testing.T) {
t.Run("CreateCRUDFile-Always-ParentSigned", crudActionCreateFile(
t, testCtx, user, "always", "always-parentsigned", "signed-always-parentsigned.txt", func(t *testing.T, response api.FileResponse) {
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
}))
})
Expand All @@ -160,6 +173,10 @@ func TestGPGGit(t *testing.T) {
assert.NotNil(t, branch.Commit)
assert.NotNil(t, branch.Commit.Verification)
assert.True(t, branch.Commit.Verification.Verified)
if !branch.Commit.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", branch.Commit.Verification.Signer.Email)
}))
})
Expand All @@ -170,7 +187,8 @@ func TestGPGGit(t *testing.T) {

t.Run("AlwaysSign-Initial-CRUD-Never", func(t *testing.T) {
defer PrintCurrentTest(t)()
testCtx := NewAPITestContext(t, username, "initial-always")
testCtx := NewAPITestContext(t, username, "initial-always-never")
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
t.Run("CreateCRUDFile-Never", crudActionCreateFile(
t, testCtx, user, "master", "never", "unsigned-never.txt", func(t *testing.T, response api.FileResponse) {
assert.False(t, response.Verification.Verified)
Expand All @@ -180,13 +198,17 @@ func TestGPGGit(t *testing.T) {
setting.Repository.Signing.CRUDActions = []string{"parentsigned"}
onGiteaRun(t, func(t *testing.T, u *url.URL) {
u.Path = baseAPITestContext.GitPath()

t.Run("AlwaysSign-Initial-CRUD-ParentSigned-On-Always", func(t *testing.T) {
defer PrintCurrentTest(t)()
testCtx := NewAPITestContext(t, username, "initial-always")
testCtx := NewAPITestContext(t, username, "initial-always-parent")
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
}))
})
Expand All @@ -197,10 +219,15 @@ func TestGPGGit(t *testing.T) {

t.Run("AlwaysSign-Initial-CRUD-Always", func(t *testing.T) {
defer PrintCurrentTest(t)()
testCtx := NewAPITestContext(t, username, "initial-always")
testCtx := NewAPITestContext(t, username, "initial-always-always")
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
assert.True(t, response.Verification.Verified)
if !response.Verification.Verified {
t.FailNow()
return
}
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
}))

Expand Down Expand Up @@ -287,7 +314,7 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *models.User, f
Email: user.Email,
},
},
Content: base64.StdEncoding.EncodeToString([]byte("This is new text")),
Content: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("This is new text for %s", path))),
}, callback...)
}

Expand Down