forked from mirror/jwt
use ioutil.ReadFile for reading test keys
This commit is contained in:
parent
fecd9ab279
commit
cdfe06219b
32
jwt_test.go
32
jwt_test.go
|
@ -1,11 +1,9 @@
|
||||||
package jwt
|
package jwt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -56,11 +54,10 @@ var jwtTestData = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSample(c map[string]interface{}) string {
|
func makeSample(c map[string]interface{}) string {
|
||||||
file, _ := os.Open("test/sample_key")
|
key, e := ioutil.ReadFile("test/sample_key")
|
||||||
buf := new(bytes.Buffer)
|
if e != nil {
|
||||||
io.Copy(buf, file)
|
panic(e.Error())
|
||||||
key := buf.Bytes()
|
}
|
||||||
file.Close()
|
|
||||||
|
|
||||||
token := New(GetSigningMethod("RS256"))
|
token := New(GetSigningMethod("RS256"))
|
||||||
token.Claims = c
|
token.Claims = c
|
||||||
|
@ -74,17 +71,15 @@ func makeSample(c map[string]interface{}) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJWT(t *testing.T) {
|
func TestJWT(t *testing.T) {
|
||||||
file, _ := os.Open("test/sample_key.pub")
|
key, e := ioutil.ReadFile("test/sample_key.pub")
|
||||||
buf := new(bytes.Buffer)
|
if e != nil {
|
||||||
io.Copy(buf, file)
|
t.Fatal(e)
|
||||||
key := buf.Bytes()
|
}
|
||||||
file.Close()
|
|
||||||
|
|
||||||
for _, data := range jwtTestData {
|
for _, data := range jwtTestData {
|
||||||
if data.tokenString == "" {
|
if data.tokenString == "" {
|
||||||
data.tokenString = makeSample(data.claims)
|
data.tokenString = makeSample(data.claims)
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := Parse(data.tokenString, func(t *Token) ([]byte, error) { return key, nil })
|
token, err := Parse(data.tokenString, func(t *Token) ([]byte, error) { return key, nil })
|
||||||
|
|
||||||
if !reflect.DeepEqual(data.claims, token.Claims) {
|
if !reflect.DeepEqual(data.claims, token.Claims) {
|
||||||
|
@ -112,11 +107,10 @@ func TestJWT(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseRequest(t *testing.T) {
|
func TestParseRequest(t *testing.T) {
|
||||||
file, _ := os.Open("test/sample_key.pub")
|
key, e := ioutil.ReadFile("test/sample_key.pub")
|
||||||
buf := new(bytes.Buffer)
|
if e != nil {
|
||||||
io.Copy(buf, file)
|
t.Fatal(e)
|
||||||
key := buf.Bytes()
|
}
|
||||||
file.Close()
|
|
||||||
|
|
||||||
// Bearer token request
|
// Bearer token request
|
||||||
for _, data := range jwtTestData {
|
for _, data := range jwtTestData {
|
||||||
|
|
Loading…
Reference in New Issue