2015-04-08 10:35:14 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2017-06-19 11:08:57 +02:00
|
|
|
"jasmine",
|
2015-04-08 10:35:14 +02:00
|
|
|
"jquery",
|
2017-02-14 15:08:39 +01:00
|
|
|
"converse-core",
|
2015-04-08 10:35:14 +02:00
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
"test-utils"], factory);
|
2017-06-19 11:08:57 +02:00
|
|
|
} (this, function (jasmine, $, converse, mock, test_utils) {
|
2015-04-08 19:51:33 +02:00
|
|
|
"use strict";
|
2016-12-20 10:30:20 +01:00
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var $iq = converse.env.$iq;
|
|
|
|
var $pres = converse.env.$pres;
|
2017-07-11 10:41:11 +02:00
|
|
|
var _ = converse.env._;
|
2015-04-08 19:51:33 +02:00
|
|
|
// See:
|
|
|
|
// https://xmpp.org/rfcs/rfc3921.html
|
2015-04-08 10:35:14 +02:00
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
describe("The Protocol", function () {
|
|
|
|
|
|
|
|
describe("Integration of Roster Items and Presence Subscriptions", function () {
|
|
|
|
// Stub the trimChat method. It causes havoc when running with
|
|
|
|
// phantomJS.
|
|
|
|
|
2015-04-08 10:35:14 +02:00
|
|
|
/* Some level of integration between roster items and presence
|
2017-01-31 22:21:59 +01:00
|
|
|
* subscriptions is normally expected by an instant messaging user
|
|
|
|
* regarding the user's subscriptions to and from other contacts. This
|
|
|
|
* section describes the level of integration that MUST be supported
|
|
|
|
* within an XMPP instant messaging applications.
|
|
|
|
*
|
|
|
|
* There are four primary subscription states:
|
|
|
|
*
|
|
|
|
* None -- the user does not have a subscription to the contact's
|
|
|
|
* presence information, and the contact does not have a subscription
|
|
|
|
* to the user's presence information
|
|
|
|
* To -- the user has a subscription to the contact's presence
|
|
|
|
* information, but the contact does not have a subscription to the
|
|
|
|
* user's presence information
|
|
|
|
* From -- the contact has a subscription to the user's presence
|
|
|
|
* information, but the user does not have a subscription to the
|
|
|
|
* contact's presence information
|
|
|
|
* Both -- both the user and the contact have subscriptions to each
|
|
|
|
* other's presence information (i.e., the union of 'from' and 'to')
|
|
|
|
*
|
|
|
|
* Each of these states is reflected in the roster of both the user and
|
|
|
|
* the contact, thus resulting in durable subscription states.
|
|
|
|
*
|
|
|
|
* The 'from' and 'to' addresses are OPTIONAL in roster pushes; if
|
|
|
|
* included, their values SHOULD be the full JID of the resource for
|
|
|
|
* that session. A client MUST acknowledge each roster push with an IQ
|
|
|
|
* stanza of type "result".
|
|
|
|
*/
|
2017-07-11 10:41:11 +02:00
|
|
|
it("Subscribe to contact, contact accepts and subscribes back",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'],
|
|
|
|
{ roster_groups: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
var contact, sent_stanza, IQ_id, stanza;
|
|
|
|
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
|
|
|
|
.then(function () {
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return _converse.xmppstatus.get('fullname');
|
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
/* The process by which a user subscribes to a contact, including
|
|
|
|
* the interaction between roster items and subscription states.
|
|
|
|
*/
|
|
|
|
test_utils.openControlBox(_converse);
|
|
|
|
var panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
|
|
|
spyOn(panel, "addContactFromForm").and.callThrough();
|
|
|
|
spyOn(_converse.roster, "addAndSubscribe").and.callThrough();
|
|
|
|
spyOn(_converse.roster, "addContact").and.callThrough();
|
|
|
|
spyOn(_converse.roster, "sendContactAddIQ").and.callThrough();
|
|
|
|
spyOn(_converse.api.vcard, "get").and.callThrough();
|
|
|
|
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
panel.delegateEvents(); // Rebind all events so that our spy gets called
|
2015-04-08 19:51:33 +02:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
/* Add a new contact through the UI */
|
|
|
|
var form = panel.el.querySelector('form.add-xmpp-contact');
|
|
|
|
expect(_.isNull(form)).toBeTruthy();
|
2015-04-08 19:51:33 +02:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
// Click the "Add a contact" link.
|
|
|
|
panel.$('.toggle-xmpp-contact-form').click();
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
// Check that the form appears
|
|
|
|
form = panel.el.querySelector('form.add-xmpp-contact');
|
|
|
|
expect(form.parentElement.offsetHeight).not.toBe(0);
|
|
|
|
expect(_.includes(form.parentElement.classList, 'collapsed')).toBeFalsy();
|
|
|
|
|
|
|
|
// Fill in the form and submit
|
|
|
|
$(form).find('input').val('contact@example.org');
|
|
|
|
$(form).submit();
|
2017-07-19 09:10:17 +02:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
/* In preparation for being able to render the contact in the
|
|
|
|
* user's client interface and for the server to keep track of the
|
|
|
|
* subscription, the user's client SHOULD perform a "roster set"
|
|
|
|
* for the new roster item.
|
|
|
|
*/
|
|
|
|
expect(panel.addContactFromForm).toHaveBeenCalled();
|
|
|
|
expect(_converse.roster.addAndSubscribe).toHaveBeenCalled();
|
|
|
|
expect(_converse.roster.addContact).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// The form should not be visible anymore (by virtue of its
|
|
|
|
// parent being collapsed)
|
|
|
|
expect(form.parentElement.offsetHeight).toBe(0);
|
|
|
|
expect(_.includes(form.parentElement.classList, 'collapsed')).toBeTrue;
|
|
|
|
|
|
|
|
/* _converse request consists of sending an IQ
|
|
|
|
* stanza of type='set' containing a <query/> element qualified by
|
|
|
|
* the 'jabber:iq:roster' namespace, which in turn contains an
|
|
|
|
* <item/> element that defines the new roster item; the <item/>
|
|
|
|
* element MUST possess a 'jid' attribute, MAY possess a 'name'
|
|
|
|
* attribute, MUST NOT possess a 'subscription' attribute, and MAY
|
|
|
|
* contain one or more <group/> child elements:
|
|
|
|
*
|
|
|
|
* <iq type='set' id='set1'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='jabber:iq:roster'>"+
|
|
|
|
"<item jid='contact@example.org' name='contact@example.org'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
/* As a result, the user's server (1) MUST initiate a roster push
|
|
|
|
* for the new roster item to all available resources associated
|
|
|
|
* with _converse user that have requested the roster, setting the
|
|
|
|
* 'subscription' attribute to a value of "none"; and (2) MUST
|
|
|
|
* reply to the sending resource with an IQ result indicating the
|
|
|
|
* success of the roster set:
|
|
|
|
*
|
|
|
|
* <iq type='set'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* subscription='none'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var create = _converse.roster.create;
|
|
|
|
var sent_stanzas = [];
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
|
|
sent_stanza = stanza;
|
|
|
|
sent_stanzas.push(stanza.toLocaleString());
|
|
|
|
});
|
|
|
|
spyOn(_converse.roster, 'create').and.callFake(function () {
|
|
|
|
contact = create.apply(_converse.roster, arguments);
|
|
|
|
spyOn(contact, 'subscribe').and.callThrough();
|
|
|
|
return contact;
|
|
|
|
});
|
|
|
|
stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'none',
|
|
|
|
'name': 'contact@example.org'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
/*
|
|
|
|
* <iq type='result' id='set1'/>
|
|
|
|
*/
|
|
|
|
stanza = $iq({'type': 'result', 'id':IQ_id});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
// A contact should now have been created
|
|
|
|
expect(_converse.roster.get('contact@example.org') instanceof _converse.RosterContact).toBeTruthy();
|
|
|
|
expect(contact.get('jid')).toBe('contact@example.org');
|
|
|
|
expect(_converse.api.vcard.get).toHaveBeenCalled();
|
|
|
|
|
|
|
|
/* To subscribe to the contact's presence information,
|
|
|
|
* the user's client MUST send a presence stanza of
|
|
|
|
* type='subscribe' to the contact:
|
|
|
|
*
|
|
|
|
* <presence to='contact@example.org' type='subscribe'/>
|
|
|
|
*/
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return sent_stanzas.length == 1;
|
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
expect(contact.subscribe).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
|
|
|
"<presence to='contact@example.org' type='subscribe' xmlns='jabber:client'>"+
|
|
|
|
"<nick xmlns='http://jabber.org/protocol/nick'>Max Mustermann</nick>"+
|
|
|
|
"</presence>"
|
|
|
|
);
|
|
|
|
/* As a result, the user's server MUST initiate a second roster
|
|
|
|
* push to all of the user's available resources that have
|
|
|
|
* requested the roster, setting the contact to the pending
|
|
|
|
* sub-state of the 'none' subscription state; _converse pending
|
|
|
|
* sub-state is denoted by the inclusion of the ask='subscribe'
|
|
|
|
* attribute in the roster item:
|
|
|
|
*
|
|
|
|
* <iq type='set'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* subscription='none'
|
|
|
|
* ask='subscribe'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
spyOn(_converse.roster, "updateContact").and.callThrough();
|
|
|
|
stanza = $iq({'type': 'set', 'from': 'dummy@localhost'})
|
|
|
|
.c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'none',
|
|
|
|
'ask': 'subscribe',
|
|
|
|
'name': 'contact@example.org'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(_converse.roster.updateContact).toHaveBeenCalled();
|
|
|
|
// Check that the user is now properly shown as a pending
|
|
|
|
// contact in the roster.
|
|
|
|
|
2017-12-17 16:03:28 +01:00
|
|
|
var $header = $('a:contains("Pending contacts")');
|
2017-12-03 12:21:57 +01:00
|
|
|
return test_utils.waitUntil(function () {
|
2017-12-17 16:03:28 +01:00
|
|
|
return $('a:contains("Pending contacts")').length && $header.is(":visible");
|
2017-12-03 12:21:57 +01:00
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
2015-04-08 19:51:33 +02:00
|
|
|
var $header = $('a:contains("Pending contacts")');
|
2017-12-17 16:03:28 +01:00
|
|
|
var $contacts = $header.parent().find('li');
|
2015-04-08 19:51:33 +02:00
|
|
|
expect($contacts.length).toBe(1);
|
2017-12-17 16:03:28 +01:00
|
|
|
expect($contacts.is(':visible')).toBeTruthy();
|
2015-04-08 19:51:33 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(contact, "ackSubscribe").and.callThrough();
|
2015-04-08 19:51:33 +02:00
|
|
|
/* Here we assume the "happy path" that the contact
|
2017-12-03 12:21:57 +01:00
|
|
|
* approves the subscription request
|
|
|
|
*
|
|
|
|
* <presence
|
|
|
|
* to='user@example.com'
|
|
|
|
* from='contact@example.org'
|
|
|
|
* type='subscribed'/>
|
|
|
|
*/
|
2015-04-08 19:51:33 +02:00
|
|
|
stanza = $pres({
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.bare_jid,
|
2015-04-08 19:51:33 +02:00
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'subscribed'
|
|
|
|
});
|
2015-04-10 13:01:31 +02:00
|
|
|
sent_stanza = ""; // Reset
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-08 19:51:33 +02:00
|
|
|
/* Upon receiving the presence stanza of type "subscribed",
|
2017-12-03 12:21:57 +01:00
|
|
|
* the user SHOULD acknowledge receipt of that
|
|
|
|
* subscription state notification by sending a presence
|
|
|
|
* stanza of type "subscribe".
|
|
|
|
*/
|
2015-04-10 13:01:31 +02:00
|
|
|
expect(contact.ackSubscribe).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
2015-04-08 19:51:33 +02:00
|
|
|
"<presence type='subscribe' to='contact@example.org' xmlns='jabber:client'/>"
|
|
|
|
);
|
|
|
|
|
|
|
|
/* The user's server MUST initiate a roster push to all of the user's
|
2017-12-03 12:21:57 +01:00
|
|
|
* available resources that have requested the roster,
|
|
|
|
* containing an updated roster item for the contact with
|
|
|
|
* the 'subscription' attribute set to a value of "to";
|
|
|
|
*
|
|
|
|
* <iq type='set'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* subscription='to'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2016-12-20 10:30:20 +01:00
|
|
|
IQ_id = _converse.connection.getUniqueId('roster');
|
2015-04-10 13:01:31 +02:00
|
|
|
stanza = $iq({'type': 'set', 'id': IQ_id})
|
2015-04-08 19:51:33 +02:00
|
|
|
.c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'to',
|
|
|
|
'name': 'contact@example.org'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-08 19:51:33 +02:00
|
|
|
// Check that the IQ set was acknowledged.
|
2015-04-10 13:01:31 +02:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
|
|
|
"<iq type='result' id='"+IQ_id+"' from='dummy@localhost/resource' xmlns='jabber:client'/>"
|
2015-04-08 19:51:33 +02:00
|
|
|
);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.roster.updateContact).toHaveBeenCalled();
|
2015-04-08 19:51:33 +02:00
|
|
|
|
|
|
|
// The contact should now be visible as an existing
|
|
|
|
// contact (but still offline).
|
|
|
|
$header = $('a:contains("My contacts")');
|
|
|
|
expect($header.length).toBe(1);
|
|
|
|
expect($header.is(":visible")).toBeTruthy();
|
2017-12-17 16:03:28 +01:00
|
|
|
$contacts = $header.parent().find('li');
|
2015-04-08 19:51:33 +02:00
|
|
|
expect($contacts.length).toBe(1);
|
|
|
|
// Check that it has the right classes and text
|
|
|
|
expect($contacts.hasClass('to')).toBeTruthy();
|
2015-04-09 10:35:51 +02:00
|
|
|
expect($contacts.hasClass('both')).toBeFalsy();
|
2015-04-08 19:51:33 +02:00
|
|
|
expect($contacts.hasClass('current-xmpp-contact')).toBeTruthy();
|
|
|
|
expect($contacts.text().trim()).toBe('Contact');
|
|
|
|
expect(contact.get('chat_status')).toBe('offline');
|
|
|
|
|
|
|
|
/* <presence
|
2017-12-03 12:21:57 +01:00
|
|
|
* from='contact@example.org/resource'
|
|
|
|
* to='user@example.com/resource'/>
|
|
|
|
*/
|
2016-12-20 10:30:20 +01:00
|
|
|
stanza = $pres({'to': _converse.bare_jid, 'from': 'contact@example.org/resource'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-08 19:51:33 +02:00
|
|
|
// Now the contact should also be online.
|
|
|
|
expect(contact.get('chat_status')).toBe('online');
|
|
|
|
|
|
|
|
/* Section 8.3. Creating a Mutual Subscription
|
2017-12-03 12:21:57 +01:00
|
|
|
*
|
|
|
|
* If the contact wants to create a mutual subscription,
|
|
|
|
* the contact MUST send a subscription request to the
|
|
|
|
* user.
|
|
|
|
*
|
|
|
|
* <presence from='contact@example.org' to='user@example.com' type='subscribe'/>
|
|
|
|
*/
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(contact, 'authorize').and.callThrough();
|
|
|
|
spyOn(_converse.roster, 'handleIncomingSubscription').and.callThrough();
|
2015-04-09 10:35:51 +02:00
|
|
|
stanza = $pres({
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.bare_jid,
|
2015-04-09 10:35:51 +02:00
|
|
|
'from': 'contact@example.org/resource',
|
|
|
|
'type': 'subscribe'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(_converse.roster.handleIncomingSubscription).toHaveBeenCalled();
|
2015-04-08 19:51:33 +02:00
|
|
|
|
|
|
|
/* The user's client MUST send a presence stanza of type
|
2017-12-03 12:21:57 +01:00
|
|
|
* "subscribed" to the contact in order to approve the
|
|
|
|
* subscription request.
|
|
|
|
*
|
|
|
|
* <presence to='contact@example.org' type='subscribed'/>
|
|
|
|
*/
|
2015-04-09 10:35:51 +02:00
|
|
|
expect(contact.authorize).toHaveBeenCalled();
|
2015-04-10 13:01:31 +02:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
2015-04-09 10:35:51 +02:00
|
|
|
"<presence to='contact@example.org' type='subscribed' xmlns='jabber:client'/>"
|
|
|
|
);
|
|
|
|
|
|
|
|
/* As a result, the user's server MUST initiate a
|
2017-12-03 12:21:57 +01:00
|
|
|
* roster push containing a roster item for the
|
|
|
|
* contact with the 'subscription' attribute set to
|
|
|
|
* a value of "both".
|
|
|
|
*
|
|
|
|
* <iq type='set'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* subscription='both'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2015-04-09 10:35:51 +02:00
|
|
|
stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'both',
|
|
|
|
'name': 'contact@example.org'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(_converse.roster.updateContact).toHaveBeenCalled();
|
2015-04-09 10:35:51 +02:00
|
|
|
|
|
|
|
// The class on the contact will now have switched.
|
|
|
|
expect($contacts.hasClass('to')).toBeFalsy();
|
|
|
|
expect($contacts.hasClass('both')).toBeTruthy();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
2015-04-08 10:35:14 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("Alternate Flow: Contact Declines Subscription Request",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2015-04-10 13:01:31 +02:00
|
|
|
/* The process by which a user subscribes to a contact, including
|
2017-12-03 12:21:57 +01:00
|
|
|
* the interaction between roster items and subscription states.
|
|
|
|
*/
|
2015-10-25 18:49:35 +01:00
|
|
|
var contact, stanza, sent_stanza, sent_IQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
|
|
|
// Add a new roster contact via roster push
|
|
|
|
stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'none',
|
|
|
|
'ask': 'subscribe',
|
|
|
|
'name': 'contact@example.org'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
// A pending contact should now exist.
|
|
|
|
contact = _converse.roster.get('contact@example.org');
|
|
|
|
expect(_converse.roster.get('contact@example.org') instanceof _converse.RosterContact).toBeTruthy();
|
|
|
|
spyOn(contact, "ackUnsubscribe").and.callThrough();
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
|
|
sent_stanza = stanza;
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
/* We now assume the contact declines the subscription
|
2017-12-03 12:21:57 +01:00
|
|
|
* requests.
|
|
|
|
*
|
|
|
|
* Upon receiving the presence stanza of type "unsubscribed"
|
|
|
|
* addressed to the user, the user's server (1) MUST deliver
|
|
|
|
* that presence stanza to the user and (2) MUST initiate a
|
|
|
|
* roster push to all of the user's available resources that
|
|
|
|
* have requested the roster, containing an updated roster
|
|
|
|
* item for the contact with the 'subscription' attribute
|
|
|
|
* set to a value of "none" and with no 'ask' attribute:
|
|
|
|
*
|
|
|
|
* <presence
|
|
|
|
* from='contact@example.org'
|
|
|
|
* to='user@example.com'
|
|
|
|
* type='unsubscribed'/>
|
|
|
|
*
|
|
|
|
* <iq type='set'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item
|
|
|
|
* jid='contact@example.org'
|
|
|
|
* subscription='none'
|
|
|
|
* name='MyContact'>
|
|
|
|
* <group>MyBuddies</group>
|
|
|
|
* </item>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2017-04-05 11:01:31 +02:00
|
|
|
// FIXME: also add the <iq>
|
|
|
|
stanza = $pres({
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'unsubscribed'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-10 13:01:31 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
/* Upon receiving the presence stanza of type "unsubscribed",
|
2017-12-03 12:21:57 +01:00
|
|
|
* the user SHOULD acknowledge receipt of that subscription
|
|
|
|
* state notification through either "affirming" it by
|
|
|
|
* sending a presence stanza of type "unsubscribe
|
|
|
|
*/
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(contact.ackUnsubscribe).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<presence type='unsubscribe' to='contact@example.org' xmlns='jabber:client'/>"
|
|
|
|
);
|
2015-04-08 10:35:14 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
/* _converse.js will then also automatically remove the
|
2017-12-03 12:21:57 +01:00
|
|
|
* contact from the user's roster.
|
|
|
|
*/
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client'>"+
|
|
|
|
"<query xmlns='jabber:iq:roster'>"+
|
|
|
|
"<item jid='contact@example.org' subscription='remove'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-02 21:19:17 +01:00
|
|
|
}));
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("Unsubscribe to a contact when subscription is mutual",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'],
|
|
|
|
{ roster_groups: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2015-04-10 16:30:04 +02:00
|
|
|
var sent_IQ, IQ_id, jid = 'annegreet.gomez@localhost';
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
// We now have a contact we want to remove
|
|
|
|
expect(_converse.roster.get(jid) instanceof _converse.RosterContact).toBeTruthy();
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return $('a:contains("My contacts")').length;
|
|
|
|
}).then(function () {
|
2015-04-10 16:30:04 +02:00
|
|
|
var $header = $('a:contains("My contacts")');
|
|
|
|
// remove the first user
|
2017-12-17 16:03:28 +01:00
|
|
|
$($header.parent().find('li .remove-xmpp-contact').get(0)).click();
|
2015-04-10 16:30:04 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
/* Section 8.6 Removing a Roster Item and Cancelling All
|
2017-12-03 12:21:57 +01:00
|
|
|
* Subscriptions
|
|
|
|
*
|
|
|
|
* First the user is removed from the roster
|
|
|
|
* Because there may be many steps involved in completely
|
|
|
|
* removing a roster item and cancelling subscriptions in
|
|
|
|
* both directions, the roster management protocol includes
|
|
|
|
* a "shortcut" method for doing so. The process may be
|
|
|
|
* initiated no matter what the current subscription state
|
|
|
|
* is by sending a roster set containing an item for the
|
|
|
|
* contact with the 'subscription' attribute set to a value
|
|
|
|
* of "remove":
|
|
|
|
*
|
|
|
|
* <iq type='set' id='remove1'>
|
|
|
|
* <query xmlns='jabber:iq:roster'>
|
|
|
|
* <item jid='contact@example.org' subscription='remove'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2015-04-10 16:30:04 +02:00
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='jabber:iq:roster'>"+
|
|
|
|
"<item jid='annegreet.gomez@localhost' subscription='remove'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
// Receive confirmation from the contact's server
|
|
|
|
// <iq type='result' id='remove1'/>
|
|
|
|
var stanza = $iq({'type': 'result', 'id':IQ_id});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-10 16:30:04 +02:00
|
|
|
// Our contact has now been removed
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(typeof _converse.roster.get(jid) === "undefined").toBeTruthy();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("Receiving a subscription request", mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-02 18:00:18 +01:00
|
|
|
spyOn(_converse, "emit");
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
|
|
|
test_utils.createContacts(_converse, 'current'); // Create some contacts so that we can test positioning
|
|
|
|
/* <presence
|
|
|
|
* from='user@example.com'
|
|
|
|
* to='contact@example.org'
|
|
|
|
* type='subscribe'/>
|
|
|
|
*/
|
|
|
|
var stanza = $pres({
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'subscribe'
|
|
|
|
}).c('nick', {
|
|
|
|
'xmlns': Strophe.NS.NICK,
|
|
|
|
}).t('Clint Contact');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return $('a:contains("Contact requests")').length;
|
|
|
|
}).then(function () {
|
2017-12-02 18:00:18 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('contactRequest', jasmine.any(Object));
|
2015-04-10 16:30:04 +02:00
|
|
|
var $header = $('a:contains("Contact requests")');
|
|
|
|
expect($header.length).toBe(1);
|
|
|
|
expect($header.is(":visible")).toBeTruthy();
|
2017-12-17 16:03:28 +01:00
|
|
|
var $contacts = $header.parent().find('li');
|
2015-04-10 16:30:04 +02:00
|
|
|
expect($contacts.length).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2015-04-08 10:35:14 +02:00
|
|
|
}));
|