From b728399c73fa4c9135df5ebddae4177583ab96f0 Mon Sep 17 00:00:00 2001 From: Dave Grijalva Date: Mon, 16 Nov 2015 12:42:37 -0800 Subject: [PATCH] signature should be populated after parsing a valid token --- parser.go | 3 ++- parser_test.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/parser.go b/parser.go index 40b02bc..3fc27bf 100644 --- a/parser.go +++ b/parser.go @@ -98,7 +98,8 @@ func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { } // Perform validation - if err = token.Method.Verify(strings.Join(parts[0:2], "."), parts[2], key); err != nil { + token.Signature = parts[2] + if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { vErr.err = err.Error() vErr.Errors |= ValidationErrorSignatureInvalid } diff --git a/parser_test.go b/parser_test.go index 97d9eee..9115017 100644 --- a/parser_test.go +++ b/parser_test.go @@ -184,9 +184,11 @@ func TestParser_Parse(t *testing.T) { if e := err.(*jwt.ValidationError).Errors; e != data.errors { t.Errorf("[%v] Errors don't match expectation. %v != %v", data.name, e, data.errors) } - } } + if data.valid && token.Signature == "" { + t.Errorf("[%v] Signature is left unpopulated after parsing", data.name) + } } }