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
When using the authentication strategy together with @octokit/core and adding hooks, the hooks are not triggered for internal requests (e.g. to https://github.com/login/oauth/access_token):
import{Octokit}from'@octokit/core';import{createOAuthUserAuth}from'@octokit/auth-oauth-user';importfetchMockfrom'fetch-mock';describe('With Octokit',()=>{test('hooks',async()=>{constfm=fetchMock.sandbox().postOnce('https://github.com/login/oauth/access_token',{body: {access_token: 'ghu_dummyToken',expires_in: 28800,refresh_token: 'ghr_dummyRefreshToken',refresh_token_expires_in: 15811200,scope: '',token_type: 'bearer',},headers: {date: newDate().toISOString(),},}).getOnce({url: 'https://api.github.com/user',headers: {authorization: 'token ghu_dummyToken'},},{});constoctokit=newOctokit({authStrategy: createOAuthUserAuth,auth: {clientId: '1234567890abcdef1234',clientSecret: '1234567890abcdef1234567890abcdef12345678',code: 'code123',},request: {fetch: fm,},});constmockedErrorRequestHook=jest.fn();constmockedBeforeRequestHook=jest.fn();constmockedAfterRequestHook=jest.fn();constmockedWrapRequestHook=jest.fn((request,options)=>request(options));octokit.hook.error('request',mockedErrorRequestHook);octokit.hook.before('request',mockedBeforeRequestHook);octokit.hook.after('request',mockedAfterRequestHook);octokit.hook.wrap('request',mockedWrapRequestHook);// Exchanges the code for the user access token authentication on first request// and caches the authentication for successive requestsawaitoctokit.request('GET /user');// First call to https://github.com/login/oauth/access_token// Second call to https://api.github.com/userexpect(fm.calls().length).toBe(2);// passesexpect(mockedErrorRequestHook).not.toHaveBeenCalled();// passesexpect(mockedBeforeRequestHook).toHaveBeenCalledTimes(2);// fails: 1expect(mockedAfterRequestHook).toHaveBeenCalledTimes(2);// fails: 1expect(mockedWrapRequestHook).toHaveBeenCalledTimes(2);// fails: 1});});
What happened?
When using the authentication strategy together with
@octokit/core
and adding hooks, the hooks are not triggered for internal requests (e.g. tohttps://github.com/login/oauth/access_token
):x-ref: octokit/octokit.js#2294 (comment)
What did you expect to happen?
That the hooks are also called for the defined hooks, when internal requests are made.
The text was updated successfully, but these errors were encountered: