Skip to content

Commit

Permalink
Unit-test the Airbitz file support
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Mar 27, 2024
1 parent ab5f7f3 commit a588c78
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/fake/fake-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export function makeFakeWorld(
},

async makeEdgeContext(opts: EdgeFakeContextOptions): Promise<EdgeContext> {
const { allowNetworkAccess = false, cleanDevice = false } = opts
const {
allowNetworkAccess = false,
cleanDevice = false,
extraFiles = {}
} = opts

const fakeFetch = makeFetchFunction(fakeServer)
const fetch: EdgeFetchFunction = !allowNetworkAccess
Expand Down Expand Up @@ -138,6 +142,12 @@ export function makeFakeWorld(
}
}

if (extraFiles != null) {
for (const path of Object.keys(extraFiles)) {
await fakeIo.disklet.setText(path, extraFiles[path])
}
}

const out = await makeContext({ io: fakeIo, nativeIo }, logBackend, {
...opts
})
Expand Down
3 changes: 3 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,9 @@ export interface EdgeFakeContextOptions {

// Fake device options:
cleanDevice?: boolean

/** Extra files to be saved on the fake device. */
extraFiles?: { [path: string]: string }
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/core/login/airbitz.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, it } from 'mocha'

import { makeFakeEdgeWorld } from '../../../src/index'
import { airbitzFiles, fakeUser } from '../../fake/fake-user'

const quiet = { onLog() {} }

describe('airbitz stashes', function () {
it('can log into legacy airbitz files', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext({
airbitzSupport: true,
apiKey: '',
appId: '',
cleanDevice: true,
extraFiles: airbitzFiles
})
await context.loginWithPIN(fakeUser.username, fakeUser.pin)
})
})
53 changes: 53 additions & 0 deletions test/fake/fake-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,56 @@ export const fakeUserDump: EdgeFakeUser = {
}

export const fakeUser = { ...fakeUserDump, ...info }

/**
* Data generated by logging the old abc-cli tool into "js test 0".
*/
export const airbitzFiles = {
'Accounts/Account0/CarePackage.json': JSON.stringify({
SNRP2: {
n: 16384,
p: 1,
r: 2,
salt_hex:
'ed6396d127b60d6ffc469634b9a53bdcfb4ee381e9b9df5e66a0f97895871981'
}
}),
'Accounts/Account0/LoginPackage.json': JSON.stringify({
ELP1: {
data_base64:
'ZHhQtHA48aPf083XbEeNMAzbu4KE5dNLU6q0WzTUwJkxGG72elIha9wMjpAvwxmJ2PC3ZCMya1eiVgHPqTO+zS8dWHmuqzbpNY+IdoAtjF//dZ6O4mCcMR8enmj5xYaVBIIQ8WCcang+2RTqDzOoI+W8p6mM9N528ypy0lkpYi9lpGrxAAAJjhk+9xdBRcL4O5jkCZ0VQEvoRCqlU2y99YtRYtB/+nYj51PTtU00MUpKq7PggNZI5EDmZC9vK/BRnBArLbnwj7L88vuKEXBumYX0GA9ZhTPXMuRfABzvCxPkTKLGG2KmfQAtSAehCDMtkgQzocXSCiUuzqBdId56WkNFYC+Phq6vgflPK2qcxkV6Kz2qu8Yr1nBveyLsUTGOZgoBlya2UEZrQ4B96mUv5Q==',
encryptionType: 0,
iv_hex: 'c801b7e3265734544c08c68bdff86979'
},
EMK_LP2: {
data_base64:
'sXBdJaaeVNWOuBWdRVvULaS+VqPkTF1eLR0BMSi2a4F+DCc+4JbMqgBPK3uyp7MHd3qpOOt7Fcth5gnT5hspzh47ONsTTaQNglwZ4lY25OKGsK7ldWrcohiDEgswgG8whGM3tqio6iIMndkuZn3Dn9aj0SwWNdCuW1xFYvbMa7pCgWr0QT+zjWJAPnlT0U1hqJNjGDqFK6jYorClWKsbBZtVJ/dCRMv5+xu05S7fCdgQnz1m5O5nMHTcw6NFR0eBApOOh3KbghOeh0QcBAa5jNm4L61BK5wMCgPydh2/u+MSu34ERsomA5kwp86N35EKHGJH3p0Jq/jf9ToR9wU/MlPivmHvbbspxIzay0feJcanodfyFqLLnsfknSptgiaX3ppat83xrdndQH+JNYweNTgoZmd5pt/8hu/LGk1iAs8Z6e61FaYXm+UI/yxUQFy3A8meST1UfVAxeFw3IRCRZRplll8fgALH67kO15s4bts=',
encryptionType: 0,
iv_hex: '0989bebe4103816be3db48a2ed3ff338'
},
ESyncKey: {
data_base64:
'ruf9v3eWUg2GZJf+94boCPyui4nQ9HnJCWx07kmRg+nKns+1MlqSFQQNINgHXLWDrQvho69AnQrP9Ep+PcXOnG+m0kiqlmzm8UdhQoQJOKP/O5S2TFwMuLpLrGN+I4F5HbdGVMA20WJjhfQ7Kzc3H2hHwm1BUo0xItbV/audT6KySR+ugeW+jF5glzB0/8eAYFKloYd0YC6TZg1gmZU7jqBatpylk7a9znrZG6zKVyPQxnkKr6TnF3xQihSw2H7g1Gd4AI4Pttye/RYsVbwqFFnD2OZwgp7kqeyLwVRsU6OboRtkBYuaa4adYhXHda94',
encryptionType: 0,
iv_hex: '59309614b12c169af977681e01d6ad8b'
}
}),
'Accounts/Account0/OtpKey.json': JSON.stringify({
TOTP: 'HELLO==='
}),
'Accounts/Account0/Pin2Key.json': JSON.stringify({
pin2Key: '22b6wM3F6bd3LpT1UHLhb7pDr5BxzAuVNhuU5HGudZHq'
}),
'Accounts/Account0/Recovery2Key.json': JSON.stringify({
recovery2Key: 'NVADGXzb5Zc55PYXVVT7GRcXPnY9NZJUjiZK8aQnidc'
}),
'Accounts/Account0/RootKey.json': JSON.stringify({
data_base64:
'pR+yQsnkynA03Xqa8AYHzRzunxsBoFM39huz09DL+20RZxAAid4iWkkBNei+Z6Mp0sdhDNfilPQmU5rOuABo70NIO+E3GNZ66RmG6SkN0Jo0Fgp28Qfyg/aD6BlMNw++oXS8yGuDvPotDpM/rgYd6l7/OuLLfg5cZw85Qe1D9UM9dqP8EVpKPQTqSsAnTE0RsHG3HFVIFVRQAsIqqsynAC+h8QiKdAFaqzdFVbB75iu4KV27wdjfRnZrTVPqGA9fnC96vhRRUNRmQnWbJRvdyhIXRHYXJbu/ip1eFts054yfjhyxHffOXfcSpm3xwL0itf3Y4rEUG0dEQO5IwfpuRxspFFn3S/Fi4wGkw+PJNNtF3r5djryeYOFE854n3YOkBayhyhnNAJuaaHeOnrP7QaD3V4hDuFezHqTWCU8lA7W0u7SmFZ1IXXXxvjITvglkmTrnx8CbWkmjRXqIbMl8tg==',
encryptionType: 0,
iv_hex: '96cc1ebc2d11a0b38c9259c056d3ca23'
}),
'Accounts/Account0/UserName.json': JSON.stringify({
userName: 'js test 0'
})
}

0 comments on commit a588c78

Please sign in to comment.