-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vault12/vault12-integration-pt2
vault12-integration-pt2
- Loading branch information
Showing
14 changed files
with
136 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { StorageDriver } from './storage-driver.interface'; | ||
|
||
/** | ||
* temporary created in-memory storage for testing purposes | ||
*/ | ||
export class InMemoryStorage implements StorageDriver { | ||
private storage: {[key: string]: any} = {}; | ||
get(key: string) { | ||
return Promise.resolve(this.storage[key]); | ||
} | ||
set (key: string, value: any) { | ||
this.storage[key] = value; | ||
return Promise.resolve(); | ||
} | ||
remove(key: string) { | ||
delete this.storage[key]; | ||
return Promise.resolve(); | ||
} | ||
reset() { | ||
this.storage = {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CryptoStorage } from '../crypto-storage/crypto-storage'; | ||
import { InMemoryStorage } from '../crypto-storage/in-memory-storage'; | ||
import { NaCl } from '../nacl/nacl'; | ||
import { testRelayURL } from '../tests.helper'; | ||
import { Mailbox } from './mailbox'; | ||
|
||
|
||
describe('Mailbox / Transfer Messages', () => { | ||
|
||
let Alice: Mailbox; | ||
let Bob: Mailbox; | ||
const messages = [ | ||
JSON.stringify({object: 'message'}), | ||
'some unencrypted message', | ||
'special ;@@#2sd characters', | ||
'кирилиця' | ||
]; | ||
const encryptMessages = [true, false]; | ||
const storage = new InMemoryStorage(); | ||
|
||
beforeAll(() => { | ||
NaCl.setDefaultInstance(); | ||
CryptoStorage.setStorageDriver(storage); | ||
}); | ||
|
||
encryptMessages.forEach(encrypt => { | ||
messages.forEach((msg) => { | ||
describe(`transfer message ${JSON.stringify(msg)} ${(encrypt ? 'with' : 'without')} encryption`, () => { | ||
beforeAll(async () => { | ||
storage.reset(); | ||
Alice = await Mailbox.new('Alice'); | ||
Bob = await Mailbox.new('Bob'); | ||
|
||
await Alice.keyRing.addGuest('Bob', Bob.keyRing.getPubCommKey()); | ||
await Bob.keyRing.addGuest('Alice', Alice.keyRing.getPubCommKey()); | ||
}); | ||
|
||
it('upload', async () => { | ||
const token = await Alice.upload(testRelayURL, 'Bob', msg, encrypt); | ||
expect(token.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('download', async () => { | ||
const [ message ] = await Bob.download(testRelayURL); | ||
expect(message.data).toEqual(msg); | ||
Bob.delete(testRelayURL, [message.nonce]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters