From d4fa43109fdbc81f4e83e39d1ceb41d0c6fa1cf0 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 3 Nov 2013 11:36:31 +0200 Subject: [PATCH] Don't use 'testing' attr override. Can be used to get the unwrapper 'inner' converse object. Instead, check that the bosh service value of the connection corresponds to the mock object used for jasmine tests. The value tested for is not usable in production, so we're sure we're only running tests. --- converse.js | 22 ++++++++++++++++------ tests/mock.js | 6 ++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/converse.js b/converse.js index f443dc292..ce5a55f15 100644 --- a/converse.js +++ b/converse.js @@ -72,7 +72,6 @@ this.show_only_online_users = false; this.show_emoticons = true; this.show_toolbar = true; - this.testing = false; // Exposes sensitive data for testing. Never set to true in production systems! this.xhr_custom_status = false; this.xhr_custom_status_url = ''; this.xhr_user_search = false; @@ -100,7 +99,6 @@ 'show_only_online_users', 'show_toolbar', 'sid', - 'testing', 'xhr_custom_status', 'xhr_custom_status_url', 'xhr_user_search', @@ -398,10 +396,22 @@ this.windowState = e.type; },this)); this.giveFeedback(__('Online Contacts')); - if (this.testing) { - this.callback(this); - } else { - this.callback(); + + if (this.callback) { + if (this.connection.service === 'jasmine tests') { + // XXX: Call back with the internal converse object. This + // object should never be exposed to production systems. + // 'jasmine tests' is an invalid http bind service value, + // so we're sure that this is just for tests. + // + // TODO: We might need to consider websockets, which + // probably won't use the 'service' attr. Current + // strophe.js version used by converse.js doesn't support + // websockets. + this.callback(this); + } else { + this.callback(); + } } }, this)); }; diff --git a/tests/mock.js b/tests/mock.js index 617e3ac26..3748504c3 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -24,13 +24,19 @@ 'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher' ]; + mock.event = { + 'preventDefault': function () {} + }; + mock.mock_connection = { + 'mock': true, 'muc': { 'listRooms': function () {}, 'join': function () {}, 'leave': function () {}, 'rooms': {} }, + 'service': 'jasmine tests', 'jid': 'dummy@localhost', 'addHandler': function (handler, ns, name, type, id, from, options) { return function () {};