From b4c30ffae95a5528bb4c03583ded9b6aeadacf25 Mon Sep 17 00:00:00 2001 From: seebees Date: Mon, 29 Jul 2019 16:42:55 -0700 Subject: [PATCH] test: Condition tests for web-crypto-backend --- .../test/backend-factory.test.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/web-crypto-backend/test/backend-factory.test.ts b/modules/web-crypto-backend/test/backend-factory.test.ts index 80f317211..a734751ab 100644 --- a/modules/web-crypto-backend/test/backend-factory.test.ts +++ b/modules/web-crypto-backend/test/backend-factory.test.ts @@ -19,7 +19,13 @@ import * as chai from 'chai' import chaiAsPromised from 'chai-as-promised' import sinon from 'sinon' import 'mocha' -import { pluckSubtleCrypto, windowRequiresFallback, webCryptoBackendFactory } from '../src/backend-factory' +import { + pluckSubtleCrypto, + windowRequiresFallback, + webCryptoBackendFactory, + getNonZeroByteBackend, + getZeroByteSubtle +} from '../src/backend-factory' import * as browserWindow from '@aws-sdk/util-locate-window' import * as fixtures from './fixtures' @@ -189,3 +195,25 @@ describe('webCryptoBackendFactory', () => { }) }) }) + +describe('getNonZeroByteBackend', () => { + it('gets a subtle backend', () => { + const test = getNonZeroByteBackend(fixtures.subtleFallbackSupportsZeroByteGCM) + expect(test === fixtures.subtleFallbackSupportsZeroByteGCM.subtle).to.equal(true) + }) + + it('Precondition: A backend must be passed to get a non zero byte backend.', () => { + expect(() => getNonZeroByteBackend(false)).to.throw('No supported backend.') + }) +}) + +describe('getZeroByteSubtle', () => { + it('gets a subtle backend', () => { + const test = getZeroByteSubtle(fixtures.subtleFallbackSupportsZeroByteGCM) + expect(test === fixtures.subtleFallbackSupportsZeroByteGCM.subtle).to.equal(true) + }) + + it('Precondition: A backend must be passed to get a zero byte backend.', () => { + expect(() => getZeroByteSubtle(false)).to.throw('No supported backend.') + }) +})