Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Ngrok Debugger Implementation #2032

Merged
merged 30 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4507aaf
Basic ngrok debugger setup
Dec 13, 2019
902b061
Ui updates completed for ngrok debug console
Dec 17, 2019
0213324
Ngrok redux setup completed. Actions hooked up to ngrokDebugContainer
Dec 20, 2019
1d7c28b
Wrapped up all inputs going into the debuggr ngrok component
Dec 20, 2019
8c969f3
Broadcasting error response
Dec 27, 2019
3d7f8b9
Write stream tests passed
Dec 27, 2019
4b1aadb
Get path initializer
Dec 27, 2019
abe0bf2
Refactoring fn names
Jan 3, 2020
105138e
Reconnect to ngrok functionality completed
Jan 6, 2020
8f4af7b
UI test updated for ngrok container
Jan 6, 2020
95fe0fd
All lock files and fresh installs done
Jan 6, 2020
23b4d99
removed unneeded scss
Jan 6, 2020
ef83075
Renaming classes
Jan 6, 2020
2d9492c
Linter errors and fixes for it across all packages
Jan 6, 2020
ad8a57a
Removed prefixed slash
Jan 6, 2020
7d9f8a9
added rebuild keytar script inside main
Jan 6, 2020
e778e50
Added lock file to ignore
Jan 7, 2020
a9daa47
Revert keytar to old version
Jan 7, 2020
92ed4d1
Updatting postman collection to leverage global variables
Jan 7, 2020
aa20468
Debug container UI tests
Jan 7, 2020
9a34510
Mock Jest Date implementation
Jan 7, 2020
b11dd49
PR review feedback addressed
Jan 9, 2020
3b8f04f
Pre feedback addressed
Jan 9, 2020
88f6642
Made sure all pacjage locks are removed and spacing between cases
Jan 9, 2020
7ce584a
PR review feedback addressed
Jan 9, 2020
49cb853
One more package lock deleted
Jan 9, 2020
f57b6e4
Qna maker package lock removed
Jan 9, 2020
e65aa20
Tests updated after refactor
Jan 9, 2020
c6ff96f
Pr feedback addressed
Jan 10, 2020
6c08711
More copy fixes
Jan 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build/
.vscode/*
chrome-driver-log.txt
.env
/packages/**/package-lock.json
1,011 changes: 525 additions & 486 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions packages/app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"lint:fix": "npm run lint -- --fix",
"start": "run-s build:shared:dev webpackdevServer:dev",
"webpackdevServer:dev": "webpack-dev-server --mode development --hot --inline --progress --colors --content-base ./public",
"test": "jest"
"test": "jest",
"test:watch": "jest --watch"
},
"jest": {
"setupTestFrameworkScriptFile": "../../../../testSetup.js",
Expand Down Expand Up @@ -51,8 +52,8 @@
"@babel/preset-typescript": "^7.1.0",
"@types/enzyme": "^3.1.10",
"@types/jest": "24.0.13",
"@types/react": "~16.3.2",
"@types/react-dom": "^16.0.4",
"@types/react": "16.9.17",
"@types/react-dom": "16.9.4",
"@types/request": "^2.47.0",
"babel-eslint": "^10.0.1",
"babel-jest": "24.8.0",
Expand Down Expand Up @@ -111,8 +112,8 @@
"botframework-webchat-core": "4.7.1",
"eslint-plugin-react": "^7.12.3",
"markdown-it": "^8.4.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/app/client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ export const CONTENT_TYPE_APP_SETTINGS = 'application/vnd.microsoft.bfemulator.d
export const CONTENT_TYPE_WELCOME_PAGE = 'application/vnd.microsoft.bfemulator.document.welcome';
export const CONTENT_TYPE_TRANSCRIPT = 'application/vnd.microsoft.bfemulator.document.transcript';
export const CONTENT_TYPE_LIVE_CHAT = SharedConstants.ContentTypes.CONTENT_TYPE_LIVE_CHAT;
export const CONTENT_TYPE_NGROK_DEBUGGER = SharedConstants.ContentTypes.CONTENT_TYPE_NGROK_DEBUGGER;

export const NAVBAR_BOT_EXPLORER = 'navbar.botExplorer';
export const NAVBAR_SETTINGS = 'navbar.settings';
export const NAVBAR_NOTIFICATIONS = 'navbar.notifications';
export const NAVBAR_RESOURCES = 'navbar:resources';
export const NAVBAR_RESOURCES = 'navbar.resources';
export const NAVBAR_NGROK_DEBUGGER = 'navbar.ngrokDebugger';

export const EDITOR_KEY_PRIMARY = 'primary';
export const EDITOR_KEY_SECONDARY = 'secondary';
Expand Down
1 change: 1 addition & 0 deletions packages/app/client/src/state/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export * from './savedBotUrlsActions';
export * from './updateActions';
export * from './userActions';
export * from './windowStateActions';
export * from './ngrokTunnelActions';
76 changes: 76 additions & 0 deletions packages/app/client/src/state/actions/ngrokTunnelActions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// 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 {
updateNewTunnelInfo,
updateTunnelError,
updateTunnelStatus,
NgrokTunnelActions,
TunnelInfo,
TunnelError,
TunnelStatus,
} from './ngrokTunnelActions';

