From cdfe06219b0980f294248e666fa52f93c9c5393e Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 3 Jun 2014 16:21:48 +0200 Subject: [PATCH] use ioutil.ReadFile for reading test keys --- jwt_test.go | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/jwt_test.go b/jwt_test.go index 8039bd2..2d8902e 100644 --- a/jwt_test.go +++ b/jwt_test.go @@ -1,11 +1,9 @@ package jwt import ( - "bytes" "fmt" - "io" + "io/ioutil" "net/http" - "os" "reflect" "testing" "time" @@ -56,11 +54,10 @@ var jwtTestData = []struct { } func makeSample(c map[string]interface{}) string { - file, _ := os.Open("test/sample_key") - buf := new(bytes.Buffer) - io.Copy(buf, file) - key := buf.Bytes() - file.Close() + key, e := ioutil.ReadFile("test/sample_key") + if e != nil { + panic(e.Error()) + } token := New(GetSigningMethod("RS256")) token.Claims = c @@ -74,17 +71,15 @@ func makeSample(c map[string]interface{}) string { } func TestJWT(t *testing.T) { - file, _ := os.Open("test/sample_key.pub") - buf := new(bytes.Buffer) - io.Copy(buf, file) - key := buf.Bytes() - file.Close() + key, e := ioutil.ReadFile("test/sample_key.pub") + if e != nil { + t.Fatal(e) + } for _, data := range jwtTestData { if data.tokenString == "" { data.tokenString = makeSample(data.claims) } - token, err := Parse(data.tokenString, func(t *Token) ([]byte, error) { return key, nil }) if !reflect.DeepEqual(data.claims, token.Claims) { @@ -112,11 +107,10 @@ func TestJWT(t *testing.T) { } func TestParseRequest(t *testing.T) { - file, _ := os.Open("test/sample_key.pub") - buf := new(bytes.Buffer) - io.Copy(buf, file) - key := buf.Bytes() - file.Close() + key, e := ioutil.ReadFile("test/sample_key.pub") + if e != nil { + t.Fatal(e) + } // Bearer token request for _, data := range jwtTestData {