Skip to content

Commit

Permalink
Small Fixes (#9)
Browse files Browse the repository at this point in the history
* Added more header context

* Fixed translation to bytes

* Added error to response header for enforcer

* Added value to error

* Changed check

* Removed errors in headers

* [skip ci] updated changelog
  • Loading branch information
kristinapathak authored Apr 5, 2019
1 parent 611f994 commit 46dfbcc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.1.1]
- Changed a check to be more generic
- Fixed byte-ifying the value for Bearer parsing

## [v0.1.0]
- Initial creation
- Added constructor, enforcer, and listener alice decorators
- Basic code and structure established

[Unreleased]: https://github.com/Comcast/comcast-bascule/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/Comcast/comcast-bascule/compare/v0.1.1...HEAD
[v0.1.1]: https://github.com/Comcast/comcast-bascule/compare/0.1.0...v0.1.1
[v0.1.0]: https://github.com/Comcast/comcast-bascule/compare/0.0.0...v0.1.0
3 changes: 1 addition & 2 deletions bascule/basculehttp/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (c *constructor) decorate(next http.Handler) http.Handler {
ctx := request.Context()
token, err := tf.ParseAndValidate(ctx, request, key, authorization[i+1:])
if err != nil {
errHeaderer := NewErrorHeaderer(err, map[string][]string{"authError": []string{err.Error()}})
WriteResponse(response, http.StatusUnauthorized, errHeaderer)
WriteResponse(response, http.StatusUnauthorized, err)
return
}

Expand Down
6 changes: 3 additions & 3 deletions bascule/basculehttp/tokenFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ type BearerTokenFactory struct {
}

func (btf BearerTokenFactory) ParseAndValidate(ctx context.Context, request *http.Request, auth bascule.Authorization, value string) (bascule.Token, error) {
decoded, err := base64.StdEncoding.DecodeString(value)
if err != nil {
return nil, err
if len(value) == 0 {
return nil, errors.New("empty value")
}
decoded := []byte(value)

jwsToken, err := btf.Parser.ParseJWS(decoded)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions bascule/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package bascule
import (
"context"
"errors"
"fmt"
)

const (
Expand Down Expand Up @@ -41,15 +42,15 @@ func CreateNonEmptyPrincipalCheck() ValidatorFunc {
}
}

func CreateStringListAttributeCheck(key string, checks ...func(context.Context, []string) error) ValidatorFunc {
func CreateListAttributeCheck(key string, checks ...func(context.Context, []interface{}) error) ValidatorFunc {
return func(ctx context.Context, token Token) error {
val, ok := token.Attributes()[key]
if !ok {
return errors.New("no capabilities found")
}
strVal, ok := val.([]string)
strVal, ok := val.([]interface{})
if !ok {
return errors.New("unexpected attribute value, expected []string")
return fmt.Errorf("unexpected attribute value, expected []interface{} but received: %v", val)
}
errs := Errors{}
for _, check := range checks {
Expand Down

0 comments on commit 46dfbcc

Please sign in to comment.