diff --git a/.dump_log.sh b/.dump_log.sh new file mode 100755 index 000000000..ce0c3dc08 --- /dev/null +++ b/.dump_log.sh @@ -0,0 +1,36 @@ +#!/bin/bash +echo "FAILED" + +if [[ $DEMOS == "TRUE" ]]; then + # dump all logs marked as failed, or in .lastlog (timedout) + FAILED_LOGS=$(cat '.failedlogs') + LAST_LOG=$(cat '.lastlog') + + echo "Failed logs: $FAILED_LOGS" + echo "=========================" + for log in $FAILED_LOGS; do + if [[ $log != "" ]]; then + cat "Failed logs: $log" + head $log + echo "----------------" + echo "" + fi + done + + echo "Timed out logs: $LAST_LOG" + echo "=========================" + for log in $LAST_LOG; do + if [[ $log != "" ]]; then + echo "Timedout logs:" + cat $log + echo "----------------" + echo "" + fi + done +else + # dump the test suite log + if [[ TEST_SUITE == '' ]]; then + TEST_SUITE='suite' + fi + cat "tests/suite/logs/${TEST_NAME}/${TEST_SUITE}.log" +fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index e65b67cc3..09457e626 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.failedlogs +.lastlog + package-lock.json jiffclient.vim *.DS_Store diff --git a/.travis.yml b/.travis.yml index c231e62ac..6b44b7dbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ before_install: - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules - git submodule update --init --recursive # End submodules fix +after_failure: + - ./.dump_log.sh + node_js: - '10' env: @@ -32,12 +35,151 @@ env: - TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='comparison' - TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='ifelse' script: -- while sleep 9m; do echo "=====[ $SECONDS seconds still running ]====="; done & -- if [ "$DEMOS" == "TRUE" ]; then npm run-script test-demo -- \*; else npm run test -- "$TEST_NAME" "$TEST_SUITE"; fi -- kill %1 -cache: - directories: - - node_modules + - while sleep 9m; do echo "=====[ $SECONDS seconds still running ]====="; done & + - if [ "$DEMOS" == "TRUE" ]; then timeout -s9 48m npm run coverage:demo -- \*; else timeout -s9 48m npm run coverage -- "$TEST_NAME" "$TEST_SUITE"; fi + - kill %1 + +jobs: + include: + - stage: test + env: DEMOS="TRUE" + workspaces: + create: + name: 1 + paths: + - .nyc_output + - env: TEST_NAME='base' TEST_SUITE='' + workspaces: + create: + name: 2 + paths: + - .nyc_output + - env: TEST_NAME='bigNumber' TEST_SUITE='' + workspaces: + create: + name: 3 + paths: + - .nyc_output + - env: TEST_NAME='negativeNumber' TEST_SUITE='' + workspaces: + create: + name: 4 + paths: + - .nyc_output + - env: TEST_NAME='bigNumber-negativeNumber' TEST_SUITE='' + workspaces: + create: + name: 5 + paths: + - .nyc_output + - env: TEST_NAME='restAPI' TEST_SUITE='' + workspaces: + create: + name: 6 + paths: + - .nyc_output + - env: TEST_NAME='bits' TEST_SUITE='' + workspaces: + create: + name: 7 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='share' + workspaces: + create: + name: 8 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='arithmetic' + workspaces: + create: + name: 9 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='constant arithmetic' + workspaces: + create: + name: 10 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='constant comparison' + workspaces: + create: + name: 11 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='comparison' + workspaces: + create: + name: 12 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint' TEST_SUITE='ifelse' + workspaces: + create: + name: 13 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='share' + workspaces: + create: + name: 14 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='arithmetic' + workspaces: + create: + name: 15 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='constant arithmetic' + workspaces: + create: + name: 16 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='constant comparison' + workspaces: + create: + name: 17 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='comparison' + workspaces: + create: + name: 18 + paths: + - .nyc_output + - env: TEST_NAME='fixedpoint-negativeNumber' TEST_SUITE='ifelse' + workspaces: + create: + name: 19 + paths: + - .nyc_output + - stage: report + script: npm run coverage:report + workspaces: + use: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + - 7 + - 8 + - 9 + - 10 + - 11 + - 12 + - 13 + - 14 + - 15 + - 16 + - 17 + - 18 + - 19 + notifications: slack: secure: DuaE/q/B/la8rNGXsn/p3owtWZmn6th1rAJUXTIUUU48OjE86ehzMD40JMLMyAty3f/NHYOPufS7//AfpaIf4cGE6/4wHcTVoLOzRv6aP7WM0SvMy1WS5QgP7ryIjciyXFczknQ+JSMcXlxQDKtMCT7wBIwQO1WrB+T8e617y575t/ofO39k9Za1NA81MlrdWxTIWTDGMo17T+Pd/zz4ImHGYoifUzXi9DdH/4Zgy9SJxWQJ3PO/5RWef4qu1mBGXdanIEd63mYjIIQh8nJLn3pvWp7rQnChmwRqURDc6hpwdPJqeWO5knqhNlu/u7/TJI985rvTOPYljXfReXdF1OEHuq+prWGhv4VbxJzTpQ9PJZ42Ac1k6nCaMCJfCphpsUL48+qgeRY9IyBoqARw4Ne8hTerc7P0T/iQxgZk8zVVahdf0C27sPD0B563gMWvFKxW41YbvHwku7CpReaCt+pcGTd77p+v0mGZGlWNv/kV6KXMBHmQXGYEdVSpscEdlFbByZKagY8lrsadyZtaAaUCdD4VRGaYCWPh/+eBsVdS94r7XRHXBceiSd3ZY093r7lMO9yGnyDwqSydL7JgncO/GxWMhsEz2vRV+bgZlLU2yo60H8Kg1jvmpVP3o0d8wfkDUyLVOkJiSDZ+LuhQZ10f1MnP3AtVrMJFEKITmqw= diff --git a/README.md b/README.md index 49165bbce..388bfcd87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # JIFF [![Build Status](https://travis-ci.org/multiparty/jiff.svg?branch=master)](https://travis-ci.org/multiparty/jiff) +[![Coverage Status](https://coveralls.io/repos/github/multiparty/jiff/badge.svg)](https://coveralls.io/github/multiparty/jiff) JIFF is a JavaScript library for building applications that rely on secure multi-party computation. JIFF is built to be highly flexible with a focus on usability, with the ability to be run in the browser, on mobile phones, or via Node.js. JIFF is designed so that developers need not be familiar with MPC techniques or know the details of cryptographic protocols in order to build secure applications. diff --git a/demos/mpc-as-a-service/server.js b/demos/mpc-as-a-service/server.js index 83537d861..b03f09cb0 100644 --- a/demos/mpc-as-a-service/server.js +++ b/demos/mpc-as-a-service/server.js @@ -61,7 +61,12 @@ var options = { return params; } - ] + ], + log: function (_, label) { + if (['share', 'open', 'crypto_provider'].indexOf(label) === -1) { + console.log.apply(console, Array.from(arguments).slice(1)); + } + } } }; diff --git a/demos/run-test.sh b/demos/run-test.sh index 4dc8cf332..7bfa40731 100755 --- a/demos/run-test.sh +++ b/demos/run-test.sh @@ -2,7 +2,13 @@ mkdir -p logs +LASTLOG='.lastlog' +FAILEDLOGS='.failedlogs' + if [ "$1" == "*" ]; then + rm -f FAILEDLOGS + touch FAILEDLOGS + EXIT_CODE=0 for i in demos/*; do if [ -f "$i/test.js" ] || [ -f "$i/test.sh" ]; then @@ -21,7 +27,9 @@ else TESTDIR=${1%/} NAME=$(basename $TESTDIR) logs="logs/${NAME}.log" + echo "Server logs at ${logs}" + echo "$logs" > $LASTLOG if [ -f "$TESTDIR/test.sh" ]; then # demo has custom test bash script, run it @@ -45,6 +53,11 @@ else EXIT_CODE=$? kill $(ps aux | grep " ${TESTDIR}/server\.js" | awk '{ print $2}') + + echo "" > $LASTLOG + if [[ $EXIT_CODE != "0" ]]; then + echo "$logs" >> $FAILEDLOGS + fi exit "$EXIT_CODE" fi fi diff --git a/demos/threshold/server.js b/demos/threshold/server.js index ca5a1c8dc..4c1b1d9c1 100644 --- a/demos/threshold/server.js +++ b/demos/threshold/server.js @@ -2,8 +2,18 @@ var path = require('path'); var express = require('express'); var app = express(); var http = require('http').Server(app); + var JIFFServer = require('../../lib/jiff-server'); -new JIFFServer(http, { logs:false }); +new JIFFServer(http, { + logs: false, + hooks: { + log: function (_, label) { + if (['share', 'open', 'crypto_provider'].indexOf(label) === -1) { + console.log.apply(console, Array.from(arguments).slice(1)); + } + } + } +}); // Serve static files. app.use('/demos', express.static(path.join(__dirname, '..', '..', 'demos'))); diff --git a/demos/web-mpc/server.js b/demos/web-mpc/server.js index 8b1fcd46e..7d4201659 100644 --- a/demos/web-mpc/server.js +++ b/demos/web-mpc/server.js @@ -14,6 +14,13 @@ var jiff_instance = new JIFFServer(http, { socketOptions: { pingTimeout: 1000, pingInterval: 2000 + }, + hooks: { + log: function (_, label) { + if (['share', 'open', 'crypto_provider'].indexOf(label) === -1) { + console.log.apply(console, Array.from(arguments).slice(1)); + } + } } }); jiff_instance.computationMaps.maxCount['web-mpc'] = 100000; // upper bound on how input parties can submit! diff --git a/lib/server/handlers.js b/lib/server/handlers.js index 047d2e0f0..a1e1c88e7 100644 --- a/lib/server/handlers.js +++ b/lib/server/handlers.js @@ -6,7 +6,7 @@ module.exports = function (jiffServer) { // initialize a party: either return an initialization message with the party id or an error message (e.g. if computation is full or requested id is taken) jiffServer.handlers.initializeParty = function (computation_id, party_id, party_count, msg, _s1) { - jiffServer.hooks.log(jiffServer, 'initialize with ', computation_id, '-', party_id, ' #', party_count, ' : ', msg, '::', _s1); + jiffServer.hooks.log(jiffServer, 'initialize ', computation_id, '-', party_id, ' #', party_count, ' : ', msg, '::', _s1); // s1 is reserved for server use only! if (_s1 !== true && party_id === 's1') { @@ -105,7 +105,7 @@ module.exports = function (jiffServer) { }; jiffServer.handlers.share = function (computation_id, from_id, msg) { - jiffServer.hooks.log(jiffServer, 'share from', computation_id, '-', from_id, ' : ', msg); + jiffServer.hooks.log(jiffServer, 'share', computation_id, '-', from_id, ' : ', msg); try { msg = jiffServer.hooks.execute_array_hooks('beforeOperation', [jiffServer, 'share', computation_id, from_id, msg], 4); @@ -123,7 +123,7 @@ module.exports = function (jiffServer) { }; jiffServer.handlers.open = function (computation_id, from_id, msg) { - jiffServer.hooks.log(jiffServer, 'open from', computation_id, '-', from_id, ' : ', msg); + jiffServer.hooks.log(jiffServer, 'open', computation_id, '-', from_id, ' : ', msg); try { msg = jiffServer.hooks.execute_array_hooks('beforeOperation', [jiffServer, 'open', computation_id, from_id, msg], 4); @@ -141,7 +141,7 @@ module.exports = function (jiffServer) { }; jiffServer.handlers.crypto_provider = function (computation_id, from_id, msg) { - jiffServer.hooks.log(jiffServer, 'crypto_provider from', computation_id, '-', from_id, ':', msg); + jiffServer.hooks.log(jiffServer, 'crypto_provider', computation_id, '-', from_id, ':', msg); try { msg = jiffServer.hooks.execute_array_hooks('beforeOperation', [jiffServer, 'crypto_provider', computation_id, from_id, msg], 4); @@ -210,7 +210,7 @@ module.exports = function (jiffServer) { }; jiffServer.handlers.custom = function (computation_id, from_id, msg) { - jiffServer.hooks.log(jiffServer, 'custom from', computation_id, '-', from_id, ':', msg); + jiffServer.hooks.log(jiffServer, 'custom', computation_id, '-', from_id, ':', msg); try { msg = jiffServer.hooks.execute_array_hooks('beforeOperation', [jiffServer, 'custom', computation_id, from_id, msg], 4); diff --git a/package.json b/package.json index e2cb99705..b265b5f8c 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,9 @@ "scripts": { "test": "./tests/suite/test.sh", "suite": "./tests/suite/suite.sh", + "coverage": "nyc --no-clean npm run test", + "coverage:report": "nyc report --reporter=text-lcov | coveralls", + "coverage:demo": "nyc --no-clean npm run test-demo", "gen-docs": "jsdoc -r -c docs/jsdoc.conf.json && sed -i -e 's/lib\\/ext\\/README.md/extensions.html/g' docs/jsdoc/*.html && sed -i -e 's/lib\\/ext\\/Hooks.md/hooks.html/g' docs/jsdoc/*.html && sed -i -e 's/Hooks.md/hooks.html/g' docs/jsdoc/*.html && sed -i -e 's/CONTRIBUTING.md/CONTRIBUTING.html/g' docs/jsdoc/*.html && grep -rl \"module:jiff-client~JIFFClient#\" docs/jsdoc/*.html | xargs sed -i 'html' 's/module:jiff-client~JIFFClient#//g'", "test-demo": "./demos/run-test.sh", "fix-memory-limit": "cross-env LIMIT=4096 increase-memory-limit", @@ -60,6 +63,7 @@ "devDependencies": { "browserify": "^16.5.2", "chai": "^4.1.2", + "coveralls": "^3.0.9", "eslint": "^4.19.1", "eslint-plugin-requirejs": "^2.0.1", "express": "^4.16.3", @@ -67,6 +71,8 @@ "marked": "^0.7.0", "minimist": "^1.2.0", "mocha": "^4.1.0", - "neptune-notebook": "^1.3.1" + "mocha-lcov-reporter": "^1.3.0", + "neptune-notebook": "^1.3.1", + "nyc": "^15.0.0" } } diff --git a/tests/suite/server.js b/tests/suite/server.js index f37275c42..f2c18ddc7 100644 --- a/tests/suite/server.js +++ b/tests/suite/server.js @@ -10,8 +10,15 @@ var jiffBigNumberServer = require('../../lib/ext/jiff-server-bignumber'); var jiffWebSocketServer = require('../../lib/ext/jiff-server-websockets'); var options = { - logs: true, - app: app + logs: false, + app: app, + hooks: { + log: function (_, label) { + if (['share', 'open', 'crypto_provider'].indexOf(label) === -1) { + console.log.apply(console, Array.from(arguments).slice(1)); + } + } + } }; var jiff_instance = new jiffServer(http, options);