Skip to content

Commit

Permalink
access: fix token permissions (#707)
Browse files Browse the repository at this point in the history
* access: fix token permissions

* add test
  • Loading branch information
mxyng authored Dec 1, 2021
1 parent e323389 commit 66127aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion internal/access/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func RequireAuthorization(c *gin.Context, require Permission) (*gorm.DB, string,
}
}

return db, authorization, nil
case data.APIKeyLength:
apiKey, err := data.GetAPIKey(db, &data.APIKey{Key: authorization})
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion internal/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ func TestRequireAuthorization(t *testing.T) {
require.EqualError(t, err, "token invalid")
},
},
"TokenNoMatch": {
"permission": PermissionAPIKeyList,
"authFunc": func(t *testing.T, db *gorm.DB, c *gin.Context) {
authorization := issueToken(t, db, "existing@infrahq.com", "infra.user.read", time.Minute*1)
c.Set("authorization", authorization)
},
"verifyFunc": func(t *testing.T, err error) {
require.EqualError(t, err, "forbidden")
},
},
"TokenInvalidSecret": {
"permission": PermissionUserRead,
"authFunc": func(t *testing.T, db *gorm.DB, c *gin.Context) {
Expand Down Expand Up @@ -187,7 +197,7 @@ func TestRequireAuthorization(t *testing.T) {
require.NoError(t, err)
},
},
"APIKeyAuthorizedNoMatch": {
"APIKeyNoMatch": {
"permission": PermissionUserRead,
"authFunc": func(t *testing.T, db *gorm.DB, c *gin.Context) {
authorization := issueAPIKey(t, db, "infra.user.create infra.group.read")
Expand Down

0 comments on commit 66127aa

Please sign in to comment.