Skip to content

Commit 5d907b8

Browse files
authored
Merge branch 'main' into fix_15601
2 parents 1eaad13 + b822932 commit 5d907b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1667
-874
lines changed

integrations/api_gpg_keys_test.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func TestGPGKeys(t *testing.T) {
2929
results []int
3030
}{
3131
{name: "NoLogin", makeRequest: MakeRequest, token: "",
32-
results: []int{http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized},
32+
results: []int{http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized},
3333
},
3434
{name: "LoggedAsUser2", makeRequest: session.MakeRequest, token: token,
35-
results: []int{http.StatusOK, http.StatusOK, http.StatusNotFound, http.StatusNoContent, http.StatusUnprocessableEntity, http.StatusNotFound, http.StatusCreated, http.StatusCreated}},
35+
results: []int{http.StatusOK, http.StatusOK, http.StatusNotFound, http.StatusNoContent, http.StatusUnprocessableEntity, http.StatusNotFound, http.StatusCreated, http.StatusNotFound, http.StatusCreated}},
3636
}
3737

3838
for _, tc := range tt {
@@ -60,7 +60,7 @@ func TestGPGKeys(t *testing.T) {
6060
t.Run("CreateValidGPGKey", func(t *testing.T) {
6161
testCreateValidGPGKey(t, tc.makeRequest, tc.token, tc.results[6])
6262
})
63-
t.Run("CreateValidSecondaryEmailGPGKey", func(t *testing.T) {
63+
t.Run("CreateValidSecondaryEmailGPGKeyNotActivated", func(t *testing.T) {
6464
testCreateValidSecondaryEmailGPGKey(t, tc.makeRequest, tc.token, tc.results[7])
6565
})
6666
})
@@ -74,6 +74,7 @@ func TestGPGKeys(t *testing.T) {
7474
req := NewRequest(t, "GET", "/api/v1/user/gpg_keys?token="+token) //GET all keys
7575
resp := session.MakeRequest(t, req, http.StatusOK)
7676
DecodeJSON(t, resp, &keys)
77+
assert.Len(t, keys, 1)
7778

7879
primaryKey1 := keys[0] //Primary key 1
7980
assert.EqualValues(t, "38EA3BCED732982C", primaryKey1.KeyID)
@@ -85,12 +86,6 @@ func TestGPGKeys(t *testing.T) {
8586
assert.EqualValues(t, "70D7C694D17D03AD", subKey.KeyID)
8687
assert.Empty(t, subKey.Emails)
8788

88-
primaryKey2 := keys[1] //Primary key 2
89-
assert.EqualValues(t, "3CEF46EF40BEFC3E", primaryKey2.KeyID)
90-
assert.Len(t, primaryKey2.Emails, 1)
91-
assert.EqualValues(t, "[email protected]", primaryKey2.Emails[0].Email)
92-
assert.False(t, primaryKey2.Emails[0].Verified)
93-
9489
var key api.GPGKey
9590
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(primaryKey1.ID, 10)+"?token="+token) //Primary key 1
9691
resp = session.MakeRequest(t, req, http.StatusOK)
@@ -105,15 +100,6 @@ func TestGPGKeys(t *testing.T) {
105100
DecodeJSON(t, resp, &key)
106101
assert.EqualValues(t, "70D7C694D17D03AD", key.KeyID)
107102
assert.Empty(t, key.Emails)
108-
109-
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(primaryKey2.ID, 10)+"?token="+token) //Primary key 2
110-
resp = session.MakeRequest(t, req, http.StatusOK)
111-
DecodeJSON(t, resp, &key)
112-
assert.EqualValues(t, "3CEF46EF40BEFC3E", key.KeyID)
113-
assert.Len(t, key.Emails, 1)
114-
assert.EqualValues(t, "[email protected]", key.Emails[0].Email)
115-
assert.False(t, key.Emails[0].Verified)
116-
117103
})
118104

119105
//Check state after basic add

integrations/repo_commits_test.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,36 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
7373

7474
//By SHA
7575
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/statuses")
76-
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
76+
reqOne := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/status")
77+
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
78+
7779
//By Ref
7880
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/statuses")
79-
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
81+
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/status")
82+
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
8083
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/statuses")
81-
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
84+
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/status")
85+
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
8286
}
8387

84-
func testRepoCommitsWithStatus(t *testing.T, resp *httptest.ResponseRecorder, state string) {
88+
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
8589
json := jsoniter.ConfigCompatibleWithStandardLibrary
86-
decoder := json.NewDecoder(resp.Body)
87-
statuses := []*api.CommitStatus{}
88-
assert.NoError(t, decoder.Decode(&statuses))
89-
assert.Len(t, statuses, 1)
90-
for _, s := range statuses {
91-
assert.Equal(t, api.CommitStatusState(state), s.State)
92-
assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/65f1bf27bc3bf70f64657658635e66094edbcb4d", s.URL)
93-
assert.Equal(t, "http://test.ci/", s.TargetURL)
94-
assert.Equal(t, "", s.Description)
95-
assert.Equal(t, "testci", s.Context)
90+
var statuses []*api.CommitStatus
91+
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
92+
var status api.CombinedStatus
93+
assert.NoError(t, json.Unmarshal(respOne.Body.Bytes(), &status))
94+
assert.NotNil(t, status)
95+
96+
if assert.Len(t, statuses, 1) {
97+
assert.Equal(t, api.CommitStatusState(state), statuses[0].State)
98+
assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/65f1bf27bc3bf70f64657658635e66094edbcb4d", statuses[0].URL)
99+
assert.Equal(t, "http://test.ci/", statuses[0].TargetURL)
100+
assert.Equal(t, "", statuses[0].Description)
101+
assert.Equal(t, "testci", statuses[0].Context)
102+
103+
assert.Len(t, status.Statuses, 1)
104+
assert.Equal(t, statuses[0], status.Statuses[0])
105+
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.SHA)
96106
}
97107
}
98108

models/error.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ func (err ErrKeyNameAlreadyUsed) Error() string {
451451
// ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
452452
type ErrGPGNoEmailFound struct {
453453
FailedEmails []string
454+
ID string
454455
}
455456

456457
// IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
@@ -463,6 +464,22 @@ func (err ErrGPGNoEmailFound) Error() string {
463464
return fmt.Sprintf("none of the emails attached to the GPG key could be found: %v", err.FailedEmails)
464465
}
465466

467+
// ErrGPGInvalidTokenSignature represents a "ErrGPGInvalidTokenSignature" kind of error.
468+
type ErrGPGInvalidTokenSignature struct {
469+
Wrapped error
470+
ID string
471+
}
472+
473+
// IsErrGPGInvalidTokenSignature checks if an error is a ErrGPGInvalidTokenSignature.
474+
func IsErrGPGInvalidTokenSignature(err error) bool {
475+
_, ok := err.(ErrGPGInvalidTokenSignature)
476+
return ok
477+
}
478+
479+
func (err ErrGPGInvalidTokenSignature) Error() string {
480+
return "the provided signature does not sign the token with the provided key"
481+
}
482+
466483
// ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
467484
type ErrGPGKeyParsing struct {
468485
ParseError error

0 commit comments

Comments
 (0)