@@ -10,75 +10,75 @@ afterEach(() => {
1010} ) ;
1111
1212describe ( 'crypto empty / missing inputs verification' , ( ) => {
13- it ( 'encrypts and decrypts a normal token string' , ( ) => {
13+ it ( 'encrypts and decrypts a normal token string' , async ( ) => {
1414 const plain = 'gho_abc123def456token' ;
15- const encrypted = encryptToken ( plain ) ;
15+ const encrypted = await encryptToken ( plain ) ;
1616 expect ( encrypted ) . toBeDefined ( ) ;
1717 expect ( encrypted ) . not . toBe ( plain ) ;
1818 expect ( encrypted . split ( '.' ) ) . toHaveLength ( 4 ) ;
19- expect ( decryptToken ( encrypted ) ) . toBe ( plain ) ;
19+ expect ( await decryptToken ( encrypted ) ) . toBe ( plain ) ;
2020 } ) ;
2121
22- it ( 'handles empty string encryption and decryption' , ( ) => {
23- const encrypted = encryptToken ( '' ) ;
22+ it ( 'handles empty string encryption and decryption' , async ( ) => {
23+ const encrypted = await encryptToken ( '' ) ;
2424 expect ( encrypted . split ( '.' ) ) . toHaveLength ( 4 ) ;
25- expect ( decryptToken ( encrypted ) ) . toBe ( '' ) ;
25+ expect ( await decryptToken ( encrypted ) ) . toBe ( '' ) ;
2626 } ) ;
2727
28- it ( 'rejects malformed payload with wrong number of parts' , ( ) => {
29- expect ( ( ) => decryptToken ( 'only-one-part' ) ) . toThrow ( ) ;
30- expect ( ( ) => decryptToken ( 'two.parts' ) ) . toThrow ( ) ;
31- expect ( ( ) => decryptToken ( 'a.b.c.d' ) ) . toThrow ( ) ;
28+ it ( 'rejects malformed payload with wrong number of parts' , async ( ) => {
29+ await expect ( decryptToken ( 'only-one-part' ) ) . rejects . toThrow ( ) ;
30+ await expect ( decryptToken ( 'two.parts' ) ) . rejects . toThrow ( ) ;
31+ await expect ( decryptToken ( 'a.b.c.d' ) ) . rejects . toThrow ( ) ;
3232 } ) ;
3333
34- it ( 'rejects payload with invalid base64' , ( ) => {
34+ it ( 'rejects payload with invalid base64' , async ( ) => {
3535 const payload = '!!!invalid-base64!!!.aaaa.aaaa' ;
36- expect ( ( ) => decryptToken ( payload ) ) . toThrow ( ) ;
36+ await expect ( decryptToken ( payload ) ) . rejects . toThrow ( ) ;
3737 } ) ;
3838
39- it ( 'rejects empty payload string' , ( ) => {
40- expect ( ( ) => decryptToken ( '' ) ) . toThrow ( ) ;
39+ it ( 'rejects empty payload string' , async ( ) => {
40+ await expect ( decryptToken ( '' ) ) . rejects . toThrow ( ) ;
4141 } ) ;
4242
43- it ( 'rejects tampered ciphertext (modified encrypted part)' , ( ) => {
43+ it ( 'rejects tampered ciphertext (modified encrypted part)' , async ( ) => {
4444 const plain = 'gho_secret_token' ;
45- const encrypted = encryptToken ( plain ) ;
45+ const encrypted = await encryptToken ( plain ) ;
4646 const parts = encrypted . split ( '.' ) ;
4747 const tampered = [ parts [ 0 ] , parts [ 1 ] , '////' ] . join ( '.' ) ;
48- expect ( ( ) => decryptToken ( tampered ) ) . toThrow ( ) ;
48+ await expect ( decryptToken ( tampered ) ) . rejects . toThrow ( ) ;
4949 } ) ;
5050
51- it ( 'rejects tampered auth tag (modified tag part)' , ( ) => {
51+ it ( 'rejects tampered auth tag (modified tag part)' , async ( ) => {
5252 const plain = 'gho_secret_token' ;
53- const encrypted = encryptToken ( plain ) ;
53+ const encrypted = await encryptToken ( plain ) ;
5454 const parts = encrypted . split ( '.' ) ;
5555 const tampered = [ parts [ 0 ] , '////' , parts [ 2 ] ] . join ( '.' ) ;
56- expect ( ( ) => decryptToken ( tampered ) ) . toThrow ( ) ;
56+ await expect ( decryptToken ( tampered ) ) . rejects . toThrow ( ) ;
5757 } ) ;
5858
59- it ( 'rejects tampered IV (modified iv part)' , ( ) => {
59+ it ( 'rejects tampered IV (modified iv part)' , async ( ) => {
6060 const plain = 'gho_secret_token' ;
61- const encrypted = encryptToken ( plain ) ;
61+ const encrypted = await encryptToken ( plain ) ;
6262 const parts = encrypted . split ( '.' ) ;
6363 const tampered = [ '////' , parts [ 1 ] , parts [ 2 ] ] . join ( '.' ) ;
64- expect ( ( ) => decryptToken ( tampered ) ) . toThrow ( ) ;
64+ await expect ( decryptToken ( tampered ) ) . rejects . toThrow ( ) ;
6565 } ) ;
6666} ) ;
6767
6868describe ( 'crypto key errors' , ( ) => {
69- it ( 'throws when ENCRYPTION_KEY is missing' , ( ) => {
69+ it ( 'throws when ENCRYPTION_KEY is missing' , async ( ) => {
7070 vi . stubEnv ( 'ENCRYPTION_KEY' , '' ) ;
71- expect ( ( ) => encryptToken ( 'test' ) ) . toThrow ( / E N C R Y P T I O N _ K E Y / i) ;
71+ await expect ( encryptToken ( 'test' ) ) . rejects . toThrow ( / E N C R Y P T I O N _ K E Y / i) ;
7272 } ) ;
7373
74- it ( 'throws when ENCRYPTION_KEY is too short' , ( ) => {
74+ it ( 'throws when ENCRYPTION_KEY is too short' , async ( ) => {
7575 vi . stubEnv ( 'ENCRYPTION_KEY' , 'short' ) ;
76- expect ( ( ) => encryptToken ( 'test' ) ) . toThrow ( / E N C R Y P T I O N _ K E Y / i) ;
76+ await expect ( encryptToken ( 'test' ) ) . rejects . toThrow ( / E N C R Y P T I O N _ K E Y / i) ;
7777 } ) ;
7878
79- it ( 'throws on decrypt with wrong key' , ( ) => {
80- const encrypted = encryptToken ( 'secret' ) ;
79+ it ( 'throws on decrypt with wrong key' , async ( ) => {
80+ const encrypted = await encryptToken ( 'secret' ) ;
8181 vi . stubEnv ( 'ENCRYPTION_KEY' , 'a-different-key-that-is-32-char!!' ) ;
82- expect ( ( ) => decryptToken ( encrypted ) ) . toThrow ( ) ;
82+ await expect ( decryptToken ( encrypted ) ) . rejects . toThrow ( ) ;
8383 } ) ;
8484} ) ;
0 commit comments