diff --git a/.gitignore b/.gitignore
index 1c3273d..fa7e9cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.DS_Store
node_modules
npm-debug.log
src/public/main.js
diff --git a/.travis.yml b/.travis.yml
index eb25b5f..0c9dcff 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,6 +20,6 @@ before_script:
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
- sleep 5 # give xvfb some time to start
- gulp bundle
- - node index.js &
+ - npm start &
- sleep 5
-script: node_modules/mocha/bin/mocha test/unit --compilers js:babel-core/register && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome
+script: npm run test-travis
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 4231a4b..248d80c 100644
--- a/gulpfile.babel.js
+++ b/gulpfile.babel.js
@@ -62,7 +62,7 @@ gulp.task('test', function() {
let acceptanceTest = spawn(
'node_modules/nightwatch/bin/nightwatch',
- ['--test', 'test/acceptance/index.js', '--config', 'test/acceptance/nightwatch.json'],
+ ['--test', 'test/acceptance/index.js', '--config', 'test/acceptance/nightwatch-local.json'],
{stdio: 'inherit'}
);
diff --git a/package.json b/package.json
index 53adc9d..a10deac 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
"forever": "^0.15.1",
"gulp": "^3.9.0",
"gulp-uglify": "^1.5.1",
+ "he": "^0.5.0",
"moment": "^2.11.2",
"mustache-express": "^1.2.2",
"sanitize-html": "^1.11.3",
@@ -39,13 +40,10 @@
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
- "dev": "gulp start",
- "test": "gulp test"
- },
- "scripts": {
- "start": "gulp start",
+ "start": "npm run bundle && gulp start",
"bundle": "gulp bundle",
- "test": "gulp test"
+ "test": "npm run bundle && gulp test",
+ "test-travis": "node_modules/mocha/bin/mocha test/unit --compilers js:babel-core/register && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome"
},
"author": "Daniel Seripap",
"license": "MIT"
diff --git a/readme.md b/readme.md
index c167549..60da626 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,7 @@
# Darkwire.io
+[](https://travis-ci.org/seripap/darkwire.io) []()
+
Simple encrypted web chat. Powered by [socket.io](http://socket.io) and the [web cryptography API](https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto).
### Installation
@@ -10,11 +12,12 @@ Simple encrypted web chat. Powered by [socket.io](http://socket.io) and the [web
# Bundle JS files (for deployment)
npm bundle
- # Start a local instance of darkwire
+ # Running tests locally
+ brew install chromedriver # Installs chromedriver to /usr/local/bin
+ npm test
+ # Start a local instance of darkwire / for dev
npm start
-Create a **.secret** file in the **/src** folder with a your session secret. It doesn't matter what it is- just keep it private.
-
Darkwire is now running on `http://localhost:3000`
### Deployment
diff --git a/src/js/chat.js b/src/js/chat.js
index ac2aae8..c9b6e9c 100644
--- a/src/js/chat.js
+++ b/src/js/chat.js
@@ -1,5 +1,6 @@
import _ from 'underscore';
import sanitizeHtml from 'sanitize-html';
+import he from 'he';
export default class Chat {
constructor(darkwire, socket) {
@@ -172,11 +173,10 @@ export default class Chat {
return this.log('Username must start with a letter or number.', {error: true});
}
- this.darkwire.updateUsername(newUsername).then((socketData) => {
+ this.darkwire.updateUsername(window.username, newUsername).then((socketData) => {
let modifiedSocketData = {
username: window.username,
- newUsername: socketData.username,
- publicKey: socketData.publicKey
+ newUsername: socketData.username
};
this.socket.emit('update user', modifiedSocketData);
@@ -302,7 +302,10 @@ export default class Chat {
if (messageType === 'action') {
$usernameDiv.css('color','').prepend('*');
}
- $messageBodyDiv.html(unescape(data.message));
+ let unescapedMessage = unescape(data.message);
+ let lineBreaks = /<br \/>/g;
+ unescapedMessage = unescapedMessage.replace(lineBreaks, '
');
+ $messageBodyDiv.html(unescapedMessage);
} else {
$messageBodyDiv.html(this.darkwire.addFileToQueue(data));
}
diff --git a/src/js/darkwire.js b/src/js/darkwire.js
index 284c0b6..1c1d3c8 100644
--- a/src/js/darkwire.js
+++ b/src/js/darkwire.js
@@ -51,12 +51,35 @@ export default class Darkwire {
return this._connected;
}
+ get audio() {
+ return this._audio;
+ }
+
get users() {
return this._users;
}
- get audio() {
- return this._audio;
+ getUserById(id) {
+ return _.findWhere(this._users, {id: id});
+ }
+
+ getUserByName(username) {
+ return _.findWhere(this._users, {username: username});
+ }
+
+ updateUser(data) {
+ return new Promise((resolve, reject) => {
+ let user = this.getUserById(data.id);
+
+ if (!user) {
+ return reject();
+ }
+
+ let oldUsername = user.username;
+
+ user.username = data.username;
+ resolve(oldUsername);
+ });
}
addUser(data) {
@@ -97,27 +120,40 @@ export default class Darkwire {
return this._users;
}
- updateUsername(username) {
+ updateUsername(username, newUsername) {
+ let user = null;
+
return new Promise((resolve, reject) => {
+ if (newUsername) {
+ user = this.getUserByName(username);
+ }
+
if (username) {
- Promise.all([
- this._cryptoUtil.createPrimaryKeys()
- ])
- .then((data) => {
- this._keys = {
- public: data[0].publicKey,
- private: data[0].privateKey
- };
- return Promise.all([
- this._cryptoUtil.exportKey(data[0].publicKey, 'spki')
- ]);
- })
- .then((exportedKeys) => {
- resolve({
- username: username,
- publicKey: exportedKeys[0]
+ if (!user) {
+ Promise.all([
+ this._cryptoUtil.createPrimaryKeys()
+ ])
+ .then((data) => {
+ this._keys = {
+ public: data[0].publicKey,
+ private: data[0].privateKey
+ };
+ return Promise.all([
+ this._cryptoUtil.exportKey(data[0].publicKey, 'spki')
+ ]);
+ })
+ .then((exportedKeys) => {
+ resolve({
+ username: username,
+ publicKey: exportedKeys[0]
+ });
});
- });
+ } else {
+ resolve({
+ username: newUsername,
+ publicKey: user.publicKey
+ });
+ }
}
});
}
diff --git a/src/js/main.js b/src/js/main.js
index 4b66ab3..ba820e7 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -5,6 +5,7 @@ import CryptoUtil from './crypto';
import Chat from './chat';
import moment from 'moment';
import sanitizeHtml from 'sanitize-html';
+import he from 'he';
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
@@ -61,25 +62,21 @@ $(function() {
// Prevents input from having injected markup
function cleanInput(input) {
- let message = sanitizeHtml(_.escape(input), {
- allowedTags: ['b', 'i', 'em', 'strong', 'a'],
- allowedAttributes: {
- 'a': ['href']
- }
- });
- // let message = $('