Skip to content

Commit

Permalink
Merge branch 'master' of /~https://github.com/go-gitea/gitea into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Mahn committed Jun 14, 2017
2 parents 0108d7e + 274149d commit 7950fa0
Show file tree
Hide file tree
Showing 61 changed files with 10,684 additions and 926 deletions.
58 changes: 58 additions & 0 deletions integrations/change_default_branch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2017 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 integrations

import (
"bytes"
"fmt"
"net/http"
"net/url"
"testing"

"code.gitea.io/gitea/models"

"github.com/stretchr/testify/assert"
)

func TestChangeDefaultBranch(t *testing.T) {
prepareTestEnv(t)
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)

session := loginUser(t, owner.Name, "password")
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)

req := NewRequest(t, "GET", branchesURL)
resp := session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
doc, err := NewHtmlParser(resp.Body)
assert.NoError(t, err)

req = NewRequestBody(t, "POST", branchesURL,
bytes.NewBufferString(url.Values{
"_csrf": []string{doc.GetInputValueByName("_csrf")},
"action": []string{"default_branch"},
"branch": []string{"DefaultBranch"},
}.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)

req = NewRequest(t, "GET", branchesURL)
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
doc, err = NewHtmlParser(resp.Body)
assert.NoError(t, err)

req = NewRequestBody(t, "POST", branchesURL,
bytes.NewBufferString(url.Values{
"_csrf": []string{doc.GetInputValueByName("_csrf")},
"action": []string{"default_branch"},
"branch": []string{"does_not_exist"},
}.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
65f1bf27bc3bf70f64657658635e66094edbcb4d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
65f1bf27bc3bf70f64657658635e66094edbcb4d
2 changes: 1 addition & 1 deletion models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (a *Action) loadActUser() {
}

func (a *Action) loadRepo() {
if a.ActUser != nil {
if a.Repo != nil {
return
}
var err error
Expand Down
6 changes: 3 additions & 3 deletions models/gpg_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"code.gitea.io/gitea/modules/log"

"github.com/go-xorm/xorm"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/packet"
"github.com/keybase/go-crypto/openpgp"
"github.com/keybase/go-crypto/openpgp/armor"
"github.com/keybase/go-crypto/openpgp/packet"
)

// GPGKey represents a GPG key.
Expand Down
41 changes: 31 additions & 10 deletions models/gpg_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,28 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
-----END PGP PUBLIC KEY BLOCK-----`

key, err := checkArmoredGPGKeyString(testGPGArmor)
assert.Nil(t, err, "Could not parse a valid GPG armored key", key)
assert.NoError(t, err, "Could not parse a valid GPG public armored rsa key", key)
//TODO verify value of key
}

func TestCheckArmoredbrainpoolP256r1GPGKeyString(t *testing.T) {
testGPGArmor := `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mFMEV6HwkhMJKyQDAwIIAQEHAgMEUsvJO/j5dFMRRj67qeZC9fSKBsGZdOHRj2+6
8wssmbUuLTfT/ZjIbExETyY8hFnURRGpD2Ifyz0cKjXcbXfJtrQTRm9vYmFyIDxm
b29AYmFyLmRlPoh/BBMTCAAnBQJZOsDIAhsDBQkJZgGABQsJCAcCBhUICQoLAgQW
AgMBAh4BAheAAAoJEGuJTd/DBMzmNVQA/2beUrv1yU4gyvCiPDEm3pK42cSfaL5D
muCtPCUg9hlWAP4yq6M78NW8STfsXgn6oeziMYiHSTmV14nOamLuwwDWM7hXBFeh
8JISCSskAwMCCAEBBwIDBG3A+XfINAZp1CTse2mRNgeUE5DbUtEpO8ALXKA1UQsQ
DLKq27b7zTgawgXIGUGP6mWsJ5oH7MNAJ/uKTsYmX40DAQgHiGcEGBMIAA8FAleh
8JICGwwFCQlmAYAACgkQa4lN38MEzOZwKAD/QKyerAgcvzzLaqvtap3XvpYcw9tc
OyjLLnFQiVmq7kEA/0z0CQe3ZQiQIq5zrs7Nh1XRkFAo8GlU/SGC9XFFi722
=ZiSe
-----END PGP PUBLIC KEY BLOCK-----`

key, err := checkArmoredGPGKeyString(testGPGArmor)
assert.NoError(t, err, "Could not parse a valid GPG public armored brainpoolP256r1 key", key)
//TODO verify value of key
}

Expand Down Expand Up @@ -79,11 +100,11 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
=i9b7
-----END PGP PUBLIC KEY BLOCK-----`
ekey, err := checkArmoredGPGKeyString(testGPGArmor)
assert.Nil(t, err, "Could not parse a valid GPG armored key", ekey)
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)

pubkey := ekey.PrimaryKey
content, err := base64EncPubKey(pubkey)
assert.Nil(t, err, "Could not base64 encode a valid PublicKey content", ekey)
assert.NoError(t, err, "Could not base64 encode a valid PublicKey content", ekey)

key := &GPGKey{
KeyID: pubkey.KeyIdString(),
Expand Down Expand Up @@ -144,21 +165,21 @@ Unknown GPG key with good email
`
//Reading Sign
goodSig, err := extractSignature(testGoodSigArmor)
assert.Nil(t, err, "Could not parse a valid GPG armored signature", testGoodSigArmor)
assert.NoError(t, err, "Could not parse a valid GPG armored signature", testGoodSigArmor)
badSig, err := extractSignature(testBadSigArmor)
assert.Nil(t, err, "Could not parse a valid GPG armored signature", testBadSigArmor)
assert.NoError(t, err, "Could not parse a valid GPG armored signature", testBadSigArmor)

//Generating hash of commit
goodHash, err := populateHash(goodSig.Hash, []byte(testGoodPayload))
assert.Nil(t, err, "Could not generate a valid hash of payload", testGoodPayload)
assert.NoError(t, err, "Could not generate a valid hash of payload", testGoodPayload)
badHash, err := populateHash(badSig.Hash, []byte(testBadPayload))
assert.Nil(t, err, "Could not generate a valid hash of payload", testBadPayload)
assert.NoError(t, err, "Could not generate a valid hash of payload", testBadPayload)

//Verify
err = verifySign(goodSig, goodHash, key)
assert.Nil(t, err, "Could not validate a good signature")
assert.NoError(t, err, "Could not validate a good signature")
err = verifySign(badSig, badHash, key)
assert.NotNil(t, err, "Validate a bad signature")
assert.Error(t, err, "Validate a bad signature")
err = verifySign(goodSig, goodHash, cannotsignkey)
assert.NotNil(t, err, "Validate a bad signature with a kay that can not sign")
assert.Error(t, err, "Validate a bad signature with a kay that can not sign")
}
8 changes: 5 additions & 3 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,11 @@ func ProtectedBranchPost(ctx *context.Context) {
return
}

branch := strings.ToLower(ctx.Query("branch"))
if ctx.Repo.GitRepo.IsBranchExist(branch) &&
repo.DefaultBranch != branch {
branch := ctx.Query("branch")
if !ctx.Repo.GitRepo.IsBranchExist(branch) {
ctx.Status(404)
return
} else if repo.DefaultBranch != branch {
repo.DefaultBranch = branch
if err := ctx.Repo.GitRepo.SetDefaultBranch(branch); err != nil {
if !git.IsErrUnsupportedVersion(err) {
Expand Down
27 changes: 27 additions & 0 deletions vendor/github.com/keybase/go-crypto/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/keybase/go-crypto/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions vendor/github.com/keybase/go-crypto/brainpool/brainpool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7950fa0

Please sign in to comment.