2015-04-08 10:35:14 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jquery",
|
2016-11-30 13:18:58 +01:00
|
|
|
"converse-api",
|
2015-04-08 10:35:14 +02:00
|
|
|
"mock",
|
2016-11-30 13:18:58 +01:00
|
|
|
"test_utils"], factory);
|
|
|
|
} (this, function ($, converse_api, mock, test_utils) {
|
2015-04-08 19:51:33 +02:00
|
|
|
"use strict";
|
2016-03-16 12:16:32 +01:00
|
|
|
var Strophe = converse_api.env.Strophe;
|
2015-04-08 10:35:14 +02:00
|
|
|
var $iq = converse_api.env.$iq;
|
2015-04-08 19:51:33 +02:00
|
|
|
var $pres = converse_api.env.$pres;
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
converse_api.user.logout();
|
2016-11-03 11:01:09 +01:00
|
|
|
converse_api.listen.not();
|
2016-11-02 21:19:17 +01:00
|
|
|
test_utils.clearBrowserStorage();
|
|
|
|
});
|
2016-06-09 11:01:54 +02:00
|
|
|
|
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".
|
|
|
|
*/
|
2016-11-02 21:19:17 +01:00
|
|
|
it("Subscribe to contact, contact accepts and subscribes back", mock.initConverse(function (converse) {
|
2015-04-08 10:35:14 +02:00
|
|
|
/* The process by which a user subscribes to a contact, including
|
|
|
|
* the interaction between roster items and subscription states.
|
|
|
|
*/
|
2015-04-10 13:01:31 +02:00
|
|
|
var contact, stanza, sent_stanza, IQ_id;
|
2016-11-02 21:19:17 +01:00
|
|
|
runs(function () {
|
|
|
|
test_utils.openControlBox(converse);
|
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
|
|
|
var panel = converse.chatboxviews.get('controlbox').contactspanel;
|
2015-04-08 19:51:33 +02:00
|
|
|
spyOn(panel, "addContactFromForm").andCallThrough();
|
2016-11-02 21:19:17 +01:00
|
|
|
spyOn(converse.roster, "addAndSubscribe").andCallThrough();
|
|
|
|
spyOn(converse.roster, "addContact").andCallThrough();
|
|
|
|
spyOn(converse.roster, "sendContactAddIQ").andCallThrough();
|
|
|
|
spyOn(converse, "getVCard").andCallThrough();
|
|
|
|
var sendIQ = converse.connection.sendIQ;
|
|
|
|
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2015-04-10 13:01:31 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2015-04-08 19:51:33 +02:00
|
|
|
});
|
|
|
|
panel.delegateEvents(); // Rebind all events so that our spy gets called
|
|
|
|
|
|
|
|
/* Add a new contact through the UI */
|
|
|
|
var $form = panel.$('form.add-xmpp-contact');
|
|
|
|
expect($form.is(":visible")).toBeFalsy();
|
|
|
|
// Click the "Add a contact" link.
|
|
|
|
panel.$('.toggle-xmpp-contact-form').click();
|
|
|
|
// Check that the $form appears
|
|
|
|
expect($form.is(":visible")).toBeTruthy();
|
|
|
|
// Fill in the form and submit
|
|
|
|
$form.find('input').val('contact@example.org');
|
|
|
|
$form.submit();
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
expect($form.is(":visible")).toBeFalsy();
|
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
/* converse request consists of sending an IQ
|
2015-04-08 19:51:33 +02:00
|
|
|
* 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();
|
2015-04-10 13:01:31 +02:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2015-04-08 19:51:33 +02:00
|
|
|
"<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
|
2016-11-02 21:19:17 +01:00
|
|
|
* with converse user that have requested the roster, setting the
|
2015-04-08 19:51:33 +02:00
|
|
|
* '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;
|
2015-04-08 10:35:14 +02:00
|
|
|
spyOn(converse.connection, 'send').andCallFake(function (stanza) {
|
2015-04-10 13:01:31 +02:00
|
|
|
sent_stanza = stanza;
|
2015-04-08 10:35:14 +02:00
|
|
|
});
|
2015-04-08 19:51:33 +02:00
|
|
|
spyOn(converse.roster, 'create').andCallFake(function () {
|
|
|
|
contact = create.apply(converse.roster, arguments);
|
|
|
|
spyOn(contact, 'subscribe').andCallThrough();
|
|
|
|
return contact;
|
|
|
|
});
|
|
|
|
stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'none',
|
|
|
|
'name': 'contact@example.org'});
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-09 10:35:51 +02:00
|
|
|
/*
|
2015-04-08 19:51:33 +02:00
|
|
|
* <iq type='result' id='set1'/>
|
|
|
|
*/
|
2015-04-10 13:01:31 +02:00
|
|
|
stanza = $iq({'type': 'result', 'id':IQ_id});
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-08 19:51:33 +02:00
|
|
|
|
|
|
|
// A contact should now have been created
|
2016-11-02 21:19:17 +01:00
|
|
|
expect(converse.roster.get('contact@example.org') instanceof converse.RosterContact).toBeTruthy();
|
2015-04-08 19:51:33 +02:00
|
|
|
expect(contact.get('jid')).toBe('contact@example.org');
|
2016-11-02 21:19:17 +01:00
|
|
|
expect(converse.getVCard).toHaveBeenCalled();
|
2015-04-08 19:51:33 +02:00
|
|
|
|
|
|
|
/* 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'/>
|
|
|
|
*/
|
|
|
|
expect(contact.subscribe).toHaveBeenCalled();
|
2015-04-10 13:01:31 +02:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
2016-03-16 12:16:32 +01:00
|
|
|
"<presence to='contact@example.org' type='subscribe' xmlns='jabber:client'>"+
|
|
|
|
"<nick xmlns='http://jabber.org/protocol/nick'>Max Mustermann</nick>"+
|
|
|
|
"</presence>"
|
2015-04-08 19:51:33 +02:00
|
|
|
);
|
|
|
|
/* 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
|
2016-11-02 21:19:17 +01:00
|
|
|
* sub-state of the 'none' subscription state; converse pending
|
2015-04-08 19:51:33 +02:00
|
|
|
* 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").andCallThrough();
|
2015-11-04 18:57:44 +01:00
|
|
|
stanza = $iq({'type': 'set', 'from': 'dummy@localhost'})
|
|
|
|
.c('query', {'xmlns': 'jabber:iq:roster'})
|
2015-04-08 19:51:33 +02:00
|
|
|
.c('item', {
|
|
|
|
'jid': 'contact@example.org',
|
|
|
|
'subscription': 'none',
|
|
|
|
'ask': 'subscribe',
|
|
|
|
'name': 'contact@example.org'});
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-08 19:51:33 +02:00
|
|
|
expect(converse.roster.updateContact).toHaveBeenCalled();
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
2015-04-10 13:01:31 +02:00
|
|
|
waits(50);
|
2016-11-02 21:19:17 +01:00
|
|
|
runs(function () {
|
2015-04-08 19:51:33 +02:00
|
|
|
// Check that the user is now properly shown as a pending
|
|
|
|
// contact in the roster.
|
|
|
|
var $header = $('a:contains("Pending contacts")');
|
|
|
|
expect($header.length).toBe(1);
|
|
|
|
expect($header.is(":visible")).toBeTruthy();
|
|
|
|
var $contacts = $header.parent().nextUntil('dt', 'dd');
|
|
|
|
expect($contacts.length).toBe(1);
|
|
|
|
|
2015-04-10 13:01:31 +02:00
|
|
|
spyOn(contact, "ackSubscribe").andCallThrough();
|
2015-04-08 19:51:33 +02:00
|
|
|
/* Here we assume the "happy path" that the contact
|
2016-11-02 21:19:17 +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({
|
|
|
|
'to': converse.bare_jid,
|
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'subscribed'
|
|
|
|
});
|
2015-04-10 13:01:31 +02:00
|
|
|
sent_stanza = ""; // Reset
|
2016-11-02 21:19:17 +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",
|
2016-11-02 21:19:17 +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
|
2016-11-02 21:19:17 +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>
|
|
|
|
*/
|
2015-04-10 13:01:31 +02:00
|
|
|
IQ_id = converse.connection.getUniqueId('roster');
|
|
|
|
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-11-02 21:19:17 +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
|
|
|
);
|
|
|
|
expect(converse.roster.updateContact).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
$contacts = $header.parent().nextUntil('dt', 'dd');
|
|
|
|
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
|
2016-11-02 21:19:17 +01:00
|
|
|
* from='contact@example.org/resource'
|
|
|
|
* to='user@example.com/resource'/>
|
|
|
|
*/
|
2015-04-08 19:51:33 +02:00
|
|
|
stanza = $pres({'to': converse.bare_jid, 'from': 'contact@example.org/resource'});
|
2016-11-02 21:19:17 +01:00
|
|
|
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
|
2016-11-02 21:19:17 +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'/>
|
|
|
|
*/
|
2015-04-09 10:35:51 +02:00
|
|
|
spyOn(contact, 'authorize').andCallThrough();
|
2016-11-02 21:19:17 +01:00
|
|
|
spyOn(converse.roster, 'handleIncomingSubscription').andCallThrough();
|
2015-04-09 10:35:51 +02:00
|
|
|
stanza = $pres({
|
|
|
|
'to': converse.bare_jid,
|
|
|
|
'from': 'contact@example.org/resource',
|
|
|
|
'type': 'subscribe'});
|
2016-11-02 21:19:17 +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
|
2016-11-02 21:19:17 +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
|
2016-11-02 21:19:17 +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-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-09 10:35:51 +02:00
|
|
|
expect(converse.roster.updateContact).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// The class on the contact will now have switched.
|
|
|
|
expect($contacts.hasClass('to')).toBeFalsy();
|
|
|
|
expect($contacts.hasClass('both')).toBeTruthy();
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
2015-04-08 10:35:14 +02:00
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
it("Alternate Flow: Contact Declines Subscription Request", mock.initConverse(function (converse) {
|
2015-04-10 13:01:31 +02:00
|
|
|
/* The process by which a user subscribes to a contact, including
|
|
|
|
* the interaction between roster items and subscription states.
|
|
|
|
*/
|
2015-10-25 18:49:35 +01:00
|
|
|
var contact, stanza, sent_stanza, sent_IQ;
|
2016-11-02 21:19:17 +01:00
|
|
|
runs(function () {
|
|
|
|
test_utils.openControlBox(converse);
|
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
2015-04-10 13:01:31 +02:00
|
|
|
// 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'});
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
});
|
2015-04-10 13:01:31 +02:00
|
|
|
waits(50);
|
2016-11-02 21:19:17 +01:00
|
|
|
runs(function () {
|
2015-04-10 13:01:31 +02:00
|
|
|
// A pending contact should now exist.
|
2016-11-02 21:19:17 +01:00
|
|
|
contact = converse.roster.get('contact@example.org');
|
|
|
|
expect(converse.roster.get('contact@example.org') instanceof converse.RosterContact).toBeTruthy();
|
2015-04-10 13:01:31 +02:00
|
|
|
spyOn(contact, "ackUnsubscribe").andCallThrough();
|
2015-04-08 10:35:14 +02:00
|
|
|
|
2015-04-10 13:01:31 +02:00
|
|
|
spyOn(converse.connection, 'send').andCallFake(function (stanza) {
|
|
|
|
sent_stanza = stanza;
|
|
|
|
});
|
2016-11-02 21:19:17 +01:00
|
|
|
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2015-04-10 13:01:31 +02:00
|
|
|
sent_IQ = iq;
|
|
|
|
});
|
|
|
|
/* We now assume the contact declines the subscription
|
2016-11-02 21:19:17 +01:00
|
|
|
* requests.
|
|
|
|
*
|
2015-04-10 13:01:31 +02:00
|
|
|
/* Upon receiving the presence stanza of type "unsubscribed"
|
2016-11-02 21:19:17 +01:00
|
|
|
* 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>
|
|
|
|
*/
|
2015-04-10 16:30:04 +02:00
|
|
|
// FIXME: also add the <iq>
|
2015-04-10 13:01:31 +02:00
|
|
|
stanza = $pres({
|
|
|
|
'to': converse.bare_jid,
|
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'unsubscribed'
|
|
|
|
});
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-10 13:01:31 +02:00
|
|
|
|
|
|
|
/* Upon receiving the presence stanza of type "unsubscribed",
|
2016-11-02 21:19:17 +01:00
|
|
|
* the user SHOULD acknowledge receipt of that subscription
|
|
|
|
* state notification through either "affirming" it by
|
|
|
|
* sending a presence stanza of type "unsubscribe
|
|
|
|
*/
|
2015-04-10 13: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
|
|
|
|
2015-04-10 13:01:31 +02:00
|
|
|
/* Converse.js will then also automatically remove the
|
2016-11-02 21:19:17 +01:00
|
|
|
* contact from the user's roster.
|
|
|
|
*/
|
2015-04-10 13: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>"
|
|
|
|
);
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
it("Unsubscribe to a contact when subscription is mutual", mock.initConverse(function (converse) {
|
2015-04-10 16:30:04 +02:00
|
|
|
var sent_IQ, IQ_id, jid = 'annegreet.gomez@localhost';
|
|
|
|
runs(function () {
|
2016-11-02 21:19:17 +01:00
|
|
|
test_utils.openControlBox(converse);
|
|
|
|
test_utils.createContacts(converse, 'current');
|
2015-04-10 16:30:04 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
|
|
|
// We now have a contact we want to remove
|
2016-11-02 21:19:17 +01:00
|
|
|
expect(converse.roster.get(jid) instanceof converse.RosterContact).toBeTruthy();
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
var sendIQ = converse.connection.sendIQ;
|
|
|
|
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2015-04-10 16:30:04 +02:00
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
|
|
|
|
var $header = $('a:contains("My contacts")');
|
|
|
|
// remove the first user
|
|
|
|
$($header.parent().nextUntil('dt', 'dd').find('.remove-xmpp-contact').get(0)).click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
/* Section 8.6 Removing a Roster Item and Cancelling All
|
2016-11-02 21:19:17 +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-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-04-10 16:30:04 +02:00
|
|
|
// Our contact has now been removed
|
2016-11-02 21:19:17 +01:00
|
|
|
expect(typeof converse.roster.get(jid) === "undefined").toBeTruthy();
|
|
|
|
});
|
|
|
|
}));
|
2015-04-10 16:30:04 +02:00
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
it("Receiving a subscription request", mock.initConverse(function (converse) {
|
2015-04-10 16:30:04 +02:00
|
|
|
runs(function () {
|
2016-11-02 21:19:17 +01:00
|
|
|
test_utils.openControlBox(converse);
|
|
|
|
test_utils.createContacts(converse, 'current'); // Create some contacts so that we can test positioning
|
2015-04-10 16:30:04 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
2016-03-01 22:57:27 +01:00
|
|
|
spyOn(converse, "emit");
|
2016-11-02 21:19:17 +01:00
|
|
|
/* <presence
|
2016-03-16 12:16:32 +01:00
|
|
|
* from='user@example.com'
|
|
|
|
* to='contact@example.org'
|
|
|
|
* type='subscribe'/>
|
|
|
|
*/
|
2015-04-10 16:30:04 +02:00
|
|
|
var stanza = $pres({
|
|
|
|
'to': converse.bare_jid,
|
|
|
|
'from': 'contact@example.org',
|
|
|
|
'type': 'subscribe'
|
2016-03-16 12:16:32 +01:00
|
|
|
}).c('nick', {
|
|
|
|
'xmlns': Strophe.NS.NICK,
|
|
|
|
}).t('Clint Contact');
|
2016-11-02 21:19:17 +01:00
|
|
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-03-01 22:57:27 +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();
|
|
|
|
var $contacts = $header.parent().nextUntil('dt', 'dd');
|
|
|
|
expect($contacts.length).toBe(1);
|
2016-11-02 21:19:17 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2015-04-08 10:35:14 +02:00
|
|
|
}));
|