Skip to content

Commit 820c78a

Browse files
committed
Unit-test the Airbitz file support
1 parent cb5345c commit 820c78a

4 files changed

Lines changed: 106 additions & 1 deletion

File tree

src/core/fake/fake-world.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ export function makeFakeWorld(
104104
},
105105

106106
async makeEdgeContext(opts: EdgeFakeContextOptions): Promise<EdgeContext> {
107-
const { allowNetworkAccess = false, cleanDevice = false } = opts
107+
const {
108+
allowNetworkAccess = false,
109+
cleanDevice = false,
110+
extraFiles = {}
111+
} = opts
108112

109113
const fakeFetch = makeFetchFunction(fakeServer)
110114
const fetch: EdgeFetchFunction = !allowNetworkAccess
@@ -138,6 +142,12 @@ export function makeFakeWorld(
138142
}
139143
}
140144

145+
if (extraFiles != null) {
146+
for (const path of Object.keys(extraFiles)) {
147+
await fakeIo.disklet.setText(path, extraFiles[path])
148+
}
149+
}
150+
141151
const out = await makeContext({ io: fakeIo, nativeIo }, logBackend, {
142152
...opts
143153
})

src/types/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,9 @@ export interface EdgeFakeContextOptions {
18741874

18751875
// Fake device options:
18761876
cleanDevice?: boolean
1877+
1878+
/** Extra files to be saved on the fake device. */
1879+
extraFiles?: { [path: string]: string }
18771880
}
18781881

