Make async in preparation for future change
This commit is contained in:
parent
ece11954a1
commit
1342fb5b3f
2 changed files with 12 additions and 10 deletions
|
|
@ -47,9 +47,9 @@ const isEncryptedMessage = message =>
|
||||||
* Generates a new encryption key pair that will be used
|
* Generates a new encryption key pair that will be used
|
||||||
* when communicating with the deviceId specified
|
* when communicating with the deviceId specified
|
||||||
* @param {string} deviceId
|
* @param {string} deviceId
|
||||||
* @returns {Pair}
|
* @returns {Promise<Pair>}
|
||||||
*/
|
*/
|
||||||
const generateKeyPair = deviceId => {
|
const generateKeyPair = async deviceId => {
|
||||||
try {
|
try {
|
||||||
const existingKey = nodeKeyPairs.get(deviceId)
|
const existingKey = nodeKeyPairs.get(deviceId)
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ const isAuthorizedDevice = ({ deviceId }) => devicePublicKeys.has(deviceId)
|
||||||
const authorizeDevice = async ({ deviceId, publicKey }) => {
|
const authorizeDevice = async ({ deviceId, publicKey }) => {
|
||||||
const hostId = await Storage.get('encryption/hostId')
|
const hostId = await Storage.get('encryption/hostId')
|
||||||
devicePublicKeys.set(deviceId, convertBase64ToBuffer(publicKey))
|
devicePublicKeys.set(deviceId, convertBase64ToBuffer(publicKey))
|
||||||
const keyPair = generateKeyPair(deviceId)
|
const keyPair = await generateKeyPair(deviceId)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,20 @@ const storageDirectory = Path.resolve(__dirname, `./.test-storage`)
|
||||||
console.log(`Storage directory: ${storageDirectory}`)
|
console.log(`Storage directory: ${storageDirectory}`)
|
||||||
|
|
||||||
describe('generateKeyPair()', () => {
|
describe('generateKeyPair()', () => {
|
||||||
it('generates a keypair', () => {
|
it('generates a keypair', async () => {
|
||||||
const pair = generateKeyPair(uuid())
|
expect.hasAssertions()
|
||||||
|
const pair = await generateKeyPair(uuid())
|
||||||
|
|
||||||
expect(pair.privateKey).toBeInstanceOf(Buffer)
|
expect(pair.privateKey).toBeInstanceOf(Buffer)
|
||||||
expect(typeof pair.privateKeyBase64 === 'string').toBeTruthy()
|
expect(typeof pair.privateKeyBase64 === 'string').toBeTruthy()
|
||||||
expect(pair.publicKey).toBeInstanceOf(Buffer)
|
expect(pair.publicKey).toBeInstanceOf(Buffer)
|
||||||
expect(typeof pair.publicKeyBase64 === 'string').toBeTruthy()
|
expect(typeof pair.publicKeyBase64 === 'string').toBeTruthy()
|
||||||
})
|
})
|
||||||
it('returns the same pair for the same device', () => {
|
it('returns the same pair for the same device', async () => {
|
||||||
|
expect.hasAssertions()
|
||||||
const id = uuid()
|
const id = uuid()
|
||||||
const pair = generateKeyPair(id)
|
const pair = await generateKeyPair(id)
|
||||||
const pairAgain = generateKeyPair(id)
|
const pairAgain = await generateKeyPair(id)
|
||||||
|
|
||||||
expect(pairAgain).toStrictEqual(pair)
|
expect(pairAgain).toStrictEqual(pair)
|
||||||
})
|
})
|
||||||
|
|
@ -46,7 +48,7 @@ describe('authorizeDevice()/isAuthorizedDevice()', () => {
|
||||||
dir: storageDirectory
|
dir: storageDirectory
|
||||||
})
|
})
|
||||||
const deviceId = uuid()
|
const deviceId = uuid()
|
||||||
const pair = generateKeyPair(deviceId)
|
const pair = await generateKeyPair(deviceId)
|
||||||
await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 })
|
await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 })
|
||||||
expect(isAuthorizedDevice({ deviceId })).toBeTruthy()
|
expect(isAuthorizedDevice({ deviceId })).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
@ -96,7 +98,7 @@ describe('encryptMessage()/decryptMessage()', () => {
|
||||||
expect.hasAssertions()
|
expect.hasAssertions()
|
||||||
const deviceId = uuid()
|
const deviceId = uuid()
|
||||||
|
|
||||||
const pair = generateKeyPair(deviceId)
|
const pair = await generateKeyPair(deviceId)
|
||||||
|
|
||||||
await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 })
|
await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 })
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue