2018-02-21 05:31:27 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import * as api from '../../../app/api';
|
|
|
|
import Keychain from '../../../app/keychain';
|
|
|
|
|
|
|
|
const encoder = new TextEncoder();
|
2018-06-21 02:05:33 +02:00
|
|
|
const plaintext = new Blob([encoder.encode('hello world!')]);
|
2018-02-21 05:31:27 +01:00
|
|
|
const metadata = {
|
|
|
|
name: 'test.txt',
|
|
|
|
type: 'text/plain'
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('API', function() {
|
2018-06-21 02:05:33 +02:00
|
|
|
describe('websocket upload', function() {
|
2018-02-21 05:31:27 +01:00
|
|
|
it('returns file info on success', async function() {
|
|
|
|
const keychain = new Keychain();
|
2018-06-22 22:17:23 +02:00
|
|
|
const enc = keychain.encryptStream(plaintext);
|
2018-02-21 05:31:27 +01:00
|
|
|
const meta = await keychain.encryptMetadata(metadata);
|
|
|
|
const verifierB64 = await keychain.authKeyB64();
|
2018-02-24 20:24:12 +01:00
|
|
|
const p = function() {};
|
2018-06-22 22:17:23 +02:00
|
|
|
const up = api.uploadWs(
|
2018-06-21 02:05:33 +02:00
|
|
|
enc.stream,
|
|
|
|
enc.streamInfo,
|
|
|
|
meta,
|
|
|
|
verifierB64,
|
|
|
|
keychain,
|
|
|
|
p
|
|
|
|
);
|
|
|
|
|
2018-02-21 05:31:27 +01:00
|
|
|
const result = await up.result;
|
|
|
|
assert.ok(result.url);
|
|
|
|
assert.ok(result.id);
|
|
|
|
assert.ok(result.ownerToken);
|
|
|
|
});
|
2018-02-24 20:24:12 +01:00
|
|
|
|
|
|
|
it('can be cancelled', async function() {
|
|
|
|
const keychain = new Keychain();
|
2018-06-22 22:17:23 +02:00
|
|
|
const enc = keychain.encryptStream(plaintext);
|
2018-02-24 20:24:12 +01:00
|
|
|
const meta = await keychain.encryptMetadata(metadata);
|
|
|
|
const verifierB64 = await keychain.authKeyB64();
|
|
|
|
const p = function() {};
|
2018-06-22 22:17:23 +02:00
|
|
|
const up = api.uploadWs(
|
2018-06-21 02:05:33 +02:00
|
|
|
enc.stream,
|
|
|
|
enc.streamInfo,
|
|
|
|
meta,
|
|
|
|
verifierB64,
|
|
|
|
keychain,
|
|
|
|
p
|
|
|
|
);
|
2018-02-24 20:24:12 +01:00
|
|
|
up.cancel();
|
|
|
|
try {
|
|
|
|
await up.result;
|
|
|
|
assert.fail('not cancelled');
|
|
|
|
} catch (e) {
|
|
|
|
assert.equal(e.message, '0');
|
|
|
|
}
|
|
|
|
});
|
2018-02-21 05:31:27 +01:00
|
|
|
});
|
|
|
|
});
|