You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing integration tests to mock the auth mechanism in my application. To do this I am using mock-jwks which internally uses the MSW library to mock the responses of creating jwks in createRemoteJWKSet. The problem I am facing right now is since he module fetches the remote JWKs through the named import of http/https modules, MSW is not able to monkey patch the http/https modules. I have found possible issues relating to this problem and there seems to be a possible solution implemented here.
//test setuptest('Test with mocked jkwsUri',async()=>{constjwksMock=createJWKSMock('https://keycloak.somedomain.com','/auth/realm/application/protocol/openid-connect/certs')// We start our app.constserver=createApp().listen()constrequest=supertest(server)jwksMock.start()constaccess_token=jwksMock.token({aud: 'private',iss: 'master',})const{ status }=awaitrequest.get('/').set('Authorization',`Bearer ${access_token}`)expect(status).toEqual(200)})// appfunctionauth(){constgetKey=createRemoteJWKSet(newURL("https://keycloak.somedomain.com/auth/realm/application/protocol/openid-connect/certs"));returnasyncfunctionmiddleware(ctx,next){const[type,accessToken]=ctx.request.get('Authorization').split(' ');try{const{ payload }=awaitjwtVerify(accessToken,getKey,{ issuer, audience });}catch(err){ctx.throw(401);}returnnext();};}constcreateApp=()=>{constapp=newKoa()app.use(auth())constrouter=newRouter()// This route is protected by the authentication middlewarerouter.get('/',(ctx)=>{ctx.body='Authenticated!'})app.use(router.middleware())returnapp}exportdefaultcreateApp
Required
I have searched the issues tracker and discussions for similar topics and couldn't find anything related.
What happened?
I am writing integration tests to mock the auth mechanism in my application. To do this I am using mock-jwks which internally uses the MSW library to mock the responses of creating
jwks
increateRemoteJWKSet
. The problem I am facing right now is since he module fetches the remoteJWKs
through the named import ofhttp
/https
modules, MSW is not able to monkey patch thehttp
/https
modules. I have found possible issues relating to this problem and there seems to be a possible solution implemented here.Related issues:
stripe/stripe-node#1844
nock/nock#2461
Version
4.11.0
Runtime
Browser
Runtime Details
Node - v16.20.2 with ESM
Code to reproduce
Required
The text was updated successfully, but these errors were encountered: