...

Source file src/github.com/MicahParks/keyfunc/v2/padding_test.go

Documentation: github.com/MicahParks/keyfunc/v2

     1  package keyfunc_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/MicahParks/keyfunc/v2"
     7  )
     8  
     9  const (
    10  	// jwksWithPadding has trailing = for base64url padding, which is non-RFC compliant padding, but still supported.
    11  	jwksWithPadding = `{"keys":[{"kty":"RSA","use":"sig","kid":"hw1T/zfqTKIT2DYbY1vweU1sLxT4SmhsgkCsHq00Ix8=","n":"0P9Deg7S0HYuM7QdDOVpXycDErBfpPqxtxKURsNCyrtlopsbW3V-kXdQSj3_QXNaaJh9hTT9l46sl6e1x713ZMcBQI1-3xjfqSPK7POu21KIQG76eSt1A4xfOU7Wj_tfhaYuu_Axwr8RcmHCxNm0umqEIMjoyd1o30xBYkpeSCiaNnqpAldyzVVFox5WAkUaQo0GFmuf9RKddprIwtDSq4DpmlPV41Qe6NUBnQ5mZnWFsJohzpnI1YacpUUfdA7ZWbnEhg5ZKlb9hl80yPKQUBjVoeMZUuB1BDOyP-HBAQgmtCrCfsm26JX2bZtagl3xdy9yQNuIK9Ly75iSXIIrFw==","e":"AQAB","alg":"RS256"}]}`
    12  )
    13  
    14  // TestNonRFCPadding confirms that a JWKS with keys that contain padding at the end values for base64url encoded public
    15  // keys. Having this trailing padding is not RFC compliant, but supported anyway.
    16  func TestNonRFCPadding(t *testing.T) {
    17  	jwks, err := keyfunc.NewJSON([]byte(jwksWithPadding))
    18  	if err != nil {
    19  		t.Fatalf(logFmt, "Failed to parse the JWKS with padding.", err)
    20  	}
    21  
    22  	// Confirm all the keys in the JWKS were parsed.
    23  	if len(jwks.KIDs()) != 1 {
    24  		t.Fatalf("Not all keys with padding were parsed.\n  Expected: %d\n  Actual: %d", 1, len(jwks.KIDs()))
    25  	}
    26  }
    27  

View as plain text