From 211113fb1aa37b8dbfe82fd5ea40969d81d64093 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Tue, 25 Apr 2017 16:04:17 +0200 Subject: [PATCH 1/5] little flowey --- .flowconfig | 7 +++++++ .travis.yml | 2 +- ARCHITECTURE.md | 4 +--- config.js.dist => config.example.js | 1 + container-start.sh | 6 +++--- readme.md | 5 ++--- rpc.js | 11 ++++++++--- storage/README.md | 4 ++-- 8 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 .flowconfig rename config.js.dist => config.example.js (99%) diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 000000000..4a58bdcde --- /dev/null +++ b/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/.travis.yml b/.travis.yml index 24288c6f2..4160b8719 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "6.6.0" before_script: - npm run-script lint - - cp config.js.dist config.js + - cp config.example.js config.js - npm install bower - ./node_modules/bower/bin/bower install - node ./server.js & diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index b1d2515f1..0d1d94873 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -76,7 +76,7 @@ Chainpad can handle out of order messages, but it performs best when its message By architecting your system such that all clients send to a server which then relays to other clients, you guarantee that a particular chain of patches is consistent between the participants of your session. Cryptpad is capable of using a variety of data stores. -Which data store your instance employs can be [easily configured](https://github.com/xwiki-labs/cryptpad/blob/master/config.js.dist). +Which data store your instance employs can be [easily configured](https://github.com/xwiki-labs/cryptpad/blob/master/config.example.js). You simply need to write an adaptor which conforms to a simple API. The documentation for writing such an adaptor, and the complete list of implemented adaptors, is available [here](https://github.com/xwiki-labs/cryptpad/tree/master/storage). @@ -243,5 +243,3 @@ A session could still have difficulty with very large chains, however, in practi ## Conclusion - - diff --git a/config.js.dist b/config.example.js similarity index 99% rename from config.js.dist rename to config.example.js index 6ef7267c1..692a91c59 100644 --- a/config.js.dist +++ b/config.example.js @@ -1,3 +1,4 @@ +/*@flow*/ /* globals module */ diff --git a/container-start.sh b/container-start.sh index 89f3be1f1..2aa4ae10f 100755 --- a/container-start.sh +++ b/container-start.sh @@ -4,12 +4,12 @@ mkdir -p customize [ -z "$(ls -A customize)" ] && echo "Creating customize folder" \ && cp -R customize.dist/* customize/ \ - && cp config.js.dist customize/config.js + && cp config.example.js customize/config.js -# Linking config.js +# Linking config.js [ ! -h config.js ] && echo "Linking config.js" && ln -s customize/config.js config.js -# Configure +# Configure [ -n "$USE_SSL" ] && echo "Using secure websockets: $USE_SSL" \ && sed -i "s/useSecureWebsockets: .*/useSecureWebsockets: ${USE_SSL},/g" customize/config.js diff --git a/readme.md b/readme.md index b3c8a1a61..60da12331 100644 --- a/readme.md +++ b/readme.md @@ -32,8 +32,8 @@ npm install npm install -g bower ## if necessary bower install -## copy config.js.dist to config.js -cp config.js.dist config.js +## copy config.example.js to config.js +cp config.example.js config.js node ./server.js ``` @@ -162,4 +162,3 @@ sales@xwiki.com [fragment identifier]: https://en.wikipedia.org/wiki/Fragment_identifier [active attack]: https://en.wikipedia.org/wiki/Attack_(computing)#Types_of_attacks [Creative Commons Attribution 2.5 License]: http://creativecommons.org/licenses/by/2.5/ - diff --git a/rpc.js b/rpc.js index d68fa78b4..808815d84 100644 --- a/rpc.js +++ b/rpc.js @@ -1,3 +1,4 @@ +/*@flow*/ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); @@ -375,7 +376,8 @@ var resetUserPins = function (store, Sessions, publicKey, channelList, cb) { }); }; -RPC.create = function (config, cb) { +/*::const ConfigType = require('./config.example.js');*/ +RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) { // load pin-store... console.log('loading rpc module...'); @@ -384,7 +386,11 @@ RPC.create = function (config, cb) { var store; - var rpc = function (ctx, data, respond) { + var rpc = function ( + ctx /*:{ store: Object }*/, + data /*:Array>*/, + respond /*:(?string, ?Array)=>void*/) + { if (!Array.isArray(data)) { return void respond('INVALID_ARG_FORMAT'); } @@ -494,4 +500,3 @@ RPC.create = function (config, cb) { }, 60000); }); }; - diff --git a/storage/README.md b/storage/README.md index 03117d95c..8fabdf53b 100644 --- a/storage/README.md +++ b/storage/README.md @@ -46,14 +46,14 @@ While we migrate to our new Netflux API, only the leveldb adaptor will be suppor ## removeChannel(channelName, callback) -This method is called (optionally, see config.js.dist for more info) some amount of time after the last client in a channel disconnects. +This method is called (optionally, see config.example.js for more info) some amount of time after the last client in a channel disconnects. It should remove any history of that channel, and execute a callback which takes an error message as an argument. ## Documenting your adaptor Naturally, you should comment your code well before making a PR. -Failing that, you should definitely add notes to `cryptpad/config.js.dist` such that people who wish to install your adaptor know how to do so. +Failing that, you should definitely add notes to `cryptpad/config.example.js` such that people who wish to install your adaptor know how to do so. Notes on how to install the back end, as well as how to install the client for connecting to the back end (as is the case with many datastores), as well as how to configure cryptpad to use your adaptor. The current configuration file should serve as an example of what to add, and how to comment. From 48973bccd617f530a26842b3c74407555d2bbc5a Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Apr 2017 16:11:19 +0200 Subject: [PATCH 2/5] add tests to assert for hash parsing --- www/assert/main.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/www/assert/main.js b/www/assert/main.js index eb9bb9157..3306c3bab 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -139,6 +139,49 @@ define([ strungJSON(orig); }); + // check that old hashes parse correctly + assert(function () { + var secret = Cryptpad.parseHash('67b8385b07352be53e40746d2be6ccd7XAYSuJYYqa9NfmInyHci7LNy'); + return secret.channel === "67b8385b07352be53e40746d2be6ccd7" && + secret.key === "XAYSuJYYqa9NfmInyHci7LNy" && + secret.version === 0; + }, "Old hash failed to parse"); + + // make sure version 1 hashes parse correctly + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI'); + return secret.version === 1 && + secret.mode === "edit" && + secret.channel === "3Ujt4F2Sjnjbis6CoYWpoQ" && + secret.key === "usn4+9CqVja8Q7RZOGTfRgqI" && + !secret.present; + }, "version 1 hash failed to parse"); + + // test support for present mode in hashes + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/present'); + return secret.version === 1 + && secret.mode === "edit" + && secret.channel === "CmN5+YJkrHFS3NSBg-P7Sg" + && secret.key === "DNZ2wcG683GscU4fyOyqA87G" + && secret.present; + }, "version 1 hash failed to parse"); + + // test support for trailing slash + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/'); + return secret.version === 1 && + secret.mode === "edit" && + secret.channel === "3Ujt4F2Sjnjbis6CoYWpoQ" && + secret.key === "usn4+9CqVja8Q7RZOGTfRgqI" && + !secret.present; + }, "test support for trailing slashes in version 1 hash failed to parse"); + + assert(function () { + // TODO + return true; + }, "version 2 hash failed to parse correctly"); + var swap = function (str, dict) { return str.replace(/\{\{(.*?)\}\}/g, function (all, key) { return typeof dict[key] !== 'undefined'? dict[key] : all; From f8f97036be76599ee5b812ca5aedd0c9ac32f574 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Apr 2017 16:12:28 +0200 Subject: [PATCH 3/5] ignore media-tag.js --- .jshintignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jshintignore b/.jshintignore index ae60d4ba0..51636ed77 100644 --- a/.jshintignore +++ b/.jshintignore @@ -9,4 +9,4 @@ server.js NetFluxWebsocketSrv.js NetFluxWebsocketServer.js WebRTCSrv.js - +www/common/media-tag.js From f196b836db801cab6908ee4a641e8de3b6647635 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Apr 2017 16:17:52 +0200 Subject: [PATCH 4/5] fix undefined reference --- www/examples/file/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/www/examples/file/main.js b/www/examples/file/main.js index 9a0d142fc..35bf4b191 100644 --- a/www/examples/file/main.js +++ b/www/examples/file/main.js @@ -16,6 +16,7 @@ define([ var $iframe = $('#pad-iframe').contents(); Cryptpad.addLoadingScreen(); + var toolbar; var andThen = function () { var $bar = $iframe.find('.toolbar-container'); @@ -38,9 +39,7 @@ define([ common: Cryptpad }; toolbar = Toolbar.create($bar, null, null, null, null, configTb); - }); - }; Cryptpad.ready(function (err, anv) { From 33090872778d3228e9d2bc7f42dc14b2a420a908 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Apr 2017 17:09:39 +0200 Subject: [PATCH 5/5] send feedback if isArray is not supported --- www/common/cryptpad-common.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 1d5015497..c2559bde2 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1189,6 +1189,11 @@ define([ if (typeof(window.Proxy) === 'undefined') { feedback("NO_PROXIES"); } + + if (typeof(Array.isArray) === 'function') { + feedback("NO_ISARRAY"); + } + $(function() { // Race condition : if document.body is undefined when alertify.js is loaded, Alertify // won't work. We have to reset it now to make sure it uses a correct "body"