-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ea521
commit f5fc12a
Showing
4 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
// @ts-ignore | ||
import crypto from 'crypto' | ||
import { browserPlatform } from '../browser/platform'; | ||
import {KeeperEndpoint} from '../endpoint' | ||
import { nodePlatform } from '../node/platform' | ||
import { connectPlatform } from '../platform' | ||
// import NodeRSA from 'node-rsa'; | ||
|
||
Object.defineProperty(global.self, 'crypto', { | ||
value: { | ||
subtle: crypto.webcrypto.subtle, | ||
getRandomValues: (array: any) => crypto.randomBytes(array.length) | ||
} | ||
}) | ||
|
||
describe('getOnsitePublicKey', () => { | ||
|
||
let endpoint = new KeeperEndpoint({ | ||
host: 'testUrl', | ||
deviceConfig: { | ||
deviceName: 'test', | ||
deviceToken: new Uint8Array(), | ||
privateKey: new Uint8Array(), | ||
publicKey: new Uint8Array(), | ||
transmissionKeyId: 1, | ||
}, | ||
}) | ||
|
||
beforeEach(() => { | ||
endpoint = new KeeperEndpoint({ | ||
host: 'testUrl', | ||
deviceConfig: { | ||
deviceName: 'test', | ||
deviceToken: new Uint8Array(), | ||
privateKey: new Uint8Array(), | ||
publicKey: new Uint8Array(), | ||
transmissionKeyId: 1, | ||
}, | ||
}) | ||
}) | ||
|
||
// NODE PLATFORM | ||
it('(node) should return the rsa public key of the onsite keeper', async () => { | ||
connectPlatform(nodePlatform) | ||
const key = await endpoint.getOnsitePublicKey(false) | ||
|
||
checkRSAKey(key) | ||
// should node platform have a different length from browser? | ||
expect(key).toHaveLength(392); | ||
}) | ||
|
||
// NODE PLATFORM | ||
it('(node) should return the ecc public key of the onsite keeper', async () => { | ||
connectPlatform(nodePlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(true) | ||
checkECCKey(key) | ||
}) | ||
|
||
// BROWSER PLATFORM | ||
it('(browser) should return the rsa public key of the onsite keeper', async () => { | ||
connectPlatform(browserPlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(false) | ||
|
||
checkRSAKey(key) | ||
// should browser platform have a different length from node? | ||
expect(key).toHaveLength(360); | ||
}) | ||
|
||
// BROWSER PLATFORM | ||
it('(browser) should return the ecc public key of the onsite keeper', async () => { | ||
connectPlatform(browserPlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(true) | ||
checkECCKey(key) | ||
}) | ||
}) | ||
|
||
function checkRSAKey(key:string){ | ||
const beginningPart = key.match(/^MIIB/i) | ||
const endingPart = key.match(/IDAQAB$/i) | ||
expect(beginningPart).toBeTruthy(); | ||
expect(endingPart).toBeTruthy(); | ||
} | ||
|
||
function checkECCKey(key:string){ | ||
expect(key).toHaveLength(87); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters