WIP cli tests for rpc
This commit is contained in:
parent
023c29795a
commit
d81ff791ad
@ -24,13 +24,15 @@ var createNetwork = Client.createNetwork = function (url, cb) {
|
|||||||
var info = {};
|
var info = {};
|
||||||
|
|
||||||
Netflux.connect(url, function (url) {
|
Netflux.connect(url, function (url) {
|
||||||
|
// this websocket seems to never close properly if the error is
|
||||||
|
// ECONNREFUSED
|
||||||
info.websocket = new WebSocket(url)
|
info.websocket = new WebSocket(url)
|
||||||
.on('error', function (err) {
|
.on('error', function (err) {
|
||||||
console.log(err);
|
CB(err);
|
||||||
})
|
})
|
||||||
.on('close', function (err) {
|
.on('close', function (err) {
|
||||||
console.log("close");
|
console.log("CLOSE_ERROR", err);
|
||||||
console.log(err);
|
delete info.websocket;
|
||||||
});
|
});
|
||||||
return info.websocket;
|
return info.websocket;
|
||||||
}).then(function (network) {
|
}).then(function (network) {
|
||||||
@ -77,7 +79,10 @@ Client.create = function (config, cb) {
|
|||||||
if (config.network) { return; }
|
if (config.network) { return; }
|
||||||
// connect to the network...
|
// connect to the network...
|
||||||
createNetwork('ws://localhost:3000/cryptpad_websocket', w(function (err, info) {
|
createNetwork('ws://localhost:3000/cryptpad_websocket', w(function (err, info) {
|
||||||
//console.log(_network);
|
if (err) {
|
||||||
|
w.abort();
|
||||||
|
return void CB(err);
|
||||||
|
}
|
||||||
config.network = info.network;
|
config.network = info.network;
|
||||||
config.websocket = info.websocket;
|
config.websocket = info.websocket;
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
"lint:less": "./node_modules/lesshint/bin/lesshint -c ./.lesshintrc ./customize.dist/src/less2/",
|
"lint:less": "./node_modules/lesshint/bin/lesshint -c ./.lesshintrc ./customize.dist/src/less2/",
|
||||||
"flow": "./node_modules/.bin/flow",
|
"flow": "./node_modules/.bin/flow",
|
||||||
"test": "node scripts/TestSelenium.js",
|
"test": "node scripts/TestSelenium.js",
|
||||||
"test-rpc": "cd scripts && node test-rpc",
|
"test-rpc": "cd scripts/tests && node test-rpc",
|
||||||
"template": "cd customize.dist/src && for page in ../index.html ../privacy.html ../terms.html ../about.html ../contact.html ../what-is-cryptpad.html ../features.html ../../www/login/index.html ../../www/register/index.html ../../www/user/index.html;do echo $page; cp template.html $page; done;"
|
"template": "cd customize.dist/src && for page in ../index.html ../privacy.html ../terms.html ../about.html ../contact.html ../what-is-cryptpad.html ../features.html ../../www/login/index.html ../../www/register/index.html ../../www/user/index.html;do echo $page; cp template.html $page; done;"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
/* globals process */
|
|
||||||
var Client = require("../lib/client/");
|
|
||||||
var Mailbox = require("../www/bower_components/chainpad-crypto").Mailbox;
|
|
||||||
var Nacl = require("tweetnacl");
|
|
||||||
|
|
||||||
var makeKeys = function () {
|
|
||||||
var pair = Nacl.box.keyPair();
|
|
||||||
return {
|
|
||||||
curvePrivate: Nacl.util.encodeBase64(pair.secretKey),
|
|
||||||
curvePublic: Nacl.util.encodeBase64(pair.publicKey),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Client.create(function (err, client) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var channel = "d34ebe83931382fcad9fe2e2d0e2cb5f"; // channel
|
|
||||||
var recipient = "e8jvf36S3chzkkcaMrLSW7PPrz7VDp85lIFNI26dTmw="; // curvePublic
|
|
||||||
|
|
||||||
var keys = makeKeys();
|
|
||||||
var cryptor = Mailbox.createEncryptor(keys);
|
|
||||||
|
|
||||||
var message = cryptor.encrypt(JSON.stringify({
|
|
||||||
type: "CHEESE",
|
|
||||||
author: keys.curvePublic,
|
|
||||||
content: {
|
|
||||||
text: "CAMEMBERT",
|
|
||||||
}
|
|
||||||
}), recipient);
|
|
||||||
|
|
||||||
client.anonRpc.send('WRITE_PRIVATE_MESSAGE', [channel, message], function (err, response) {
|
|
||||||
if (err) {
|
|
||||||
return void console.error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
response = response;
|
|
||||||
// shutdown doesn't work, so we need to do this instead
|
|
||||||
client.shutdown();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
1
scripts/tests/index.js
Normal file
1
scripts/tests/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
require("./test-rpc");
|
||||||
74
scripts/tests/test-rpc.js
Normal file
74
scripts/tests/test-rpc.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
var Client = require("../../lib/client/");
|
||||||
|
var Mailbox = require("../../www/bower_components/chainpad-crypto").Mailbox;
|
||||||
|
var Nacl = require("tweetnacl");
|
||||||
|
var nThen = require("nthen");
|
||||||
|
|
||||||
|
var makeCurveKeys = function () {
|
||||||
|
var pair = Nacl.box.keyPair();
|
||||||
|
return {
|
||||||
|
curvePrivate: Nacl.util.encodeBase64(pair.secretKey),
|
||||||
|
curvePublic: Nacl.util.encodeBase64(pair.publicKey),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Client.create(function (err, client) {
|
||||||
|
if (err) { return void console.error(err); }
|
||||||
|
|
||||||
|
nThen(function () { // BASIC KEY MANAGEMENT
|
||||||
|
// generate keys with login
|
||||||
|
// signing keys
|
||||||
|
// curve keys
|
||||||
|
// drive
|
||||||
|
}).nThen(function () {
|
||||||
|
// make a drive
|
||||||
|
// pin it
|
||||||
|
}).nThen(function () { // MAILBOXES
|
||||||
|
// write to your mailbox
|
||||||
|
// pin your mailbox
|
||||||
|
}).nThen(function () {
|
||||||
|
// create an owned pad
|
||||||
|
// pin the pad
|
||||||
|
// write to it
|
||||||
|
}).nThen(function () {
|
||||||
|
// get pinned usage
|
||||||
|
// remember the usage
|
||||||
|
}).nThen(function () {
|
||||||
|
// upload a file
|
||||||
|
// remember its size
|
||||||
|
}).nThen(function () {
|
||||||
|
// get pinned usage
|
||||||
|
// check that it is consistent with the size of your uploaded file
|
||||||
|
}).nThen(function () {
|
||||||
|
// delete your uploaded file
|
||||||
|
// unpin your owned file
|
||||||
|
}).nThen(function () { // EDITABLE METADATA
|
||||||
|
//
|
||||||
|
}).nThen(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var channel = "d34ebe83931382fcad9fe2e2d0e2cb5f"; // channel
|
||||||
|
var recipient = "e8jvf36S3chzkkcaMrLSW7PPrz7VDp85lIFNI26dTmw="; // curvePublic
|
||||||
|
|
||||||
|
// curve keys
|
||||||
|
var keys = makeCurveKeys();
|
||||||
|
var cryptor = Mailbox.createEncryptor(keys);
|
||||||
|
|
||||||
|
var message = cryptor.encrypt(JSON.stringify({
|
||||||
|
type: "CHEESE",
|
||||||
|
author: keys.curvePublic,
|
||||||
|
content: {
|
||||||
|
text: "CAMEMBERT",
|
||||||
|
}
|
||||||
|
}), recipient);
|
||||||
|
|
||||||
|
client.anonRpc.send('WRITE_PRIVATE_MESSAGE', [channel, message], function (err, response) {
|
||||||
|
if (err) {
|
||||||
|
return void console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = response;
|
||||||
|
// shutdown doesn't work, so we need to do this instead
|
||||||
|
client.shutdown();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user