MCPcopy
hub / github.com/golang-jwt/jwt / TestRSAWithPreParsedPrivateKey

Function TestRSAWithPreParsedPrivateKey

rsa_test.go:100–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestRSAWithPreParsedPrivateKey(t *testing.T) {
101 key, _ := os.ReadFile("test/sample_key")
102 parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
103 if err != nil {
104 t.Fatal(err)
105 }
106 testData := rsaTestData[0]
107 parts := strings.Split(testData.tokenString, ".")
108 sig, err := jwt.SigningMethodRS256.Sign(strings.Join(parts[0:2], "."), parsedKey)
109 if err != nil {
110 t.Errorf("[%v] Error signing token: %v", testData.name, err)
111 }
112 if !reflect.DeepEqual(sig, decodeSegment(t, parts[2])) {
113 t.Errorf("[%v] Incorrect signature.\nwas:\n%v\nexpecting:\n%v", testData.name, sig, parts[2])
114 }
115}
116
117func TestRSAKeyParsing(t *testing.T) {
118 key, _ := os.ReadFile("test/sample_key")

Callers

nothing calls this directly

Calls 2

decodeSegmentFunction · 0.85
SignMethod · 0.65

Tested by

no test coverage detected