describe('Ngrok Tunnel Actions', () => {
it('should create an update tunnel info action', () => {
const payload: TunnelInfo = {
publicUrl: 'https://d1a2bf16.ngrok.io',
inspectUrl: 'http://127.0.0.1:4041',
logPath: 'ngrok.log',
postmanCollectionPath: 'postman.json',
};
const action = updateNewTunnelInfo(payload);
expect(action.type).toBe(NgrokTunnelActions.setDetails);
expect(action.payload).toEqual(payload);
});

it('should create a update tunnel error action', () => {
const payload: TunnelError = {
statusCode: 402,
errorMessage: 'Tunnel has expired',
};
const action = updateTunnelError(payload);
expect(action.type).toBe(NgrokTunnelActions.updateOnError);
expect(action.payload).toEqual(payload);
});

it('should create a tunnel status update action', () => {
const mockDate = new Date(1466424490000);
jest.spyOn(global, 'Date').mockImplementation(() => mockDate as any);
const expectedStatus: TunnelStatus = TunnelStatus.Active;
const action = updateTunnelStatus(expectedStatus);
expect(action.type).toBe(NgrokTunnelActions.setStatus);
expect(action.payload.timestamp).toBe(new Date().toLocaleString());
expect(action.payload.status).toBe(expectedStatus);
});
});
93 changes: 93 additions & 0 deletions packages/app/client/src/state/actions/ngrokTunnelActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// 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 { Action } from 'redux';

export enum NgrokTunnelActions {
setDetails = 'NgrokTunnel/SET_DETAILS',
updateOnError = 'NgrokTunnel/TUNNEL_ERROR',
setStatus = 'NgrokTunnel/STATUS_CHECK',
}

export enum TunnelStatus {
Active,
Inactive,
Error,
}

export interface TunnelInfo {
publicUrl: string;
inspectUrl: string;
logPath: string;
postmanCollectionPath: string;
}

export interface TunnelError {
statusCode: number;
errorMessage: string;
}

export interface TunnelStatusAndTimestamp {
status: TunnelStatus;
timestamp: string;
}

export interface NgrokTunnelAction<T> extends Action {
type: NgrokTunnelActions;
payload: T;
}

export type NgrokTunnelPayloadTypes = TunnelError | TunnelInfo | TunnelStatusAndTimestamp;

export function updateNewTunnelInfo(payload: TunnelInfo): NgrokTunnelAction<TunnelInfo> {
return {
type: NgrokTunnelActions.setDetails,
payload,
};
}

export function updateTunnelStatus(tunnelStatus: TunnelStatus): NgrokTunnelAction<TunnelStatusAndTimestamp> {
return {
type: NgrokTunnelActions.setStatus,
payload: {
status: tunnelStatus,
timestamp: new Date().toLocaleString(),
},
};
}

