forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt-phone-number.test.js
More file actions
33 lines (27 loc) · 1004 Bytes
/
decrypt-phone-number.test.js
File metadata and controls
33 lines (27 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { decryptPhoneNumber } from '../decrypt-phone-number'
import crypto from 'crypto'
const { CIPHER_KEY } = process.env
describe('given an encrypted phone number field', () => {
describe('phone number field is a valid phone number', () => {
it('returns the decrypted phone number', () => {
const originalPhoneNumber = '+12345678912'
const phoneDetails = {
iv: crypto.randomBytes(12).toString('hex'),
}
const cipher = crypto.createCipheriv(
'aes-256-ccm',
String(CIPHER_KEY),
Buffer.from(phoneDetails.iv, 'hex'),
{
authTagLength: 16,
},
)
let encrypted = cipher.update(originalPhoneNumber, 'utf8', 'hex')
encrypted += cipher.final('hex')
phoneDetails.phoneNumber = encrypted
phoneDetails.tag = cipher.getAuthTag().toString('hex')
const decryptedPhoneNumber = decryptPhoneNumber(phoneDetails)
expect(decryptedPhoneNumber).toEqual(originalPhoneNumber)
})
})
})