Skip to content

Commit

Permalink
Reset RSA access state on connect.core.terminate() (#828)
Browse files Browse the repository at this point in the history
Reset RSA access state on connect.core.terminate()
---------

Co-authored-by: Andy Wang <[email protected]>
  • Loading branch information
andywang219 and Andy Wang authored Jan 16, 2024
1 parent d7fc746 commit a1cb44c
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-connect-streams",
"version": "2.4.12",
"version": "2.4.13",
"description": "Amazon Connect Streams Library",
"engines": {
"node": ">=12.0.0"
Expand Down
2 changes: 1 addition & 1 deletion release/connect-streams-min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion release/connect-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -25652,7 +25652,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-

connect.core = {};
connect.core.initialized = false;
connect.version = "2.4.12";
connect.version = "2.4.13";
connect.DEFAULT_BATCH_SIZE = 500;

var CCP_SYN_TIMEOUT = 1000; // 1 sec
Expand Down Expand Up @@ -25832,6 +25832,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
connect.core.softphoneManager = null;
connect.core.upstream = null;
connect.core.keepaliveManager = null;
connect.storageAccess.resetStorageAccessState();
connect.agent.initialized = false;
connect.core.initialized = false;
};
Expand Down Expand Up @@ -29389,6 +29390,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
storageParams = {};
originalCCPUrl = '';
rsaContainer = null;
onGrantCallbackInvoked = false;
};

/**
Expand Down Expand Up @@ -29653,6 +29655,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
getRequestStorageAccessUrl,
storageAccessEvents,
resetStorageAccessState,
getOnGrantCallbackInvoked: () => onGrantCallbackInvoked,
getStorageAccessParams: () => storageParams,
onRequest: onRequestHandler,
request: () => {
Expand Down
1 change: 1 addition & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
connect.core.softphoneManager = null;
connect.core.upstream = null;
connect.core.keepaliveManager = null;
connect.storageAccess.resetStorageAccessState();
connect.agent.initialized = false;
connect.core.initialized = false;
};
Expand Down
2 changes: 2 additions & 0 deletions src/request-storage-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
storageParams = {};
originalCCPUrl = '';
rsaContainer = null;
onGrantCallbackInvoked = false;
};

/**
Expand Down Expand Up @@ -346,6 +347,7 @@
getRequestStorageAccessUrl,
storageAccessEvents,
resetStorageAccessState,
getOnGrantCallbackInvoked: () => onGrantCallbackInvoked,
getStorageAccessParams: () => storageParams,
onRequest: onRequestHandler,
request: () => {
Expand Down
81 changes: 81 additions & 0 deletions test/unit/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,87 @@ describe('Core', function () {
});
});

describe('#connect.core.terminate()', function () {
jsdom({ url: "http://localhost" });
function isCCPInitialized(containerDiv, params) {
try {
expect(params.ccpUrl).not.to.be.a("null");
expect(containerDiv).not.to.be.a("null");
assert.isTrue(document.createElement.calledOnce);
assert.isTrue(containerDiv.appendChild.calledOnce);
return true;
} catch(e) {
console.log("InitCCP initialization failed: ",e);
return false;
}
}
function isCCPTerminated() {
try {
assert.isEmpty(connect.core.client);
assert.isEmpty(connect.core.agentAppClient);
assert.isEmpty(connect.core.masterClient);
assert.isNull(connect.core.agentDataProvider);
assert.isNull(connect.core.softphoneManager);
assert.isNull(connect.core.upstream);
assert.isNull(connect.core.keepaliveManager);
assert.isFalse(connect.agent.initialized);
assert.isFalse(connect.core.initialized);
assert.isFalse(connect.core.eventBus.logEvents);
return true;
} catch(e) {
console.log("InitCCP Terminated failed: ",e);
return false;
}
}
let containerDiv;
const softphoneParams = { allowFramedSoftphone: true };

before(function () {
containerDiv = { appendChild: sandbox.spy() };
params = {
ccpUrl: "url.com",
softphone: softphoneParams,
loginOptions: { autoClose: true }
};

sandbox.spy(document, "createElement");
connect.core.initialized = false;
});

afterEach(function () {
sandbox.resetHistory();
});

it("Checking if Connect is uninitialized", function () {
connect.core.initCCP(containerDiv, params);
expect(isCCPInitialized(containerDiv, params)).to.be.true;
connect.core.terminate();
expect(isCCPTerminated()).to.be.true;
});

it("Check if CCP is initialized after calling terminate function and re-calling initCCP", function () {
const storageAccessOriginal = connect.storageAccess;
connect.storageAccess = { ...connect.storageAccess, resetStorageAccessState: sinon.fake()};

expect(params.ccpUrl).not.to.be.a("null");
expect(containerDiv).not.to.be.a("null");
connect.core.initCCP(containerDiv, params);
expect(isCCPInitialized(containerDiv, params)).to.be.true;

connect.core.terminate();
expect(connect.storageAccess.resetStorageAccessState.calledOnce).to.be.true;

connect.core.terminate();
expect(connect.storageAccess.resetStorageAccessState.calledTwice).to.be.true;

expect(isCCPTerminated()).to.be.true;
sandbox.resetHistory();
connect.core.initCCP(containerDiv, params);
expect(isCCPInitialized(containerDiv, params)).to.be.true;
connect.storageAccess = storageAccessOriginal;
});
});

describe('onIframeRetriesExhausted', () => {
after(() => {
sandbox.restore();
Expand Down
45 changes: 25 additions & 20 deletions test/unit/request-storage-access.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,31 @@ describe('Request Storage Access module', () => {
});

it('Should trigger REQUEST post message and invoke onGrant callback', () => {
mockMessageFromIframe({
event: connect.storageAccess.storageAccessEvents.GRANTED,
data: {},
});

connect.storageAccess.init(ccpUrl, container);
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
connect.storageAccess.request();

expect(postMessageSpy.called).to.be.true;
let storageAccessRequestArgs = postMessageSpy.getCall(0).args[0];
console.log(storageAccessRequestArgs);
expect(storageAccessRequestArgs.event).to.be.equals('storageAccess::request');
expect(storageAccessRequestArgs.data.landat).to.be.equals('/connect/ccp-v2');

expect(onGrantSpy.called).to.be.true;
connect.storageAccess.request();

/** Should be called only once */
expect(onGrantSpy.calledTwice).not.to.be.true;
mockMessageFromIframe({
event: connect.storageAccess.storageAccessEvents.GRANTED,
data: {},
});

connect.storageAccess.init(ccpUrl, container);
expect(connect.storageAccess.getOnGrantCallbackInvoked()).to.be.false;
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
connect.storageAccess.request();

expect(postMessageSpy.called).to.be.true;
let storageAccessRequestArgs = postMessageSpy.getCall(0).args[0];
console.log(storageAccessRequestArgs);
expect(storageAccessRequestArgs.event).to.be.equals('storageAccess::request');
expect(storageAccessRequestArgs.data.landat).to.be.equals('/connect/ccp-v2');

expect(onGrantSpy.called).to.be.true;
expect(connect.storageAccess.getOnGrantCallbackInvoked()).to.be.true;
connect.storageAccess.request();

/** Should be called only once */
expect(onGrantSpy.calledTwice).not.to.be.true;

connect.storageAccess.resetStorageAccessState();
expect(connect.storageAccess.getOnGrantCallbackInvoked()).to.be.false;
});

it('Should hide container if mode is custom after granting access', () => {
Expand Down

0 comments on commit a1cb44c

Please sign in to comment.