Browse Source

additional tests

ameba23 3 years ago
parent
commit
0f6963363c
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      test/index.test.js

+ 25
- 0
test/index.test.js View File

@@ -45,6 +45,19 @@ describe('key generation', (context) => {
45 45
     next()
46 46
   })
47 47
 
48
+  context('pack an access key given as strings', (assert, next) => {
49
+    const pubKey = crypto.keyPair().publicKey
50
+    const secretKey = crypto.symmetricKey()
51
+
52
+    const accessKey = crypto.pack(pubKey.toString('hex'), secretKey.toString('hex'))
53
+    assert.ok(accessKey, 'Key successfully generated')
54
+    assert.ok(accessKey instanceof Buffer, 'Access key is a buffer')
55
+    assert.same(accessKey.length, 64, 'read key is 64 bytes')
56
+    assert.same(accessKey.slice(0, 32), pubKey)
57
+    assert.same(accessKey.slice(32, 64), secretKey)
58
+    next()
59
+  })
60
+
48 61
   context('unpack an access key', (assert, next) => {
49 62
     const accessKey = crypto.accessKey()
50 63
 
@@ -57,6 +70,18 @@ describe('key generation', (context) => {
57 70
     next()
58 71
   })
59 72
 
73
+  context('unpack an access key given as a string', (assert, next) => {
74
+    const accessKey = crypto.accessKey()
75
+
76
+    const keys = crypto.unpack(accessKey.toString('hex'))
77
+    const pubKey = accessKey.slice(0, 32)
78
+    const symKey = accessKey.slice(32, 64)
79
+
80
+    assert.same(keys.publicKey, pubKey, 'Unpacks the public key')
81
+    assert.same(keys.symmetricKey, symKey, 'Unpacks the symmetric key')
82
+    next()
83
+  })
84
+
60 85
   context('check a key is a valid blind replication / public key', (assert, next) => {
61 86
     const accessKey = crypto.accessKey()
62 87
     assert.same(false, crypto.isBlindKey(accessKey), 'access key is not a valid blind replication key')