File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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+
190207func (s * ApplicationSuite ) Test_DeleteApplication_expectNotFoundOnCurrentUserIsNotOwner () {
191208 s .db .User (2 )
192209 s .db .User (5 ).App (5 )
You can’t perform that action at this time.
0 commit comments