export function updateTunnelError(payload: TunnelError): NgrokTunnelAction<TunnelError> {
return {
type: NgrokTunnelActions.updateOnError,
payload,
};
}
1 change: 1 addition & 0 deletions packages/app/client/src/state/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ export * from './theme';
export * from './update';
export * from './users';
export * from './windowState';
export * from './ngrokTunnel';
128 changes: 128 additions & 0 deletions packages/app/client/src/state/reducers/ngrokTunnel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// 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 {
TunnelStatus,
NgrokTunnelAction,
TunnelInfo,
NgrokTunnelPayloadTypes,
NgrokTunnelActions,
TunnelError,
TunnelStatusAndTs,
} from '../actions/ngrokTunnelActions';

import { ngrokTunnel, NgrokTunnelState } from './ngrokTunnel';

describe('Ngrok Tunnel reducer', () => {
const DEFAULT_STATE: NgrokTunnelState = {
inspectUrl: 'http://127.0.0.1:4040',
publicUrl: '',
logPath: '',
postmanCollectionPath: '',
errors: {} as TunnelError,
tunnelStatus: TunnelStatus.Inactive,
lastTunnelStatusCheckTS: '',
};

afterEach(() => {
const emptyAction: NgrokTunnelAction<NgrokTunnelPayloadTypes> = {
type: null,
payload: null,
};
ngrokTunnel({ ...DEFAULT_STATE }, emptyAction);
});

it('Tunnel info should be set from payload', () => {
const payload: TunnelInfo = {
publicUrl: 'https://abc.io/',
inspectUrl: 'http://127.0.0.1:4003',
logPath: 'logger.txt',
postmanCollectionPath: 'postman.json',
};
const setDetailsAction: NgrokTunnelAction<NgrokTunnelPayloadTypes> = {
type: NgrokTunnelActions.setDetails,
payload,
};
const startingState = { ...DEFAULT_STATE };
const endingState = ngrokTunnel(startingState, setDetailsAction);

expect(endingState.publicUrl).toBe(payload.publicUrl);
expect(endingState.logPath).toBe(payload.logPath);
expect(endingState.postmanCollectionPath).toBe(payload.postmanCollectionPath);
expect(endingState.inspectUrl).toBe(payload.inspectUrl);
});

it('Tunnel errors should be set from payload', () => {
const payload: TunnelError = {
statusCode: 422,
errorMessage: '<h1>Too many connections<h1>',
};
const updateErrorAction: NgrokTunnelAction<NgrokTunnelPayloadTypes> = {
type: NgrokTunnelActions.updateOnError,
payload,
};
const startingState = { ...DEFAULT_STATE };
const endingState = ngrokTunnel(startingState, updateErrorAction);

expect(endingState.publicUrl).toBe(DEFAULT_STATE.publicUrl);
expect(endingState.errors.statusCode).toBe(payload.statusCode);
expect(endingState.errors.errorMessage).toBe(payload.errorMessage);
});

it('Tunnel status should be set from payload', () => {
const payload: TunnelStatusAndTs = {
status: TunnelStatus.Active,
ts: '12/27/2019, 1:30:00 PM',
};
const nextPayload: TunnelStatusAndTs = {
status: TunnelStatus.Error,
ts: '12/27/2019, 1:33:00 PM',
};
const actions: NgrokTunnelAction<NgrokTunnelPayloadTypes>[] = [
{
type: NgrokTunnelActions.setStatus,
payload,
},
{
type: NgrokTunnelActions.setStatus,
payload: nextPayload,
},
];
const startingState = { ...DEFAULT_STATE };
const transientState = ngrokTunnel(startingState, actions[0]);
expect(transientState.tunnelStatus).toBe(payload.status);

const finalState = ngrokTunnel(startingState, actions[1]);
expect(finalState.tunnelStatus).toBe(nextPayload.status);
});
});
Loading