Commit d2ee62da authored by JC Brand's avatar JC Brand

Make sure that there is a valid connection when login API is called

In the process I had to refactor some methods which required the mock
connection of tests to be changed as well.
parent a969d010
...@@ -136,6 +136,7 @@ ...@@ -136,6 +136,7 @@
describe("The live filter", $.proxy(function () { describe("The live filter", $.proxy(function () {
beforeEach(function () { beforeEach(function () {
test_utils.openControlBox(); test_utils.openControlBox();
test_utils.openContactsPanel();
}); });
it("will only appear when roster contacts flow over the visible area", function () { it("will only appear when roster contacts flow over the visible area", function () {
......
...@@ -16,47 +16,40 @@ ...@@ -16,47 +16,40 @@
describe("Authentication", function () { describe("Authentication", function () {
it("needs either a bosh_service_url a websocket_url or both", function () { it("needs either a bosh_service_url a websocket_url or both", function () {
converse.connection.connected = false; var url = converse.bosh_service_url;
var connection = converse.connection;
delete converse.bosh_service_url;
delete converse.connection;
expect(converse.initConnection.bind({})).toThrow( expect(converse.initConnection.bind({})).toThrow(
new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.")); new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both."));
converse.connection.connected = true; converse.bosh_service_url = url;
converse.connection = connection;
}); });
describe("with prebind", function () { describe("with prebind", function () {
it("needs a jid when also using keepalive", function () { it("needs a jid when also using keepalive", function () {
var authentication = converse.authentication; var authentication = converse.authentication;
var connection = converse.connection;
var jid = converse.jid; var jid = converse.jid;
converse.bosh_service_url = "localhost"; delete converse.jid;
converse.connection = undefined;
converse.jid = undefined;
converse.keepalive = true; converse.keepalive = true;
converse.authentication = "prebind"; converse.authentication = "prebind";
expect(converse.initConnection.bind(converse)).toThrow( expect(converse.logIn.bind(converse)).toThrow(
new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user.")); new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, you must supply the JID of the current user."));
converse.authentication= authentication; converse.authentication= authentication;
converse.bosh_service_url = undefined;
converse.connection = connection;
converse.jid = jid; converse.jid = jid;
converse.keepalive = undefined; converse.keepalive = false;
}); });
it("needs jid, rid and sid values when not using keepalive", function () { it("needs jid, rid and sid values when not using keepalive", function () {
var authentication = converse.authentication; var authentication = converse.authentication;
var connection = converse.connection;
var jid = converse.jid; var jid = converse.jid;
converse.bosh_service_url = "localhost"; delete converse.jid;
converse.connection = undefined;
converse.jid = undefined;
converse.keepalive = false;
converse.authentication = "prebind"; converse.authentication = "prebind";
expect(converse.initConnection.bind(converse)).toThrow( expect(converse.logIn.bind(converse)).toThrow(
new Error("initConnection: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values")); new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values"));
converse.authentication= authentication; converse.authentication= authentication;
converse.bosh_service_url = undefined; converse.bosh_service_url = undefined;
converse.connection = connection;
converse.jid = jid; converse.jid = jid;
converse.keepalive = undefined;
}); });
}); });
}); });
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
describe("A headlines box", function () { describe("A headlines box", function () {
beforeEach(function () {
test_utils.openControlBox();
test_utils.openContactsPanel();
});
it("will not open nor display non-headline messages", function () { it("will not open nor display non-headline messages", function () {
/* XMPP spam message: /* XMPP spam message:
* *
......
...@@ -11,34 +11,27 @@ ...@@ -11,34 +11,27 @@
} (this, function ($, mock, test_utils) { } (this, function ($, mock, test_utils) {
var b64_sha1 = converse_api.env.b64_sha1; var b64_sha1 = converse_api.env.b64_sha1;
return describe("The OTR module", $.proxy(function(mock, test_utils) { return describe("The OTR module", function() {
beforeEach($.proxy(function () { it("can store a session passphrase in session storage", function () {
window.localStorage.clear();
window.sessionStorage.clear();
}, converse));
it("can store a session passphrase in session storage", $.proxy(function () {
var pp;
// With no prebind, the user's XMPP password is used and nothing is // With no prebind, the user's XMPP password is used and nothing is
// stored in session storage. // stored in session storage.
this.authentication = "manual"; var auth = converse.authentication;
this.connection.pass = 's3cr3t!'; var pass = converse.connection.pass;
expect(this.otr.getSessionPassphrase()).toBe(this.connection.pass); converse.authentication = "manual";
expect(window.sessionStorage.length).toBe(0); converse.connection.pass = 's3cr3t!';
expect(window.localStorage.length).toBe(0); expect(converse.otr.getSessionPassphrase()).toBe(converse.connection.pass);
// With prebind, a random passphrase is generated and stored in // With prebind, a random passphrase is generated and stored in
// session storage. // session storage.
this.authentication = "prebind"; converse.authentication = "prebind";
pp = this.otr.getSessionPassphrase(); var pp = converse.otr.getSessionPassphrase();
expect(pp).not.toBe(this.connection.pass); expect(pp).not.toBe(converse.connection.pass);
expect(window.sessionStorage.length).toBe(1);
expect(window.localStorage.length).toBe(0);
expect(pp).toBe(window.sessionStorage[b64_sha1(converse.connection.jid)]); expect(pp).toBe(window.sessionStorage[b64_sha1(converse.connection.jid)]);
// Clean up // Clean up
this.authentication = "manual"; converse.authentication = auth;
}, converse)); converse.connection.pass = pass;
}, converse, mock, test_utils)); });
});
})); }));
/*global converse */ /*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["jquery", "mock", "test_utils"], factory);
"jquery",
"mock",
"test_utils"
], function ($, mock, test_utils) {
return factory($, mock, test_utils);
}
);
} (this, function ($, mock, test_utils) { } (this, function ($, mock, test_utils) {
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
var original_connection = converse.connection;
describe("The Registration Panel", $.proxy(function (mock, test_utils) { describe("The Registration Panel", function () {
beforeEach(function () { beforeEach(function () {
test_utils.closeControlBox(); test_utils.closeControlBox();
var connection = mock.mock_connection;
connection.connected = false;
converse._tearDown(); converse._tearDown();
converse.initialized_plugins = []; converse.initialized_plugins = [];
});
afterEach(function () {
test_utils.closeControlBox();
converse.connection = original_connection;
});
it("is not available unless allow_registration=true", function () {
converse.initialize({ converse.initialize({
i18n: window.locales.en, i18n: window.locales.en,
bosh_service_url: 'localhost', bosh_service_url: 'localhost',
allow_registration: true, allow_registration: true,
auto_subscribe: false, auto_subscribe: false,
animate: false, animate: false,
connection: connection, connection: mock.mock_connection,
no_trimming: true, no_trimming: true,
debug: true debug: false
}, function (converse) {
test_utils.closeControlBox();
var cbview = converse.chatboxviews.get('controlbox');
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
cbview = converse.chatboxviews.get('controlbox');
expect(cbview.$el.find('#controlbox-tabs li').length).toBe(2);
expect(cbview.$('#controlbox-tabs li').first().text().trim()).toBe("Sign in");
expect(cbview.$('#controlbox-tabs li').last().text().trim()).toBe("Register");
}); });
test_utils.openControlBox();
}); });
afterEach($.proxy(function () { it("can be opened by clicking on the registration tab", function () {
this.connection.connected = false;
test_utils.closeControlBox();
}, converse));
it("is not available unless allow_registration=true", $.proxy(function () {
test_utils.closeControlBox();
var connection = mock.mock_connection;
connection.connected = false;
converse._tearDown();
converse.initialized_plugins = [];
converse.initialize({ converse.initialize({
i18n: window.locales.en, i18n: window.locales.en,
animate: false,
auto_subscribe: false,
bosh_service_url: 'localhost', bosh_service_url: 'localhost',
connection: connection, allow_registration: true,
auto_subscribe: false,
animate: false,
connection: mock.mock_connection,
no_trimming: true, no_trimming: true,
allow_registration: false, debug: false
debug: true }, function (converse) {
test_utils.closeControlBox();
var cbview = converse.chatboxviews.get('controlbox');
var $tabs = cbview.$('#controlbox-tabs');
var $panels = cbview.$('.controlbox-panes');
var $login = $panels.children().first();
var $registration = $panels.children().last();
expect($tabs.find('li').first().text()).toBe('Sign in');
expect($tabs.find('li').last().text()).toBe('Register');
spyOn(cbview, 'switchTab').andCallThrough();
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
$tabs.find('li').last().find('a').click(); // Click the Register tab
expect($login.is(':visible')).toBe(false);
expect($registration.is(':visible')).toBe(true);
expect(cbview.switchTab).toHaveBeenCalled();
}); });
test_utils.openControlBox(); });
var cbview = this.chatboxviews.get('controlbox');
expect(cbview.$('#controlbox-tabs li').length).toBe(1); it("allows the user to choose an XMPP provider's domain", function () {
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
connection = mock.mock_connection;
connection.connected = false;
converse._tearDown();
converse.initialized_plugins = [];
converse.initialize({ converse.initialize({
i18n: window.locales.en, i18n: window.locales.en,
bosh_service_url: 'localhost', bosh_service_url: 'localhost',
allow_registration: true, allow_registration: true,
auto_subscribe: false, auto_subscribe: false,
animate: false, animate: false,
connection: connection, connection: mock.mock_connection,
no_trimming: true, no_trimming: true,
debug: true debug: false
}, function (converse) {
test_utils.closeControlBox();
var cbview = converse.chatboxviews.get('controlbox');
var registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect');
var $tabs = cbview.$('#controlbox-tabs');
$tabs.find('li').last().find('a').click(); // Click the Register tab
// Check the form layout
var $form = cbview.$('#converse-register');
expect($form.find('input').length).toEqual(2);
expect($form.find('input').first().attr('name')).toEqual('domain');
expect($form.find('input').last().attr('type')).toEqual('submit');
// Check that the input[type=domain] input is required
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
// Check that the form is accepted if input[type=domain] has a value
$form.find('input[name=domain]').val('conversejs.org');
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(converse.connection.connect).toHaveBeenCalled();
}); });
test_utils.openControlBox(); });
cbview = this.chatboxviews.get('controlbox');
expect(cbview.$el.find('#controlbox-tabs li').length).toBe(2);
expect(cbview.$('#controlbox-tabs li').first().text().trim()).toBe("Sign in");
expect(cbview.$('#controlbox-tabs li').last().text().trim()).toBe("Register");
}, converse));
it("can be opened by clicking on the registration tab", $.proxy(function () {
var cbview = this.chatboxviews.get('controlbox');
var $tabs = cbview.$('#controlbox-tabs');
var $panels = cbview.$('.controlbox-panes');
var $login = $panels.children().first();
var $registration = $panels.children().last();
expect($tabs.find('li').first().text()).toBe('Sign in');
expect($tabs.find('li').last().text()).toBe('Register');
spyOn(cbview, 'switchTab').andCallThrough();
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
$tabs.find('li').last().find('a').click(); // Click the Register tab
expect($login.is(':visible')).toBe(false);
expect($registration.is(':visible')).toBe(true);
expect(cbview.switchTab).toHaveBeenCalled();
}, converse));
it("allows the user to choose an XMPP provider's domain", $.proxy(function () {
var cbview = this.chatboxviews.get('controlbox');
var registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(this.connection, 'connect');
var $tabs = cbview.$('#controlbox-tabs');
$tabs.find('li').last().find('a').click(); // Click the Register tab
// Check the form layout
var $form = cbview.$('#converse-register');
expect($form.find('input').length).toEqual(2);
expect($form.find('input').first().attr('name')).toEqual('domain');
expect($form.find('input').last().attr('type')).toEqual('submit');
// Check that the input[type=domain] input is required
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
// Check that the form is accepted if input[type=domain] has a value
$form.find('input[name=domain]').val('conversejs.org');
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(this.connection.connect).toHaveBeenCalled();
}, converse));
it("will render a registration form as received from the XMPP provider", $.proxy(function () {
var cbview = this.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = this.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(this.connection, 'connect').andCallThrough();
expect(registerview._registering).toBeFalsy(); it("will render a registration form as received from the XMPP provider", function () {
expect(this.connection.connected).toBeFalsy(); converse.initialize({
registerview.$('input[name=domain]').val('conversejs.org'); i18n: window.locales.en,
registerview.$('input[type=submit]').click(); bosh_service_url: 'localhost',
expect(registerview.onProviderChosen).toHaveBeenCalled(); allow_registration: true,
expect(registerview._registering).toBeTruthy(); auto_subscribe: false,
expect(this.connection.connect).toHaveBeenCalled(); animate: false,
connection: mock.mock_connection,
no_trimming: true,
debug: false
}, function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
var stanza = new Strophe.Builder("stream:features", { expect(registerview._registering).toBeFalsy();
'xmlns:stream': "http://etherx.jabber.org/streams", expect(converse.connection.connected).toBeFalsy();
'xmlns': "jabber:client" registerview.$('input[name=domain]').val('conversejs.org');
}) registerview.$('input[type=submit]').click();
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up() expect(registerview.onProviderChosen).toHaveBeenCalled();
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}); expect(registerview._registering).toBeTruthy();
this.connection._connect_cb(test_utils.createRequest(stanza)); expect(converse.connection.connect).toHaveBeenCalled();
expect(registerview.getRegistrationFields).toHaveBeenCalled(); var stanza = new Strophe.Builder("stream:features", {
expect(this.connection.connected).toBeTruthy(); 'xmlns:stream': "http://etherx.jabber.org/streams",
'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({ expect(registerview.getRegistrationFields).toHaveBeenCalled();
'type': 'result', expect(converse.connection.connected).toBeTruthy();
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Please choose a username, password and provide your email address').up()
.c('username').up()
.c('password').up()
.c('email');
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.onRegistrationFields).toHaveBeenCalled();
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
expect(registerview.$('input').length).toBe(5);
expect(registerview.$('input[type=submit]').length).toBe(1);
expect(registerview.$('input[type=button]').length).toBe(1);
}, converse));
it("will set form_type to legacy and submit it as legacy", $.proxy(function () { stanza = $iq({
var cbview = this.chatboxviews.get('controlbox'); 'type': 'result',
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab 'id': 'reg1'
var registerview = this.chatboxviews.get('controlbox').registerpanel; }).c('query', {'xmlns': 'jabber:iq:register'})
spyOn(registerview, 'onProviderChosen').andCallThrough(); .c('instructions')
spyOn(registerview, 'getRegistrationFields').andCallThrough(); .t('Please choose a username, password and provide your email address').up()
spyOn(registerview, 'onRegistrationFields').andCallThrough(); .c('username').up()
spyOn(registerview, 'renderRegistrationForm').andCallThrough(); .c('password').up()
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called .c('email');
spyOn(this.connection, 'connect').andCallThrough(); converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.onRegistrationFields).toHaveBeenCalled();
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
expect(registerview.$('input').length).toBe(5);
expect(registerview.$('input[type=submit]').length).toBe(1);
expect(registerview.$('input[type=button]').length).toBe(1);
});
});
registerview.$('input[name=domain]').val('conversejs.org'); it("will set form_type to legacy and submit it as legacy", function () {
registerview.$('input[type=submit]').click(); converse.initialize({
i18n: window.locales.en,
bosh_service_url: 'localhost',
allow_registration: true,
auto_subscribe: false,
animate: false,
connection: mock.mock_connection,
no_trimming: true,
debug: false
}, function (converse) {
test_utils.closeControlBox();
var cbview = converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
var stanza = new Strophe.Builder("stream:features", { registerview.$('input[name=domain]').val('conversejs.org');
'xmlns:stream': "http://etherx.jabber.org/streams", registerview.$('input[type=submit]').click();
'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
this.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Please choose a username, password and provide your email address').up()
.c('username').up()
.c('password').up()
.c('email');
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('legacy');
registerview.$('input[name=username]').val('testusername'); var stanza = new Strophe.Builder("stream:features", {
registerview.$('input[name=password]').val('testpassword'); 'xmlns:stream': "http://etherx.jabber.org/streams",
registerview.$('input[name=email]').val('test@email.local'); 'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Please choose a username, password and provide your email address').up()
.c('username').up()
.c('password').up()
.c('email');
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('legacy');
spyOn(converse.connection, 'send'); registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
registerview.$('input[type=submit]').click(); spyOn(converse.connection, 'send');
expect(converse.connection.send).toHaveBeenCalled(); registerview.$('input[type=submit]').click();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(3);
expect($stanza.children('query').children()[0].tagName).toBe('username');
}, converse));
it("will set form_type to xform and submit it as xform", $.proxy(function () { expect(converse.connection.send).toHaveBeenCalled();
var cbview = this.chatboxviews.get('controlbox'); var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab expect($stanza.children('query').children().length).toBe(3);
var registerview = this.chatboxviews.get('controlbox').registerpanel; expect($stanza.children('query').children()[0].tagName).toBe('username');
spyOn(registerview, 'onProviderChosen').andCallThrough(); });
spyOn(registerview, 'getRegistrationFields').andCallThrough(); });
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(this.connection, 'connect').andCallThrough();
registerview.$('input[name=domain]').val('conversejs.org'); it("will set form_type to xform and submit it as xform", function () {
registerview.$('input[type=submit]').click(); converse.initialize({
i18n: window.locales.en,
bosh_service_url: 'localhost',
allow_registration: true,
auto_subscribe: false,
animate: false,
connection: mock.mock_connection,
no_trimming: true,
debug: false
}, function (converse) {
test_utils.closeControlBox();
var cbview = converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
var stanza = new Strophe.Builder("stream:features", { registerview.$('input[name=domain]').val('conversejs.org');
'xmlns:stream': "http://etherx.jabber.org/streams", registerview.$('input[type=submit]').click();
'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
this.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Using xform data').up()
.c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
.c('instructions').t('xform instructions').up()
.c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
.c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('xform');
registerview.$('input[name=username]').val('testusername'); var stanza = new Strophe.Builder("stream:features", {
registerview.$('input[name=password]').val('testpassword'); 'xmlns:stream': "http://etherx.jabber.org/streams",
registerview.$('input[name=email]').val('test@email.local'); 'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Using xform data').up()
.c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
.c('instructions').t('xform instructions').up()
.c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
.c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('xform');
spyOn(converse.connection, 'send'); registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
registerview.$('input[type=submit]').click(); spyOn(converse.connection, 'send');
expect(converse.connection.send).toHaveBeenCalled(); registerview.$('input[type=submit]').click();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(1);
expect($stanza.children('query').children().children().length).toBe(3);
expect($stanza.children('query').children().children()[0].tagName).toBe('field');
}, converse));
}, converse, mock, test_utils)); expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(1);
expect($stanza.children('query').children().children().length).toBe(3);
expect($stanza.children('query').children().children()[0].tagName).toBe('field');
});
});
});
})); }));
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
}, },
'user': { 'user': {
'login': function (credentials) { 'login': function (credentials) {
converse.initConnection();
converse.logIn(credentials); converse.logIn(credentials);
}, },
'logout': function () { 'logout': function () {
......
...@@ -1620,7 +1620,8 @@ ...@@ -1620,7 +1620,8 @@
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged); return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
} else if (this.keepalive) { } else if (this.keepalive) {
if (!this.jid) { if (!this.jid) {
throw new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user."); throw new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, "+
"you must supply the JID of the current user.");
} }
try { try {
return this.connection.restore(this.jid, this.onConnectStatusChanged); return this.connection.restore(this.jid, this.onConnectStatusChanged);
...@@ -1629,7 +1630,7 @@ ...@@ -1629,7 +1630,7 @@
this.clearSession(); // If there's a roster, we want to clear it (see #555) this.clearSession(); // If there's a roster, we want to clear it (see #555)
} }
} else { } else {
throw new Error("initConnection: If you use prebind and not keepalive, "+ throw new Error("attemptPreboundSession: If you use prebind and not keepalive, "+
"then you MUST supply JID, RID and SID values"); "then you MUST supply JID, RID and SID values");
} }
// We haven't been able to attach yet. Let's see if there // We haven't been able to attach yet. Let's see if there
...@@ -1700,6 +1701,8 @@ ...@@ -1700,6 +1701,8 @@
this.logIn = function (credentials) { this.logIn = function (credentials) {
if (credentials) { if (credentials) {
// When credentials are passed in, they override prebinding
// or credentials fetching via HTTP
this.autoLogin(credentials); this.autoLogin(credentials);
} else { } else {
// We now try to resume or automatically set up a new session. // We now try to resume or automatically set up a new session.
...@@ -1713,22 +1716,18 @@ ...@@ -1713,22 +1716,18 @@
}; };
this.initConnection = function () { this.initConnection = function () {
if (this.connection && this.connection.connected) { if (this.connection) {
this.setUpXMLLogging(); return;
this.onConnected(); }
if (!this.bosh_service_url && ! this.websocket_url) {
throw new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && this.websocket_url) {
this.connection = new Strophe.Connection(this.websocket_url);
} else if (this.bosh_service_url) {
this.connection = new Strophe.Connection(this.bosh_service_url, {'keepalive': this.keepalive});
} else { } else {
if (!this.bosh_service_url && ! this.websocket_url) { throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified.");
throw new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && this.websocket_url) {
this.connection = new Strophe.Connection(this.websocket_url);
} else if (this.bosh_service_url) {
this.connection = new Strophe.Connection(this.bosh_service_url, {'keepalive': this.keepalive});
} else {
throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified.");
}
this.setUpXMLLogging();
this.logIn();
} }
}; };
...@@ -1753,6 +1752,8 @@ ...@@ -1753,6 +1752,8 @@
this.chatboxviews = new this.ChatBoxViews({model: this.chatboxes}); this.chatboxviews = new this.ChatBoxViews({model: this.chatboxes});
this.initSession(); this.initSession();
this.initConnection(); this.initConnection();
this.setUpXMLLogging();
this.logIn();
return this; return this;
}; };
......
...@@ -47,9 +47,13 @@ require([ ...@@ -47,9 +47,13 @@ require([
converse.initialize({ converse.initialize({
i18n: window.locales.en, i18n: window.locales.en,
auto_subscribe: false, auto_subscribe: false,
animate: false, bosh_service_url: 'localhost',
connection: mock.mock_connection, connection: mock.mock_connection,
animate: false,
no_trimming: true, no_trimming: true,
auto_login: true,
jid: 'dummy@localhost',
password: 'secret',
debug: false debug: false
}, function (converse) { }, function (converse) {
window.converse = converse; window.converse = converse;
...@@ -64,6 +68,7 @@ require([ ...@@ -64,6 +68,7 @@ require([
require([ require([
"console-runner", "console-runner",
"spec/converse", "spec/converse",
"spec/headline",
"spec/disco", "spec/disco",
"spec/protocol", "spec/protocol",
"spec/mam", "spec/mam",
...@@ -76,9 +81,8 @@ require([ ...@@ -76,9 +81,8 @@ require([
"spec/notification", "spec/notification",
"spec/profiling", "spec/profiling",
"spec/ping", "spec/ping",
"spec/headline",
"spec/register", "spec/register",
"spec/xmppstatus" "spec/xmppstatus",
], function () { ], function () {
// Make sure this callback is only called once. // Make sure this callback is only called once.
delete converse.callback; delete converse.callback;
......
...@@ -50,10 +50,6 @@ ...@@ -50,10 +50,6 @@
mock.mock_connection = function () { mock.mock_connection = function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests'); var c = new Strophe.Connection('jasmine tests');
c.authenticated = true;
c.connected = true;
c.mock = true;
c.jid = 'dummy@localhost/resource';
c.vcard = { c.vcard = {
'get': function (callback, jid) { 'get': function (callback, jid) {
var fullname; var fullname;
...@@ -71,8 +67,13 @@ ...@@ -71,8 +67,13 @@
callback(vcard.tree()); callback(vcard.tree());
} }
}; };
c._changeConnectStatus(Strophe.Status.CONNECTED); c._proto._connect = function () {
c.attach(c.jid); c.authenticated = true;
c.connected = true;
c.mock = true;
c.jid = 'dummy@localhost/resource';
c._changeConnectStatus(Strophe.Status.CONNECTED);
};
return c; return c;
}(); }();
return mock; return mock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment