This is an automated email from the ASF dual-hosted git repository. alexkli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git
commit 2da4644191a176d1abe4253f880d3599876e3048 Author: Alexander Klimetschek <aklim...@adobe.com> AuthorDate: Mon Mar 30 22:47:58 2020 -0700 quick fix for ngrok agent requiring access to invoker --- src/agentmgr.js | 4 ++-- src/agents/ngrok.js | 3 ++- src/debugger.js | 2 +- test/ngrok.test.js | 20 ++++++++++++-------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/agentmgr.js b/src/agentmgr.js index c1aa673..8753f41 100644 --- a/src/agentmgr.js +++ b/src/agentmgr.js @@ -133,7 +133,7 @@ class AgentMgr { return {action, agentAlreadyInstalled }; } - async installAgent(action) { + async installAgent(action, invoker) { this.agentInstalled = true; let agentName; @@ -143,7 +143,7 @@ class AgentMgr { if (this.argv.ngrok) { // user manually requested ngrok - this.ngrokAgent = new NgrokAgent(this.argv); + this.ngrokAgent = new NgrokAgent(this.argv, invoker); // agent using ngrok for forwarding agentName = "ngrok"; diff --git a/src/agents/ngrok.js b/src/agents/ngrok.js index d778b57..1ee2a45 100644 --- a/src/agents/ngrok.js +++ b/src/agents/ngrok.js @@ -25,8 +25,9 @@ const util = require('util'); const crypto = require("crypto"); class NgrokAgent { - constructor(argv) { + constructor(argv, invoker) { this.argv = argv; + this.invoker = invoker; } async getAgent(action) { diff --git a/src/debugger.js b/src/debugger.js index fc24b11..415bde9 100644 --- a/src/debugger.js +++ b/src/debugger.js @@ -82,7 +82,7 @@ class Debugger { await this.agentMgr.restoreAction(); } - await this.agentMgr.installAgent(action); + await this.agentMgr.installAgent(action, this.invoker); if (this.argv.onStart) { console.log("On start:", this.argv.onStart); diff --git a/test/ngrok.test.js b/test/ngrok.test.js index 0ae21b3..a095659 100644 --- a/test/ngrok.test.js +++ b/test/ngrok.test.js @@ -126,20 +126,19 @@ describe('ngrok', function() { it("should handle action invocation using ngrok", async function() { const actionName = "myaction"; + // should not use this code if we specify local sources which return CORRECT + const code = `const main = () => ({ msg: 'WRONG' });`; // port of the local server started by wskdebug to be expecting calls from ngrok // which we will do in this test - let ngrokServerPort; + let ngrokServerPort, ngrokKillInvoked, ngrokAuth; mockNgrokLibrary(function(opts) { ngrokServerPort = opts.addr; return "https://UNIT_TEST.ngrok.io"; + }, function() { + ngrokKillInvoked = true; }); - // should not use this code if we specify local sources which return CORRECT - const code = `const main = () => ({ msg: 'WRONG' });`; - - let ngrokAuth; - test.mockAction(actionName, code); test.mockCreateBackupAction(actionName); @@ -156,8 +155,11 @@ describe('ngrok', function() { .matchHeader("authorization", test.openwhiskApiAuthHeader()) .reply(200, test.nodejsActionDescription(actionName)); + test.mockReadBackupAction(actionName); + test.mockRestoreAction(actionName); + test.mockRemoveBackupAction(actionName); - // wskdebug myaction --ngrok -p ${test.port} + // wskdebug myaction action.js --ngrok -p ${test.port} const argv = { port: test.port, action: actionName, @@ -174,7 +176,7 @@ describe('ngrok', function() { await test.sleep(10); try { - + // simulate invocation coming in via ngrok forwarding const response = await fetch(`http://127.0.0.1:${ngrokServerPort}`, { method: "POST", headers: { @@ -185,6 +187,7 @@ describe('ngrok', function() { }) }); + // ensure correct result assert.strictEqual(response.status, 200); const result = await response.json(); assert.strictEqual(result.msg, "CORRECT"); @@ -193,6 +196,7 @@ describe('ngrok', function() { await dbgr.stop(); } + assert(ngrokKillInvoked); assert(nock.isDone(), "Expected these HTTP requests: " + nock.pendingMocks().join()); }); });