From dba9b8e4c03fce9a54381bc2ea4d2c269a1dc462 Mon Sep 17 00:00:00 2001 From: Tony Anziano Date: Fri, 12 Apr 2019 11:32:40 -0700 Subject: [PATCH] Removed custom user agent string from outgoing requests. --- CHANGELOG.md | 3 ++ .../app/main/src/appendCustomUserAgent.ts | 43 ------------------- packages/app/main/src/main.ts | 4 -- .../log/logService.spec.ts} | 43 ++++++++++--------- 4 files changed, 26 insertions(+), 67 deletions(-) delete mode 100644 packages/app/main/src/appendCustomUserAgent.ts rename packages/app/main/src/{appendCustomUserAgent.spec.ts => platform/log/logService.spec.ts} (61%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10fa659c9..6dd6b33d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [ui-react] Added default disabled styling to checkbox control in PR [1424](https://github.com/Microsoft/BotFramework-Emulator/pull/1424) - [client] Fixed issue where BOM wasn't being stripped from transcripts opened via the File menu in PR [1425](https://github.com/Microsoft/BotFramework-Emulator/pull/1425) +## Removed +- [main] Removed custom user agent string from outgoing requests in PR [1427](https://github.com/Microsoft/BotFramework-Emulator/pull/1427) + ## v4.3.3 - 2019 - 03 - 14 ## Fixed - [client] Use correct casing for user id prop for web chat in PR [#1374](https://github.com/Microsoft/BotFramework-Emulator/pull/1374) diff --git a/packages/app/main/src/appendCustomUserAgent.ts b/packages/app/main/src/appendCustomUserAgent.ts deleted file mode 100644 index 2f9711e35..000000000 --- a/packages/app/main/src/appendCustomUserAgent.ts +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. -// -// Microsoft Bot Framework: http://botframework.com -// -// Bot Framework Emulator Github: -// https://github.com/Microsoft/BotFramwork-Emulator -// -// Copyright (c) Microsoft Corporation -// All rights reserved. -// -// MIT License: -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -import * as Electron from 'electron'; - -export function appendCustomUserAgent(details: any, callback: (...args: any[]) => any): void { - const { requestHeaders = {} } = details; - const version = Electron.app.getVersion(); - - requestHeaders['User-Agent'] += ` botbuilder/emulator/${version}`; - - callback({ cancel: false, requestHeaders }); -} diff --git a/packages/app/main/src/main.ts b/packages/app/main/src/main.ts index 6435318fd..d142d7e79 100644 --- a/packages/app/main/src/main.ts +++ b/packages/app/main/src/main.ts @@ -41,7 +41,6 @@ import { app, BrowserWindow, dialog, ipcMain, Rectangle, screen, systemPreferenc import { UpdateInfo } from 'electron-updater'; import { Store } from 'redux'; -import { appendCustomUserAgent } from './appendCustomUserAgent'; import { AppMenuBuilder } from './appMenuBuilder'; import { AppUpdater } from './appUpdater'; import { getStore } from './botData/store'; @@ -298,9 +297,6 @@ const createMainWindow = async () => { }) ); - // attach custom user agent string - mainWindow.webContents.session.webRequest.onBeforeSendHeaders(appendCustomUserAgent); - // get reference to bots list in state for comparison against state changes let botsRef = store.getState().bot.botFiles; diff --git a/packages/app/main/src/appendCustomUserAgent.spec.ts b/packages/app/main/src/platform/log/logService.spec.ts similarity index 61% rename from packages/app/main/src/appendCustomUserAgent.spec.ts rename to packages/app/main/src/platform/log/logService.spec.ts index e5233f0b6..f2d4f1347 100644 --- a/packages/app/main/src/appendCustomUserAgent.spec.ts +++ b/packages/app/main/src/platform/log/logService.spec.ts @@ -31,28 +31,31 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -import { appendCustomUserAgent } from './appendCustomUserAgent'; +import { SharedConstants } from '@bfemulator/app-shared'; +import { logEntry, LogLevel, textItem } from '@bfemulator/sdk-shared'; -const mockVersion = 'v4.5.6'; -jest.mock('electron', () => ({ - app: { - getVersion: () => mockVersion, - }, -})); +import { LogService } from './logService'; -it('should append a custom user agent to outgoing requests', () => { - const mockDetails = { - requestHeaders: { - 'User-Agent': 'some/user/agent', - }, - }; - const callBack = jest.fn((...args: any[]) => null); - appendCustomUserAgent(mockDetails, callBack); +describe('LogService', () => { + it('should log items to chat', () => { + // lock down the time so that the timestamp doesn't break the test + Date.now = () => 123; - expect(callBack).toHaveBeenCalledWith({ - cancel: false, - requestHeaders: { - 'User-Agent': `some/user/agent botbuilder/emulator/${mockVersion}`, - }, + const mockRemoteCall = jest.fn(() => null); + const window: any = { + commandService: { + remoteCall: mockRemoteCall, + }, + }; + const logService = new LogService(window); + const item1 = textItem(LogLevel.Debug, 'someText'); + const item2 = textItem(LogLevel.Info, 'someOtherText'); + logService.logToChat('someConvoId', item1, item2); + + expect(mockRemoteCall).toHaveBeenCalledWith( + SharedConstants.Commands.Emulator.AppendToLog, + 'someConvoId', + logEntry(item1, item2) + ); }); });