Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 40b8ef0

Browse files
committed
fix: reversion in browsers
1 parent ee67e69 commit 40b8ef0

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

migrations/migration-8/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ function encode (name) {
1515
}
1616

1717
function decode (name) {
18-
log(name)
1918
if (!name.startsWith(KEY_PREFIX)) {
2019
throw Error("Unknown format of key's name!")
2120
}
2221

2322
const decoder = new base32.Decoder({ type: "rfc4648" })
24-
return decoder.finalize(name.replace(KEY_PREFIX, '').toUpperCase())
23+
const decodedNameBuff = decoder.finalize(name.replace(KEY_PREFIX, '').toUpperCase())
24+
return Buffer.from(decodedNameBuff).toString()
2525
}
2626

2727
async function processFolder (store, prefix, fileNameProcessor) {

test/browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe('Browser specific tests', () => {
4343
require('./version-test')(createRepo, repoCleanup)
4444
})
4545

46+
describe('migrations tests', () => {
47+
require('./migrations/migration-8-test')(createRepo, repoCleanup)
48+
})
49+
4650
describe('init tests', () => {
4751
require('./init-test')(createRepo, repoCleanup)
4852
})

test/migrations/migration-8-test.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const chai = require('chai')
55
chai.use(require('dirty-chai'))
6-
const chaiAsPromised = require("chai-as-promised")
6+
const chaiAsPromised = require('chai-as-promised')
77
chai.use(chaiAsPromised)
88
const expect = chai.expect
99

@@ -27,8 +27,8 @@ async function bootstrapKeys (dir, encoded) {
2727
let name
2828
for (let keyNames of fixtures) {
2929
name = encoded ? keyNames[1] : keyNames[0]
30-
await store.put(new Key(`/pkcs8/${name}`), '')
31-
await store.put(new Key(`/info/${name}`), '')
30+
await store.put(new Key(`/pkcs8/${ name }`), '')
31+
await store.put(new Key(`/info/${ name }`), '')
3232
}
3333

3434
await store.close()
@@ -41,42 +41,44 @@ async function validateKeys (dir, shouldBeEncoded) {
4141
let name
4242
for (let keyNames of fixtures) {
4343
name = shouldBeEncoded ? keyNames[1] : keyNames[0]
44-
expect(await store.has(new Key(`/pkcs8/${name}`))).to.be.true()
45-
expect(await store.has(new Key(`/info/${name}`))).to.be.true()
44+
expect(await store.has(new Key(`/pkcs8/${ name }`))).to.be.true(name)
45+
expect(await store.has(new Key(`/info/${ name }`))).to.be.true(name)
4646
}
4747

4848
await store.close()
4949
}
5050

5151
module.exports = (setup, cleanup) => {
52-
let dir
52+
describe('migration 8', () => {
53+
let dir
5354

54-
beforeEach(async () => {
55-
dir = await setup()
56-
})
57-
afterEach(() => cleanup(dir))
55+
beforeEach(async () => {
56+
dir = await setup()
57+
})
58+
afterEach(() => cleanup(dir))
5859

59-
it('should migrate forward', async () => {
60-
await bootstrapKeys(dir, false)
61-
await migration.migrate(dir)
62-
await validateKeys(dir, true)
63-
})
60+
it('should migrate forward', async () => {
61+
await bootstrapKeys(dir, false)
62+
await migration.migrate(dir)
63+
await validateKeys(dir, true)
64+
})
6465

65-
it('should migrate backward', async () => {
66-
await bootstrapKeys(dir, true)
67-
await migration.revert(dir)
68-
await validateKeys(dir, false)
69-
})
66+
it('should migrate backward', async () => {
67+
await bootstrapKeys(dir, true)
68+
await migration.revert(dir)
69+
await validateKeys(dir, false)
70+
})
7071

71-
it('should fail to migrate backward with invalid key name', async () => {
72-
const store = new Datastore(path.join(dir, 'keys'), { extension: '.data', createIfMissing: true })
73-
await store.open()
72+
it('should fail to migrate backward with invalid key name', async () => {
73+
const store = new Datastore(path.join(dir, 'keys'), { extension: '.data', createIfMissing: true })
74+
await store.open()
7475

75-
await store.put(new Key('/pkcs8/mfawc'), '')
76-
await store.put(new Key('/info/mfawc'), '')
76+
await store.put(new Key('/pkcs8/mfawc'), '')
77+
await store.put(new Key('/info/mfawc'), '')
7778

78-
await store.close()
79+
await store.close()
7980

80-
expect(migration.revert(dir)).to.eventually.rejectedWith('Unknown format of key\'s name!')
81+
expect(migration.revert(dir)).to.eventually.rejectedWith('Unknown format of key\'s name!')
82+
})
8183
})
8284
}

test/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Node specific tests', () => {
4444
})
4545

4646
describe('migrations tests', () => {
47-
require('./migrations/migration-8-test')(repoSetup, repoCleanup)
47+
require('./migrations/migration-8-test')(createRepo, repoCleanup)
4848
})
4949

5050
describe('init tests', () => {

0 commit comments

Comments
 (0)