diff --git a/ghost/api-version-compatibility-service/lib/api-version-compatibility-service.js b/ghost/api-version-compatibility-service/lib/api-version-compatibility-service.js index 171cf9387f..e15ab69c3a 100644 --- a/ghost/api-version-compatibility-service/lib/api-version-compatibility-service.js +++ b/ghost/api-version-compatibility-service/lib/api-version-compatibility-service.js @@ -16,15 +16,16 @@ class APIVersionCompatibilityService { async handleMismatch({acceptVersion, contentVersion, userAgent = ''}) { if (!await this.fetchHandled(acceptVersion)) { + const trimmedUseAgent = userAgent.split('/')[0]; const emailTemplate = ` - ${userAgent} integration expected Ghost version: ${acceptVersion} + ${trimmedUseAgent} integration expected Ghost version: ${acceptVersion} Current Ghost version: ${contentVersion} `; const emails = await this.fetchEmailsToNotify(); for (const email of emails) { await this.sendEmail({ - subject: `Attention required: Your ${userAgent} integration has failed`, + subject: `Attention required: Your ${trimmedUseAgent} integration has failed`, to: email, html: emailTemplate }); diff --git a/ghost/api-version-compatibility-service/test/api-version-compatibility-service.test.js b/ghost/api-version-compatibility-service/test/api-version-compatibility-service.test.js index 0e3c4b346d..28be1888d8 100644 --- a/ghost/api-version-compatibility-service/test/api-version-compatibility-service.test.js +++ b/ghost/api-version-compatibility-service/test/api-version-compatibility-service.test.js @@ -113,4 +113,29 @@ describe('APIVersionCompatibilityService', function () { assert.match(sendEmail.args[2][0].html, /Elaborate Fox integration expected Ghost version: v4.8/); assert.match(sendEmail.args[2][0].html, /Current Ghost version: v5.1/); }); + + it('Trims down the name of the integration when a lot of meta information is present in user-agent header', async function (){ + const sendEmail = sinon.spy(); + const fetchHandled = sinon.spy(); + const saveHandled = sinon.spy(); + + const compatibilityService = new APIVersionCompatibilityService({ + sendEmail, + fetchEmailsToNotify: async () => ['test_env@example.com'], + fetchHandled, + saveHandled + }); + + await compatibilityService.handleMismatch({ + acceptVersion: 'v4.5', + contentVersion: 'v5.1', + userAgent: 'Zapier/2.3 GhostAdminSDK/2.4.0' + }); + + assert.equal(sendEmail.called, true); + assert.equal(sendEmail.args[0][0].to, 'test_env@example.com'); + assert.equal(sendEmail.args[0][0].subject, `Attention required: Your Zapier integration has failed`); + assert.match(sendEmail.args[0][0].html, /Zapier integration expected Ghost version: v4.5/); + assert.match(sendEmail.args[0][0].html, /Current Ghost version: v5.1/); + }); });