forked from Mirrors/oauth2
Test PrivateClaims support in jwt.go.
This commit is contained in:
parent
9dd27cc44e
commit
8baca543ee
|
@ -11,6 +11,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -221,6 +222,16 @@ func TestJWTFetch_AssertionPayload(t *testing.T) {
|
||||||
TokenURL: ts.URL,
|
TokenURL: ts.URL,
|
||||||
Audience: "https://example.com",
|
Audience: "https://example.com",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Email: "aaa2@xxx.com",
|
||||||
|
PrivateKey: dummyPrivateKey,
|
||||||
|
PrivateKeyID: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
|
TokenURL: ts.URL,
|
||||||
|
PrivateClaims: map[string]interface{}{
|
||||||
|
"private0": "claim0",
|
||||||
|
"private1": "claim1",
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(conf.Email, func(t *testing.T) {
|
t.Run(conf.Email, func(t *testing.T) {
|
||||||
_, err := conf.TokenSource(context.Background()).Token()
|
_, err := conf.TokenSource(context.Background()).Token()
|
||||||
|
@ -261,6 +272,18 @@ func TestJWTFetch_AssertionPayload(t *testing.T) {
|
||||||
if got, want := claimSet.Prn, conf.Subject; got != want {
|
if got, want := claimSet.Prn, conf.Subject; got != want {
|
||||||
t.Errorf("payload prn = %q; want %q", got, want)
|
t.Errorf("payload prn = %q; want %q", got, want)
|
||||||
}
|
}
|
||||||
|
if len(conf.PrivateClaims) > 0 {
|
||||||
|
var got interface{}
|
||||||
|
if err := json.Unmarshal(gotjson, &got); err != nil {
|
||||||
|
t.Errorf("failed to parse payload; err = %q", err)
|
||||||
|
}
|
||||||
|
m := got.(map[string]interface{})
|
||||||
|
for v, k := range conf.PrivateClaims {
|
||||||
|
if !reflect.DeepEqual(m[v], k) {
|
||||||
|
t.Errorf("payload private claims key = %q: got %q; want %q", v, m[v], k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue