5
5
6
6
import * as chai from 'chai'
7
7
import chaiAsPromised from 'chai-as-promised'
8
- import sinon from 'sinon'
9
8
// import 'mocha'
10
9
import {
11
10
pluckSubtleCrypto ,
@@ -14,7 +13,6 @@ import {
14
13
getNonZeroByteBackend ,
15
14
getZeroByteSubtle ,
16
15
} from '../src/backend-factory'
17
- import * as browserWindow from '@aws-sdk/util-locate-window'
18
16
19
17
import * as fixtures from './fixtures'
20
18
chai . use ( chaiAsPromised )
@@ -55,47 +53,28 @@ describe('windowRequiresFallback', () => {
55
53
describe ( 'webCryptoBackendFactory' , ( ) => {
56
54
describe ( 'configureFallback' , ( ) => {
57
55
it ( 'returns a valid and configured fallback.' , async ( ) => {
58
- const { locateWindow } = browserWindow
59
- sinon
60
- . stub ( browserWindow , 'locateWindow' )
61
- . returns ( fixtures . fakeWindowNoWebCrypto )
62
-
63
56
const { configureFallback } = webCryptoBackendFactory (
64
57
fixtures . fakeWindowNoWebCrypto
65
58
)
66
59
const test = await configureFallback (
67
60
fixtures . subtleFallbackSupportsZeroByteGCM
68
61
)
69
62
70
- // @ts -ignore
71
- browserWindow . locateWindow = locateWindow
72
63
expect ( test === fixtures . subtleFallbackSupportsZeroByteGCM ) . to . equal ( true )
73
64
} )
74
65
75
66
it ( 'Precondition: If a fallback is not required, do not configure one.' , async ( ) => {
76
- const { locateWindow } = browserWindow
77
- sinon
78
- . stub ( browserWindow , 'locateWindow' )
79
- . returns ( fixtures . fakeWindowWebCryptoSupportsZeroByteGCM )
80
-
81
67
const { configureFallback } = webCryptoBackendFactory (
82
68
fixtures . fakeWindowWebCryptoSupportsZeroByteGCM
83
69
)
84
70
const test = await configureFallback (
85
71
fixtures . subtleFallbackSupportsZeroByteGCM
86
72
)
87
- // @ts -ignore
88
- browserWindow . locateWindow = locateWindow
89
73
90
74
expect ( test ) . to . equal ( undefined )
91
75
} )
92
76
93
77
it ( 'Precondition: Can not reconfigure fallback.' , async ( ) => {
94
- const { locateWindow } = browserWindow
95
- sinon
96
- . stub ( browserWindow , 'locateWindow' )
97
- . returns ( fixtures . fakeWindowWebCryptoOnlyRandomSource )
98
-
99
78
const { configureFallback } = webCryptoBackendFactory (
100
79
fixtures . fakeWindowWebCryptoOnlyRandomSource
101
80
)
@@ -104,61 +83,35 @@ describe('webCryptoBackendFactory', () => {
104
83
await expect (
105
84
configureFallback ( fixtures . subtleFallbackSupportsZeroByteGCM )
106
85
) . to . rejectedWith ( Error )
107
-
108
- // @ts -ignore
109
- browserWindow . locateWindow = locateWindow
110
86
} )
111
87
112
88
it ( 'Precondition: Fallback must look like it supports the required operations.' , async ( ) => {
113
- const { locateWindow } = browserWindow
114
- sinon
115
- . stub ( browserWindow , 'locateWindow' )
116
- . returns ( fixtures . fakeWindowWebCryptoOnlyRandomSource )
117
-
118
89
const { configureFallback } = webCryptoBackendFactory (
119
90
fixtures . fakeWindowWebCryptoOnlyRandomSource
120
91
)
121
92
122
93
await expect (
123
94
configureFallback ( fixtures . subtleFallbackNoWebCrypto )
124
95
) . to . rejectedWith ( Error )
125
-
126
- // @ts -ignore
127
- browserWindow . locateWindow = locateWindow
128
96
} )
129
97
130
98
it ( 'Postcondition: The fallback must specifically support ZeroByteGCM.' , async ( ) => {
131
- const { locateWindow } = browserWindow
132
- sinon
133
- . stub ( browserWindow , 'locateWindow' )
134
- . returns ( fixtures . fakeWindowWebCryptoOnlyRandomSource )
135
-
136
99
const { configureFallback } = webCryptoBackendFactory (
137
100
fixtures . fakeWindowWebCryptoOnlyRandomSource
138
101
)
139
102
140
103
await expect (
141
104
configureFallback ( fixtures . subtleFallbackZeroByteEncryptFail )
142
105
) . to . rejectedWith ( Error )
143
-
144
- // @ts -ignore
145
- browserWindow . locateWindow = locateWindow
146
106
} )
147
107
} )
148
108
149
109
describe ( 'getWebCryptoBackend' , ( ) => {
150
110
it ( 'getWebCryptoBackend returns subtle and randomValues' , async ( ) => {
151
- const { locateWindow } = browserWindow
152
- sinon
153
- . stub ( browserWindow , 'locateWindow' )
154
- . returns ( fixtures . fakeWindowWebCryptoSupportsZeroByteGCM )
155
-
156
111
const { getWebCryptoBackend } = webCryptoBackendFactory (
157
112
fixtures . fakeWindowWebCryptoSupportsZeroByteGCM
158
113
)
159
114
const test = await getWebCryptoBackend ( )
160
- // @ts -ignore
161
- browserWindow . locateWindow = locateWindow
162
115
163
116
expect ( test )
164
117
. to . have . property ( 'subtle' )
@@ -169,54 +122,27 @@ describe('webCryptoBackendFactory', () => {
169
122
} )
170
123
171
124
it ( 'Precondition: Access to a secure random source is required.' , async ( ) => {
172
- const { locateWindow } = browserWindow
173
- sinon
174
- . stub ( browserWindow , 'locateWindow' )
175
- . returns ( fixtures . fakeWindowNoWebCrypto )
176
-
177
125
const { getWebCryptoBackend } = webCryptoBackendFactory (
178
126
fixtures . fakeWindowNoWebCrypto
179
127
)
180
128
await expect ( getWebCryptoBackend ( ) ) . to . rejectedWith ( Error )
181
-
182
- // @ts -ignore
183
- browserWindow . locateWindow = locateWindow
184
129
} )
185
130
186
131
it ( 'Postcondition: If no SubtleCrypto exists, a fallback must configured.' , async ( ) => {
187
- const { locateWindow } = browserWindow
188
- sinon
189
- . stub ( browserWindow , 'locateWindow' )
190
- . returns ( fixtures . fakeWindowWebCryptoOnlyRandomSource )
191
-
192
132
const { getWebCryptoBackend } = webCryptoBackendFactory (
193
133
fixtures . fakeWindowWebCryptoOnlyRandomSource
194
134
)
195
135
await expect ( getWebCryptoBackend ( ) ) . to . rejectedWith ( Error )
196
- // @ts -ignore
197
- browserWindow . locateWindow = locateWindow
198
136
} )
199
137
200
138
it ( 'Postcondition: If a a subtle backend exists and a fallback is required, one must be configured.' , async ( ) => {
201
- const { locateWindow } = browserWindow
202
- sinon
203
- . stub ( browserWindow , 'locateWindow' )
204
- . returns ( fixtures . fakeWindowWebCryptoZeroByteEncryptFail )
205
-
206
139
const { getWebCryptoBackend } = webCryptoBackendFactory (
207
140
fixtures . fakeWindowWebCryptoZeroByteEncryptFail
208
141
)
209
142
await expect ( getWebCryptoBackend ( ) ) . to . rejectedWith ( Error )
210
- // @ts -ignore
211
- browserWindow . locateWindow = locateWindow
212
143
} )
213
144
214
145
it ( 'getWebCryptoBackend returns configured fallback subtle and randomValues' , async ( ) => {
215
- const { locateWindow } = browserWindow
216
- sinon
217
- . stub ( browserWindow , 'locateWindow' )
218
- . returns ( fixtures . fakeWindowWebCryptoOnlyRandomSource )
219
-
220
146
const {
221
147
getWebCryptoBackend,
222
148
configureFallback,
@@ -226,8 +152,6 @@ describe('webCryptoBackendFactory', () => {
226
152
// I _also_ test its ability to await the configuration.
227
153
configureFallback ( fixtures . subtleFallbackSupportsZeroByteGCM ) // eslint-disable-line @typescript-eslint/no-floating-promises
228
154
const test = await getWebCryptoBackend ( )
229
- // @ts -ignore
230
- browserWindow . locateWindow = locateWindow
231
155
232
156
expect ( test )
233
157
. to . have . property ( 'subtle' )
@@ -236,11 +160,6 @@ describe('webCryptoBackendFactory', () => {
236
160
} )
237
161
238
162
it ( 'getWebCryptoBackend returns MixedSupportWebCryptoBackend' , async ( ) => {
239
- const { locateWindow } = browserWindow
240
- sinon
241
- . stub ( browserWindow , 'locateWindow' )
242
- . returns ( fixtures . fakeWindowWebCryptoZeroByteEncryptFail )
243
-
244
163
const {
245
164
getWebCryptoBackend,
246
165
configureFallback,
@@ -252,8 +171,6 @@ describe('webCryptoBackendFactory', () => {
252
171
// I _also_ test its ability to await the configuration.
253
172
configureFallback ( fixtures . subtleFallbackSupportsZeroByteGCM ) // eslint-disable-line @typescript-eslint/no-floating-promises
254
173
const test = await getWebCryptoBackend ( )
255
- // @ts -ignore
256
- browserWindow . locateWindow = locateWindow
257
174
258
175
expect ( test )
259
176
. to . have . property ( 'nonZeroByteSubtle' )
0 commit comments