mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(GraphQL Node): Refresh OAuth2 token when it expires (#17891)
This commit is contained in:
@@ -2,9 +2,8 @@ import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||
import nock from 'nock';
|
||||
|
||||
describe('GraphQL Node', () => {
|
||||
const baseUrl = 'https://api.n8n.io/';
|
||||
|
||||
beforeAll(async () => {
|
||||
describe('valid request', () => {
|
||||
const baseUrl = 'https://api.n8n.io/';
|
||||
nock(baseUrl)
|
||||
.matchHeader('accept', 'application/json')
|
||||
.matchHeader('content-type', 'application/json')
|
||||
@@ -54,7 +53,61 @@ describe('GraphQL Node', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
new NodeTestHarness().setupTests({
|
||||
workflowFiles: ['workflow.json'],
|
||||
});
|
||||
});
|
||||
|
||||
new NodeTestHarness().setupTests();
|
||||
describe('invalid expression', () => {
|
||||
new NodeTestHarness().setupTests({
|
||||
workflowFiles: ['workflow.error_invalid_expression.json'],
|
||||
});
|
||||
});
|
||||
|
||||
describe('oauth2 refresh token', () => {
|
||||
const credentials = {
|
||||
oAuth2Api: {
|
||||
scope: '',
|
||||
accessTokenUrl: 'http://test/token',
|
||||
clientId: 'dummy_client_id',
|
||||
clientSecret: 'dummy_client_secret',
|
||||
oauthTokenData: {
|
||||
access_token: 'dummy_access_token',
|
||||
refresh_token: 'dummy_refresh_token',
|
||||
},
|
||||
},
|
||||
};
|
||||
const baseUrl = 'http://test';
|
||||
nock(baseUrl)
|
||||
.post('/graphql', '{"query":"query { foo }","variables":{},"operationName":null}')
|
||||
.reply(401, {
|
||||
errors: [
|
||||
{
|
||||
message: 'Unauthorized',
|
||||
},
|
||||
],
|
||||
});
|
||||
nock(baseUrl)
|
||||
.post('/token', {
|
||||
refresh_token: 'dummy_refresh_token',
|
||||
grant_type: 'refresh_token',
|
||||
})
|
||||
.reply(200, {
|
||||
access_token: 'dummy_access_token',
|
||||
refresh_token: 'dummy_refresh_token',
|
||||
expires_in: 3600,
|
||||
});
|
||||
nock(baseUrl)
|
||||
.post('/graphql', '{"query":"query { foo }","variables":{},"operationName":null}')
|
||||
.reply(200, {
|
||||
data: {
|
||||
foo: 'bar',
|
||||
},
|
||||
});
|
||||
new NodeTestHarness().setupTests({
|
||||
workflowFiles: ['workflow.refresh_token.json'],
|
||||
credentials,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user