mirror of
https://github.com/standardnotes/web.git
synced 2024-10-27 16:31:40 +03:00
199 lines
6.6 KiB
JavaScript
199 lines
6.6 KiB
JavaScript
/* eslint-disable no-unused-expressions */
|
|
/* eslint-disable no-undef */
|
|
import * as Factory from './lib/factory.js'
|
|
chai.use(chaiAsPromised)
|
|
const expect = chai.expect
|
|
|
|
describe('protocol', function () {
|
|
beforeEach(async function () {
|
|
localStorage.clear()
|
|
this.application = await Factory.createInitAppWithFakeCrypto()
|
|
this.email = UuidGenerator.GenerateUuid()
|
|
this.password = UuidGenerator.GenerateUuid()
|
|
})
|
|
|
|
afterEach(async function () {
|
|
await Factory.safeDeinit(this.application)
|
|
this.application = null
|
|
localStorage.clear()
|
|
})
|
|
|
|
it('checks version to make sure its 004', function () {
|
|
expect(this.application.encryptionService.getLatestVersion()).to.equal('004')
|
|
})
|
|
|
|
it('checks supported versions to make sure it includes 001, 002, 003, 004', function () {
|
|
expect(this.application.encryptionService.supportedVersions()).to.eql(['001', '002', '003', '004'])
|
|
})
|
|
|
|
it('platform derivation support', function () {
|
|
expect(
|
|
this.application.encryptionService.platformSupportsKeyDerivation({
|
|
version: '001',
|
|
}),
|
|
).to.equal(true)
|
|
expect(
|
|
this.application.encryptionService.platformSupportsKeyDerivation({
|
|
version: '002',
|
|
}),
|
|
).to.equal(true)
|
|
expect(
|
|
this.application.encryptionService.platformSupportsKeyDerivation({
|
|
version: '003',
|
|
}),
|
|
).to.equal(true)
|
|
expect(
|
|
this.application.encryptionService.platformSupportsKeyDerivation({
|
|
version: '004',
|
|
}),
|
|
).to.equal(true)
|
|
expect(
|
|
this.application.encryptionService.platformSupportsKeyDerivation({
|
|
version: '005',
|
|
}),
|
|
).to.equal(true)
|
|
})
|
|
|
|
it('key params versions <= 002 should include pw_cost in portable value', function () {
|
|
const keyParams002 = this.application.encryptionService.createKeyParams({
|
|
version: '002',
|
|
pw_cost: 5000,
|
|
})
|
|
expect(keyParams002.getPortableValue().pw_cost).to.be.ok
|
|
})
|
|
|
|
it('version comparison of 002 should be older than library version', function () {
|
|
expect(this.application.encryptionService.isVersionNewerThanLibraryVersion('002')).to.equal(false)
|
|
})
|
|
|
|
it('version comparison of 005 should be newer than library version', function () {
|
|
expect(this.application.encryptionService.isVersionNewerThanLibraryVersion('005')).to.equal(true)
|
|
})
|
|
|
|
it('library version should not be outdated', function () {
|
|
var currentVersion = this.application.encryptionService.getLatestVersion()
|
|
expect(isProtocolVersionExpired(currentVersion)).to.equal(false)
|
|
})
|
|
|
|
it('001 protocol should be expired', function () {
|
|
expect(isProtocolVersionExpired(ProtocolVersion.V001)).to.equal(true)
|
|
})
|
|
|
|
it('002 protocol should be expired', function () {
|
|
expect(isProtocolVersionExpired(ProtocolVersion.V002)).to.equal(true)
|
|
})
|
|
|
|
it('004 protocol should not be expired', function () {
|
|
expect(isProtocolVersionExpired(ProtocolVersion.V004)).to.equal(false)
|
|
})
|
|
|
|
it('decrypting already decrypted payload should throw', async function () {
|
|
const payload = Factory.createNotePayload()
|
|
let error
|
|
try {
|
|
await this.application.encryptionService.decryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
})
|
|
} catch (e) {
|
|
error = e
|
|
}
|
|
expect(error).to.be.ok
|
|
})
|
|
|
|
it('ejected payload should not have meta fields', async function () {
|
|
await this.application.addPasscode('123')
|
|
const payload = Factory.createNotePayload()
|
|
const result = CreateEncryptedServerSyncPushPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(result.fields).to.not.be.ok
|
|
expect(result.source).to.not.be.ok
|
|
expect(result.format).to.not.be.ok
|
|
expect(result.dirtyIndex).to.not.be.ok
|
|
})
|
|
|
|
it('encrypted payload for server should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
|
|
it('ejected payload for server should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
|
|
it('encrypted payload for storage should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedLocalStorageContextPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
|
|
it('ejected payload for storage should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedLocalStorageContextPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
|
|
it('encrypted payload for file should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedBackupFileContextPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
|
|
it('ejected payload for file should include duplicate_of field', async function () {
|
|
const payload = Factory.createNotePayload('Test')
|
|
const encryptedPayload = CreateEncryptedBackupFileContextPayload(
|
|
await this.application.encryptionService.encryptSplitSingle({
|
|
usesItemsKeyWithKeyLookup: {
|
|
items: [payload],
|
|
},
|
|
}),
|
|
)
|
|
expect(encryptedPayload).to.be.ok
|
|
expect(encryptedPayload).to.contain.keys('duplicate_of')
|
|
})
|
|
})
|