Skip to content

Commit

Permalink
feat(): byok revoked error handling (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivani1211 authored Sep 15, 2023
1 parent d66a330 commit 9893f02
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/@webex/internal-plugin-encryption/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const KMS_KEY_REVOKE_FAILURE = 'event:kms:key:revoke:encryption:failure';
export const KMS_KEY_REVOKE_ERROR_STATUS = 405;
export const KMS_KEY_REVOKE_ERROR_CODES = [405005, 405006];
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {safeSetTimeout} from '@webex/common-timers';
import {Batcher} from '@webex/webex-core';

import {KmsError, KmsTimeoutError} from './kms-errors';
import {KmsError, KmsTimeoutError, handleKmsKeyRevokedEncryptionFailure} from './kms-errors';

export const TIMEOUT_SYMBOL = Symbol('TIMEOUT_SYMBOL');

Expand Down Expand Up @@ -133,6 +133,8 @@ const KmsBatcher = Batcher.extend({
* @returns {Promise}
*/
handleItemFailure(item, reason) {
handleKmsKeyRevokedEncryptionFailure(item, this.webex);

return this.getDeferredForResponse(item).then((defer) => {
defer.reject(reason || new KmsError(item.body));
});
Expand Down
20 changes: 20 additions & 0 deletions packages/@webex/internal-plugin-encryption/src/kms-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import {Exception} from '@webex/common';
import {WebexHttpError} from '@webex/webex-core';

import {
KMS_KEY_REVOKE_ERROR_CODES,
KMS_KEY_REVOKE_FAILURE,
KMS_KEY_REVOKE_ERROR_STATUS,
} from './constants';

/**
* Error class for KMS errors
*/
Expand Down Expand Up @@ -145,3 +151,17 @@ export class DryError extends WebexHttpError {
return message;
}
}

/**
* Function triggers an event when specific encryption failures are received.
*/

// eslint-disable-next-line consistent-return
export const handleKmsKeyRevokedEncryptionFailure = (item, webex) => {
if (
item.status === KMS_KEY_REVOKE_ERROR_STATUS &&
KMS_KEY_REVOKE_ERROR_CODES.includes(item.body.errorCode)
) {
webex.internal.encryption.trigger(KMS_KEY_REVOKE_FAILURE);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {assert} from '@webex/test-helper-chai';
import {handleKmsKeyRevokedEncryptionFailure} from '../../../src/kms-errors'
import sinon from 'sinon';

describe('handleKmsKeyRevokedEncryptionFailure', () => {

it('triggers `event:kms:key:revoke:encryption:failure` event when correct error code is detected', () => {
const webex = {
internal: {
encryption: {
trigger: sinon.spy()
},
},
}

const item = {
status: 405,
body: {
errorCode: 405005,
}
}

handleKmsKeyRevokedEncryptionFailure(item, webex);

assert.calledOnce(webex.internal.encryption.trigger);
assert.calledWithExactly(webex.internal.encryption.trigger, `event:kms:key:revoke:encryption:failure`);
});

it('does not trigger `event:kms:key:revoke:encryption:failure` event when correct status but wrong error code is detected', () => {
const webex = {
internal: {
encryption: {
trigger: sinon.spy()
},
},
}

const item = {
status: 405,
body: {
errorCode: 405009,
}
}

handleKmsKeyRevokedEncryptionFailure(item, webex);

assert.notCalled(webex.internal.encryption.trigger);
});

it('does not trigger `event:kms:key:revoke:encryption:failure` event when wrong status but correct error code is detected', () => {
const webex = {
internal: {
encryption: {
trigger: sinon.spy()
},
},
}

const item = {
status: 403,
body: {
errorCode: 405005,
}
}

handleKmsKeyRevokedEncryptionFailure(item, webex);

assert.notCalled(webex.internal.encryption.trigger);
});
});

0 comments on commit 9893f02

Please sign in to comment.