Browse Source

add a test to reveal failure to encode to hex

Kieran Gibb 2 years ago
parent
commit
1fe539f66b
No known key found for this signature in database
1 changed files with 6 additions and 2 deletions
  1. 6
    2
      test/index.test.js

+ 6
- 2
test/index.test.js View File

@@ -32,16 +32,20 @@ describe('key generation', (context) => {
32 32
   })
33 33
 
34 34
   context('encryptionKey(string)', (assert, next) => {
35
-    const key = crypto.encryptionKey(crypto.randomBytes(32).toString('hex'))
35
+    const bytes = crypto.randomBytes(32).toString('hex')
36
+    const key = crypto.encryptionKey(bytes)
36 37
     assert.ok(key, 'Key successfully generated')
37 38
     assert.ok(key instanceof Buffer, 'key is a secure buffer')
39
+    assert.same(bytes, key.toString('hex'), 'keys match')
38 40
     next()
39 41
   })
40 42
 
41 43
   context('encryptionKey(buffer)', (assert, next) => {
42
-    const key = crypto.encryptionKey(crypto.randomBytes(32))
44
+    const bytes = crypto.randomBytes(32)
45
+    const key = crypto.encryptionKey(bytes)
43 46
     assert.ok(key, 'Key successfully generated')
44 47
     assert.ok(key instanceof Buffer, 'key is a secure buffer')
48
+    assert.same(bytes.toString('hex'), key.toString('hex'), 'keys match')
45 49
     next()
46 50
   })
47 51