18791882
/**

test/core/login/airbitz.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from 'chai'
2+
import { describe, it } from 'mocha'
3+
4+
import { makeFakeEdgeWorld } from '../../../src/index'
5+
import { airbitzFiles, fakeUser } from '../../fake/fake-user'
6+
7+
const quiet = { onLog() {} }
8+
9+
describe('airbitz stashes', function () {
10+
it('can log into legacy airbitz files', async function () {
11+
const world = await makeFakeEdgeWorld([fakeUser], quiet)
12+
const context = await world.makeEdgeContext({
13+
airbitzSupport: true,
14+
apiKey: '',
15+
appId: '',
16+
cleanDevice: true,
17+
extraFiles: airbitzFiles
18+
})
19+
20+
expect(context.localUsers).deep.equals([
21+
{
22+
keyLoginEnabled: true,
23+
lastLogin: undefined,
24+
loginId: 'BTnpEn7pabDXbcv7VxnKBDsn4CVSwLRA25J8U84qmg4h',
25+
pinLoginEnabled: true,
26+
recovery2Key: 'NVADGXzb5Zc55PYXVVT7GRcXPnY9NZJUjiZK8aQnidc',
27+
username: 'js test 0',
28+
voucherId: undefined
29+
}
30+
])
31+
32+
await context.loginWithPIN(fakeUser.username, fakeUser.pin)
33+
})
34+
})

test/fake/fake-user.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,61 @@ export const fakeUserDump: EdgeFakeUser = {
221221
}
222222

223223
export const fakeUser = { ...fakeUserDump, ...info }
224+
225+
/**
226+
* This data comes from the old C++ abc-cli tool.
227+
* It was created by uploading the "js test 0" user above into a
228+
* testing login server, and then running `abc-cli sign-in`
229+
* with the matching username and password.
230+
* These are the exact files abc-cli wrote to disk
231+
* once the sign-in was complete.
232+
*/
233+
export const airbitzFiles = {
234+
'Accounts/Account0/CarePackage.json': JSON.stringify({
235+
SNRP2: {
236+
n: 16384,
237+
p: 1,
238+
r: 2,
239+
salt_hex:
240+
'ed6396d127b60d6ffc469634b9a53bdcfb4ee381e9b9df5e66a0f97895871981'
241+
}
242+
}),
243+
'Accounts/Account0/LoginPackage.json': JSON.stringify({
244+
ELP1: {
245+
data_base64:
246+
'ZHhQtHA48aPf083XbEeNMAzbu4KE5dNLU6q0WzTUwJkxGG72elIha9wMjpAvwxmJ2PC3ZCMya1eiVgHPqTO+zS8dWHmuqzbpNY+IdoAtjF//dZ6O4mCcMR8enmj5xYaVBIIQ8WCcang+2RTqDzOoI+W8p6mM9N528ypy0lkpYi9lpGrxAAAJjhk+9xdBRcL4O5jkCZ0VQEvoRCqlU2y99YtRYtB/+nYj51PTtU00MUpKq7PggNZI5EDmZC9vK/BRnBArLbnwj7L88vuKEXBumYX0GA9ZhTPXMuRfABzvCxPkTKLGG2KmfQAtSAehCDMtkgQzocXSCiUuzqBdId56WkNFYC+Phq6vgflPK2qcxkV6Kz2qu8Yr1nBveyLsUTGOZgoBlya2UEZrQ4B96mUv5Q==',
247+
encryptionType: 0,
248+
iv_hex: 'c801b7e3265734544c08c68bdff86979'
249+
},
250+
EMK_LP2: {
251+
data_base64:
252+
'sXBdJaaeVNWOuBWdRVvULaS+VqPkTF1eLR0BMSi2a4F+DCc+4JbMqgBPK3uyp7MHd3qpOOt7Fcth5gnT5hspzh47ONsTTaQNglwZ4lY25OKGsK7ldWrcohiDEgswgG8whGM3tqio6iIMndkuZn3Dn9aj0SwWNdCuW1xFYvbMa7pCgWr0QT+zjWJAPnlT0U1hqJNjGDqFK6jYorClWKsbBZtVJ/dCRMv5+xu05S7fCdgQnz1m5O5nMHTcw6NFR0eBApOOh3KbghOeh0QcBAa5jNm4L61BK5wMCgPydh2/u+MSu34ERsomA5kwp86N35EKHGJH3p0Jq/jf9ToR9wU/MlPivmHvbbspxIzay0feJcanodfyFqLLnsfknSptgiaX3ppat83xrdndQH+JNYweNTgoZmd5pt/8hu/LGk1iAs8Z6e61FaYXm+UI/yxUQFy3A8meST1UfVAxeFw3IRCRZRplll8fgALH67kO15s4bts=',
253+
encryptionType: 0,
254+
iv_hex: '0989bebe4103816be3db48a2ed3ff338'
255+
},
256+
ESyncKey: {
257+
data_base64:
258+
'ruf9v3eWUg2GZJf+94boCPyui4nQ9HnJCWx07kmRg+nKns+1MlqSFQQNINgHXLWDrQvho69AnQrP9Ep+PcXOnG+m0kiqlmzm8UdhQoQJOKP/O5S2TFwMuLpLrGN+I4F5HbdGVMA20WJjhfQ7Kzc3H2hHwm1BUo0xItbV/audT6KySR+ugeW+jF5glzB0/8eAYFKloYd0YC6TZg1gmZU7jqBatpylk7a9znrZG6zKVyPQxnkKr6TnF3xQihSw2H7g1Gd4AI4Pttye/RYsVbwqFFnD2OZwgp7kqeyLwVRsU6OboRtkBYuaa4adYhXHda94',
259+
encryptionType: 0,
260+
iv_hex: '59309614b12c169af977681e01d6ad8b'
261+
}
262+
}),
263+
'Accounts/Account0/OtpKey.json': JSON.stringify({
264+
TOTP: 'HELLO==='
265+
}),
266+
'Accounts/Account0/Pin2Key.json': JSON.stringify({
267+
pin2Key: '22b6wM3F6bd3LpT1UHLhb7pDr5BxzAuVNhuU5HGudZHq'
268+
}),
269+
'Accounts/Account0/Recovery2Key.json': JSON.stringify({
270+
recovery2Key: 'NVADGXzb5Zc55PYXVVT7GRcXPnY9NZJUjiZK8aQnidc'
271+
}),
272+
'Accounts/Account0/RootKey.json': JSON.stringify({
273+
data_base64:
274+
'pR+yQsnkynA03Xqa8AYHzRzunxsBoFM39huz09DL+20RZxAAid4iWkkBNei+Z6Mp0sdhDNfilPQmU5rOuABo70NIO+E3GNZ66RmG6SkN0Jo0Fgp28Qfyg/aD6BlMNw++oXS8yGuDvPotDpM/rgYd6l7/OuLLfg5cZw85Qe1D9UM9dqP8EVpKPQTqSsAnTE0RsHG3HFVIFVRQAsIqqsynAC+h8QiKdAFaqzdFVbB75iu4KV27wdjfRnZrTVPqGA9fnC96vhRRUNRmQnWbJRvdyhIXRHYXJbu/ip1eFts054yfjhyxHffOXfcSpm3xwL0itf3Y4rEUG0dEQO5IwfpuRxspFFn3S/Fi4wGkw+PJNNtF3r5djryeYOFE854n3YOkBayhyhnNAJuaaHeOnrP7QaD3V4hDuFezHqTWCU8lA7W0u7SmFZ1IXXXxvjITvglkmTrnx8CbWkmjRXqIbMl8tg==',
275+
encryptionType: 0,
276+
iv_hex: '96cc1ebc2d11a0b38c9259c056d3ca23'
277+
}),
278+
'Accounts/Account0/UserName.json': JSON.stringify({
279+
userName: 'js test 0'
280+
})
281+
}

0 commit comments

Comments
 (0)