(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestToken_SignedString(t *testing.T) { |
| 72 | type fields struct { |
| 73 | claims *token.Claims |
| 74 | } |
| 75 | type args struct { |
| 76 | sigAlg string |
| 77 | key interface{} |
| 78 | } |
| 79 | |
| 80 | rsaKey, err := pemutil.Read("../testdata/openssl.rsa1024.pem") |
| 81 | if err != nil { |
| 82 | t.Fatal(err) |
| 83 | } |
| 84 | |
| 85 | rsaPublic := rsaKey.(*rsa.PrivateKey).Public() |
| 86 | expected := "eyJhbGciOiJSUzI1NiIsImtpZCI6Im50U2lnZFFZNHRLOFlmTDdHQjZjNGRuZzhvSGVGOU5VMkl0QUlVOGtHZGciLCJ0eXAiOiJKV1QifQ.e30.spzx_GFrhXg_LTPBIE3z3uWaA-GH7G0rbPdskxbUahJnXRLwF8S_AAQMTjtsWY9iELwOQQUXW7aPES-jONCebTpXl00RYP7maiS87wcGW6nZ0ICmsbS5NnCDJIKpV4Ei3MZ4MXfZ4vLaONaR5BunHYkicMDqWif_2v8yvxebh7c" |
| 87 | |
| 88 | tests := []struct { |
| 89 | name string |
| 90 | fields fields |
| 91 | args args |
| 92 | want string |
| 93 | wantErr bool |
| 94 | }{ |
| 95 | {"ok", fields{&token.Claims{}}, args{"RS256", rsaKey}, expected, false}, |
| 96 | {"fail bad alg", fields{&token.Claims{}}, args{"ES256", rsaKey}, "", true}, |
| 97 | {"fail with public", fields{&token.Claims{}}, args{"RS256", rsaPublic}, "", true}, |
| 98 | } |
| 99 | for _, tt := range tests { |
| 100 | t.Run(tt.name, func(t *testing.T) { |
| 101 | tok := &Token{ |
| 102 | claims: tt.fields.claims, |
| 103 | } |
| 104 | got, err := tok.SignedString(tt.args.sigAlg, tt.args.key) |
| 105 | if (err != nil) != tt.wantErr { |
| 106 | t.Errorf("Token.SignedString() error = %v, wantErr %v", err, tt.wantErr) |
| 107 | return |
| 108 | } |
| 109 | if got != tt.want { |
| 110 | t.Errorf("Token.SignedString() = %v, want %v", got, tt.want) |
| 111 | } |
| 112 | }) |
| 113 | } |
| 114 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…