(ctx context.Context, subject string)
| 105 | } |
| 106 | |
| 107 | func makePacketBrokerTokenIssuer(ctx context.Context, subject string) (iss string, tok func(aud string) string) { |
| 108 | public, private, err := ed25519.GenerateKey(nil) |
| 109 | if err != nil { |
| 110 | panic(err) |
| 111 | } |
| 112 | var ( |
| 113 | publicJWK = jose.JSONWebKey{ |
| 114 | Algorithm: string(jose.EdDSA), |
| 115 | Key: public, |
| 116 | KeyID: "test", |
| 117 | } |
| 118 | privateJWK = jose.JSONWebKey{ |
| 119 | Algorithm: string(jose.EdDSA), |
| 120 | Key: private, |
| 121 | KeyID: "test", |
| 122 | } |
| 123 | sig = test.Must(jose.NewSigner(jose.SigningKey{ |
| 124 | Algorithm: jose.SignatureAlgorithm(privateJWK.Algorithm), |
| 125 | Key: privateJWK, |
| 126 | }, new(jose.SignerOptions).WithType("JWT"))).(jose.Signer) |
| 127 | ) |
| 128 | |
| 129 | router := mux.NewRouter() |
| 130 | router.Handle("/.well-known/jwks.json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 131 | w.Header().Set("Content-Type", "application/json") |
| 132 | json.NewEncoder(w).Encode(&jose.JSONWebKeySet{ //nolint:errcheck |
| 133 | Keys: []jose.JSONWebKey{publicJWK}, |
| 134 | }) |
| 135 | })) |
| 136 | srv := httptest.NewServer(router) |
| 137 | |
| 138 | go func() { |
| 139 | <-ctx.Done() |
| 140 | srv.Close() |
| 141 | }() |
| 142 | |
| 143 | return srv.URL, func(aud string) string { |
| 144 | claims := packetbroker.TokenClaims{ |
| 145 | Claims: jwt.Claims{ |
| 146 | Issuer: srv.URL, |
| 147 | Subject: subject, |
| 148 | Audience: jwt.Audience{aud}, |
| 149 | }, |
| 150 | PacketBroker: packetbroker.IAMTokenClaims{ |
| 151 | Cluster: true, |
| 152 | }, |
| 153 | } |
| 154 | return test.Must(jwt.Signed(sig).Claims(claims).CompactSerialize()) |
| 155 | } |
| 156 | } |
no test coverage detected