From ca63f21113780643db35401f1c8dd5ba83228073 Mon Sep 17 00:00:00 2001 From: Pierre-Yves B Date: Sun, 12 Sep 2021 20:48:23 +0100 Subject: [PATCH] Stop attempting to override Accept header in [GitHub] API provider (#7013) --- services/github/github-api-provider.js | 1 - services/github/github-auth-service.spec.js | 56 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 services/github/github-auth-service.spec.js diff --git a/services/github/github-api-provider.js b/services/github/github-api-provider.js index eefbe1b966892..bfb26c20abf77 100644 --- a/services/github/github-api-provider.js +++ b/services/github/github-api-provider.js @@ -178,7 +178,6 @@ class GithubApiProvider { baseUrl, headers: { 'User-Agent': userAgent, - Accept: 'application/vnd.github.v3+json', Authorization: `token ${tokenString}`, ...options.headers, }, diff --git a/services/github/github-auth-service.spec.js b/services/github/github-auth-service.spec.js new file mode 100644 index 0000000000000..928589400626a --- /dev/null +++ b/services/github/github-auth-service.spec.js @@ -0,0 +1,56 @@ +import Joi from 'joi' +import { expect } from 'chai' +import sinon from 'sinon' +import { GithubAuthV3Service } from './github-auth-service.js' +import GithubApiProvider from './github-api-provider.js' + +describe('GithubAuthV3Service', function () { + class DummyGithubAuthV3Service extends GithubAuthV3Service { + static category = 'build' + static route = { base: 'runs' } + + async handle() { + const { requiredString } = await this._requestJson({ + schema: Joi.object({ + requiredString: Joi.string().required(), + }).required(), + url: 'https://github-api.example.com/repos/badges/shields/check-runs', + options: { + headers: { + Accept: 'application/vnd.github.antiope-preview+json', + }, + }, + }) + return { message: requiredString } + } + } + + it('forwards custom Accept header', async function () { + const sendAndCacheRequestWithCallbacks = sinon.stub().returns( + Promise.resolve({ + buffer: '{"requiredString": "some-string"}', + res: { statusCode: 200 }, + }) + ) + const githubApiProvider = new GithubApiProvider({ + baseUrl: 'https://github-api.example.com', + }) + const mockToken = { update: sinon.mock(), invalidate: sinon.mock() } + sinon.stub(githubApiProvider.standardTokens, 'next').returns(mockToken) + + DummyGithubAuthV3Service.invoke({ + sendAndCacheRequestWithCallbacks, + githubApiProvider, + }) + + expect(sendAndCacheRequestWithCallbacks).to.have.been.calledOnceWith({ + headers: { + 'User-Agent': 'Shields.io/2003a', + Accept: 'application/vnd.github.antiope-preview+json', + Authorization: 'token undefined', + }, + url: 'https://github-api.example.com/repos/badges/shields/check-runs', + baseUrl: 'https://github-api.example.com', + }) + }) +})