Skip to content

Commit 0fd65a0

Browse files
Merge pull request #988 from gotify/sec-update-rekey
fixup! feat(security): application token refresh
2 parents 89e1968 + 5e81bed commit 0fd65a0

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

api/application.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ func (a *ApplicationAPI) UpdateApplicationSecurity(ctx *gin.Context) {
335335
if success := successOrAbort(ctx, 500, err); !success {
336336
return
337337
}
338+
if app == nil || app.UserID != auth.GetUserID(ctx) {
339+
ctx.AbortWithError(404, fmt.Errorf("app with id %d doesn't exists", id))
340+
return
341+
}
342+
338343
action := model.SecurityUpdateAction{}
339344
response := model.SecurityUpdateActionResponse{}
340345
if err := ctx.Bind(&action); err == nil {

api/application_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ func (s *ApplicationSuite) Test_UpdateApplicationSecurity_isNoOpIfNilAction() {
187187
assert.Equal(s.T(), oldToken, newToken)
188188
}
189189

190+
func (s *ApplicationSuite) Test_UpdateApplicationSecurity_expectNotFoundOnCurrentUserIsNotOwner() {
191+
s.db.User(2)
192+
s.db.User(5).App(1)
193+
test.WithUser(s.ctx, 2)
194+
195+
oldToken, err := s.db.GetApplicationByID(1)
196+
assert.NoError(s.T(), err)
197+
s.ctx.Request = httptest.NewRequest("PUT", "/application/1/security", bytes.NewBufferString(`{}`))
198+
s.ctx.Request.Header.Set("Content-Type", "application/json")
199+
s.ctx.Params = gin.Params{{Key: "id", Value: "1"}}
200+
s.a.UpdateApplicationSecurity(s.ctx)
201+
assert.Equal(s.T(), 404, s.recorder.Code)
202+
newToken, err := s.db.GetApplicationByID(1)
203+
assert.NoError(s.T(), err)
204+
assert.Equal(s.T(), oldToken, newToken)
205+
}
206+
190207
func (s *ApplicationSuite) Test_DeleteApplication_expectNotFoundOnCurrentUserIsNotOwner() {
191208
s.db.User(2)
192209
s.db.User(5).App(5)

0 commit comments

Comments
 (0)