forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.test.ts
More file actions
42 lines (39 loc) · 1.79 KB
/
keys.test.ts
File metadata and controls
42 lines (39 loc) · 1.79 KB
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
34
35
36
37
38
39
40
41
42
import { generatePrivateKey, generatePublicKey, getPublicKey } from '../../../src/chat/keys'
import { store } from 'solid-logic-jss'
import { NamedNode } from 'rdflib'
import * as helpers from '../../../src/utils/keyHelpers/accessData'
const PRIV_KEY = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
const PUB_KEY = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
jest.mock('../../../src/utils/keyHelpers/accessData')
store.fetcher.load = jest.fn().mockImplementation(() => {})
store.any = jest.fn()
describe('generate key pair', () => {
// console.log('alain')
it('private key exists is length 64', () => {
const privateKey = generatePrivateKey()
expect(privateKey.length).toEqual(64)
})
it('public key exists is length 64', () => {
const publicKey = generatePublicKey(PRIV_KEY)
expect(publicKey).toEqual(PUB_KEY)
expect(publicKey.length).toEqual(64)
})
})
describe('getPublicKey', () => {
const webId = new NamedNode('https://alice.solidcommunity.net/profile/card#me')
it('should return the key', async () => {
/* @ts-ignore */
jest.spyOn(helpers, 'pubKeyUrl').mockResolvedValue('https://alice.solidcommunity.net/profile/keys/publicKey.ttl')
/* @ts-ignore */
store.any.mockReturnValue({ value: PUB_KEY })
const webId = new NamedNode('https://alice.solidcommunity.net/profile/card#me')
const result = await getPublicKey(webId)
expect(result).toBe(PUB_KEY)
})
it.skip('should return undefined if loading and retrieving key fails', async () => {
jest.spyOn(helpers, 'pubKeyUrl').mockResolvedValue('https://alice.solidcommunity.net/profile/keys/publicKey.ttl')
/* @ts-ignore */
store.any.mockRejectedValue()
expect(await getPublicKey(webId)).rejects.toThrowError()
})
})