1- import { decrypt , encrypt } from "../index" ;
2- import { _testExports } from "../encryption" ;
1+ import { decrypt , encrypt } from "../encryption" ;
32
43const EMBED_SECRET = "my fake embed secret" ;
54
@@ -12,55 +11,4 @@ describe("oauth token encryption", () => {
1211 const decryptedToken = decrypt ( EMBED_SECRET , encryptedToken ) ;
1312 expect ( decryptedToken ) . toBe ( plaintext ) ;
1413 } ) ;
15-
16- function toEncodedString (
17- salt : string ,
18- iv : string ,
19- tag : string ,
20- ciphertext : string ,
21- ) : string {
22- return `${ salt } .${ iv } .${ tag } .${ ciphertext } ` ;
23- }
24-
25- it ( "only throws error when reading an incorrectly encoded string" , ( ) => {
26- // Throws for invalid format.
27- expect ( ( ) => {
28- _testExports . asEncodedPassphraseEncryptionOutput ( "hello, world!" ) ;
29- } ) . toThrow ( ) ;
30-
31- // Throws for valid format, but with non-base64 components.
32- expect ( ( ) => {
33- _testExports . asEncodedPassphraseEncryptionOutput (
34- toEncodedString ( "(salt)" , "(iv)" , "(tag)" , "(ciphertext)" ) ,
35- ) ;
36- } ) . toThrow ( ) ;
37-
38- // Throws for valid format with base64 components of invalid length.
39- expect ( ( ) => {
40- _testExports . asEncodedPassphraseEncryptionOutput (
41- toEncodedString ( "YQ==" , "Yg==" , "Yw==" , "ZA==" ) ,
42- ) ;
43- } ) . toThrow ( ) ;
44-
45- // Does not throw for valid format with base64 components of valid length.
46- const salt = Buffer . from (
47- "s" . repeat (
48- _testExports . PBKDF2_HMAC_SHA256_KEY_DERIVATION . SALT_LENGTH_BYTES ,
49- ) ,
50- ) . toString ( "base64" ) ;
51- const iv = Buffer . from (
52- "i" . repeat ( _testExports . AES_256_GCM_ENCRYPTION . IV_LENGTH_BYTES ) ,
53- ) . toString ( "base64" ) ;
54- const tag = Buffer . from (
55- "t" . repeat ( _testExports . AES_256_GCM_ENCRYPTION . TAG_LENGTH_BYTES ) ,
56- ) . toString ( "base64" ) ;
57- const ciphertext = Buffer . from (
58- "c" . repeat ( 10 /* arbitrary length */ ) ,
59- ) . toString ( "base64" ) ;
60- expect ( ( ) => {
61- _testExports . asEncodedPassphraseEncryptionOutput (
62- toEncodedString ( salt , iv , tag , ciphertext ) ,
63- ) ;
64- } ) . not . toThrow ( ) ;
65- } ) ;
6614} ) ;
0 commit comments