(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestAuthConfig_AuthFunc(t *testing.T) { |
| 60 | var ( |
| 61 | authSrv *oauth2.AuthorizationServer |
| 62 | err error |
| 63 | port uint16 |
| 64 | ) |
| 65 | |
| 66 | // We need to start a REST server for JWKS (using our auth server) |
| 67 | authSrv, port, err = testutil.StartAuthenticationServer() |
| 68 | assert.NoError(t, err) |
| 69 | defer authSrv.Close() |
| 70 | |
| 71 | // Some pre-work to retrieve a valid token |
| 72 | token, err := authSrv.GenerateToken(testdata.MockAuthClientID, 0, 0) |
| 73 | assert.NoError(t, err) |
| 74 | assert.NotNil(t, token) |
| 75 | |
| 76 | type fields struct { |
| 77 | jwksURL string |
| 78 | useJWKS bool |
| 79 | publicKey *ecdsa.PublicKey |
| 80 | } |
| 81 | type args struct { |
| 82 | ctx context.Context |
| 83 | } |
| 84 | tests := []struct { |
| 85 | name string |
| 86 | fields fields |
| 87 | args args |
| 88 | wantJWKS bool |
| 89 | wantCtx assert.Want[context.Context] |
| 90 | wantErr assert.ErrorAssertionFunc |
| 91 | }{ |
| 92 | { |
| 93 | name: "Request with valid bearer token using JWKS", |
| 94 | fields: fields{ |
| 95 | jwksURL: testutil.JWKSURL(port), |
| 96 | useJWKS: true, |
| 97 | }, |
| 98 | args: args{ |
| 99 | ctx: metadata.NewIncomingContext(context.TODO(), metadata.MD{"Authorization": []string{fmt.Sprintf("bearer %s", token.AccessToken)}}), |
| 100 | }, |
| 101 | wantCtx: ValidClaimAssertion, |
| 102 | }, |
| 103 | { |
| 104 | name: "Request with invalid bearer token using JWKS", |
| 105 | fields: fields{ |
| 106 | jwksURL: testutil.JWKSURL(port), |
| 107 | useJWKS: true, |
| 108 | }, |
| 109 | args: args{ |
| 110 | ctx: metadata.NewIncomingContext(context.TODO(), metadata.MD{"Authorization": []string{"bearer not_really"}}), |
| 111 | }, |
| 112 | wantErr: func(tt assert.TestingT, e error, i ...interface{}) bool { |
| 113 | return assert.ErrorIs(tt, e, status.Error(codes.Unauthenticated, "invalid auth token")) |
| 114 | }, |
| 115 | }, |
| 116 | { |
nothing calls this directly
no test coverage detected