mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-21 20:20:03 +02:00
Co-authored-by: Matsu <matias.huhta@n8n.io> Co-authored-by: Stephen Wright <sjw948@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Bernhard Wittmann <bernhard.wittmann@n8n.io> Co-authored-by: Nikhil Kuriakose <nikhil.kuriakose@n8n.io> Co-authored-by: Albert Alises <albert.alises@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Andreas Fitzek <andreas.fitzek@n8n.io> Co-authored-by: Ricardo Espinoza <ricardo@n8n.io> Co-authored-by: Mike Repeć <mike.repec@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: bjorger <50590409+bjorger@users.noreply.github.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import * as jwt from 'jsonwebtoken';
|
|
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
|
|
import type { Mock } from 'vitest';
|
|
import { mock } from 'vitest-mock-extended';
|
|
|
|
import { getGoogleAccessToken } from '../GenericFunctions';
|
|
|
|
vi.mock('jsonwebtoken', () => {
|
|
const sign = vi.fn(() => 'signed-jwt');
|
|
return { default: { sign }, sign };
|
|
});
|
|
|
|
describe('getGoogleAccessToken', () => {
|
|
const mockedSign = jwt.sign as unknown as Mock;
|
|
|
|
beforeEach(() => {
|
|
mockedSign.mockClear();
|
|
});
|
|
|
|
it('signs the assertion with only standard JWT header fields', async () => {
|
|
const ctx = mock<IExecuteFunctions>();
|
|
ctx.helpers = { request: vi.fn().mockResolvedValue({ access_token: 'token' }) } as any;
|
|
|
|
const credentials: IDataObject = {
|
|
email: 'svc@project.iam.gserviceaccount.com',
|
|
privateKey: '-----BEGIN PRIVATE KEY-----\nkey\n-----END PRIVATE KEY-----',
|
|
};
|
|
|
|
await getGoogleAccessToken.call(ctx, credentials, 'drive');
|
|
|
|
const signOptions = mockedSign.mock.calls[0][2] as { header: Record<string, unknown> };
|
|
expect(signOptions.header).toEqual({ typ: 'JWT', alg: 'RS256' });
|
|
expect(signOptions.header).not.toHaveProperty('kid');
|
|
});
|
|
});
|