@@ -29,34 +29,46 @@ const notSupportedMessages = [
29
29
'frameLength out of bounds: 0 > frameLength >= 4294967295' ,
30
30
'Unsupported right now'
31
31
]
32
- describe ( 'browser encrypt tests' , function ( ) {
33
- const tests = __fixtures__ [ 'fixtures/encrypt_tests' ]
34
- const decryptOracle = __fixtures__ [ 'fixtures/decrypt_oracle' ]
35
-
36
- for ( const testName of tests ) {
37
- it ( testName , async ( ) => {
38
- console . log ( `start: ${ testName } ` )
39
- const response = await fetch ( `base/fixtures/${ testName } .json` )
40
- const { keysInfo, plainTextData, encryptOp } = await response . json ( )
41
-
42
- const plainText = fromBase64 ( plainTextData )
43
- try {
44
- const cmm = await encryptMaterialsManagerWebCrypto ( keysInfo )
45
- const { result } = await encrypt ( cmm , plainText , encryptOp )
46
- const response = await fetch ( decryptOracle , {
47
- method : 'POST' ,
48
- headers : {
49
- 'Content-Type' : 'application/octet-stream' ,
50
- 'Accept' : 'application/octet-stream'
51
- } ,
52
- body : result
53
- } )
54
- const body = await response . arrayBuffer ( )
55
- needs ( response . ok , `Failed to decrypt: ${ toUtf8 ( body ) } ` )
56
- expect ( plainText ) . toEqual ( new Uint8Array ( body ) )
57
- } catch ( e ) {
58
- if ( ! notSupportedMessages . includes ( e . message ) ) throw e
59
- }
60
- } )
61
- }
62
- } )
32
+
33
+ const tests = __fixtures__ [ 'fixtures/encrypt_tests' ]
34
+ const decryptOracle = __fixtures__ [ 'fixtures/decrypt_oracle' ]
35
+ const chunk = __fixtures__ [ 'fixtures/concurrency' ] || 1
36
+
37
+ for ( let i = 0 , j = tests . length ; i < j ; i += chunk ) {
38
+ aGroup ( chunk , tests . slice ( i , i + chunk ) , decryptOracle )
39
+ }
40
+
41
+ function aGroup ( groupNumber : number , tests : string [ ] , decryptOracle : string ) {
42
+ describe ( `'browser encrypt tests': ${ groupNumber } ` , ( ) => {
43
+ for ( const testName of tests ) {
44
+ aTest ( testName , decryptOracle )
45
+ }
46
+ } )
47
+ }
48
+
49
+ function aTest ( testName : string , decryptOracle : string ) {
50
+ it ( testName , async ( ) => {
51
+ console . log ( `start: ${ testName } ` )
52
+ const response = await fetch ( `base/fixtures/${ testName } .json` )
53
+ const { keysInfo, plainTextData, encryptOp } = await response . json ( )
54
+
55
+ const plainText = fromBase64 ( plainTextData )
56
+ try {
57
+ const cmm = await encryptMaterialsManagerWebCrypto ( keysInfo )
58
+ const { result } = await encrypt ( cmm , plainText , encryptOp )
59
+ const response = await fetch ( decryptOracle , {
60
+ method : 'POST' ,
61
+ headers : {
62
+ 'Content-Type' : 'application/octet-stream' ,
63
+ 'Accept' : 'application/octet-stream'
64
+ } ,
65
+ body : result
66
+ } )
67
+ const body = await response . arrayBuffer ( )
68
+ needs ( response . ok , `Failed to decrypt: ${ toUtf8 ( body ) } ` )
69
+ expect ( plainText ) . toEqual ( new Uint8Array ( body ) )
70
+ } catch ( e ) {
71
+ if ( ! notSupportedMessages . includes ( e . message ) ) throw e
72
+ }
73
+ } )
74
+ }
0 commit comments