Пример #1
0
app.post('/v1/mock/when/equals', (req, res) => {
  var expected = xml.parse(req.body.expected)
  var result = xml.parse(req.body.result)
  console.log(`Mocking xmpp stanza(ignoring stanza id):\n${JSON.stringify(expected)}\nresult will be\n${JSON.stringify(result)}\n`)

  xmppMock.addExpectationV1(expected, result)

  res.status(200).end()
})
Пример #2
0
exports.settingsToJSON = function(reply) {

  var replyEl = ltx.parse(reply.toString());

  var allSettings = replyEl.getChild('query')
      .getChildren('notificationSettings', settingsNs);
  var allSettingsJSON = []

  for (var i = 0; i < allSettings.length; i++) {
    var settings = allSettings[i];

    var target = settings.getChild('target');
    var postAfterMe = settings.getChild("postAfterMe");
    var postMentionedMe = settings.getChild("postMentionedMe");
    var postOnMyChannel = settings.getChild("postOnMyChannel");
    var postOnSubscribedChannel = settings.getChild("postOnSubscribedChannel");
    var followMyChannel = settings.getChild("followMyChannel");
    var followRequest = settings.get("followRequest");

    jsonItem = {
      target : target ? target.getText() : null,
      postAfterMe : postAfterMe ? postAfterMe.getText() : null,
      postMentionedMe : postMentionedMe ? postMentionedMe.getText() : null,
      postOnMyChannel : postOnMyChannel ? postOnMyChannel.getText() : null,
      postOnSubscribedChannel : postOnSubscribedChannel ? postOnSubscribedChannel.getText() : null,
      followMyChannel : followMyChannel ? followMyChannel.getText() : null,
      followRequest : followRequest ? followRequest.getText() : null
    };

    allSettingsJSON.push(jsonItem);
  }

  return allSettingsJSON;
}
Пример #3
0
        client.on('stanza', function(stz) {
            var query = null;
            var stanza = ltx.parse(stz.toString());
            if (stanza.is('iq') && (query = stanza.getChild('query', "jabber:iq:version"))) {
                stanza.attrs.type = "result";
                stanza.attrs.to = stanza.attrs.from;
                delete stanza.attrs.from;

                // Actual version attributes
                if(typeof(config.name) === "undefined") {
                    query.c("name").t(defaults.name);
                }
                else {
                    query.c("name").t(config.name);
                }

                if(typeof(config.version) === "undefined") {
                    query.c("version").t(defaults.version);
                }
                else {
                    query.c("version").t(config.version);
                }

                if(typeof(config.os) === "undefined") {
                    query.c("os").t(defaults.os);
                }
                else {
                    query.c("os").t(config.os);
                }
                client.send(stanza);
            }
        });
Пример #4
0
    xmppMock.getReceived('iq', (err, docs) => {
      if (err) {
        res.status(500).send(err).end()
        return
      }

      if (childToFilter) {
        var filtered = []
        for (var doc of docs) {
          let stanza = doc.xml

          console.log(stanza)
          var xmlst = xml.parse(stanza)
          console.log(xmlst)

          let found = xmlst.children.find(function (child) {
              return (!childXmlns || child.attrs[ 'xmlns' ] === childXmlns) && child.name === childToFilter
            }
          )
          console.log('found: ' + found)

          if (found) {
            filtered.push(doc)
          }
        }
        res.json(filtered).end()
      } else {
        res.json(docs).end()
      }
    })
      it('Precondition: Create and configure node', function (done) {

        var id = 'newnode-r2d2';
        var config = ltx.parse("<x xmlns='jabber:x:data' type='submit'><field var='pubsub#deliver_payloads'><value>0</value></field></x>");

        var stanza = new ltx.Element('iq', {
          to: 'pubsub.example.net',
          from: helper.userRomeo.jid,
          type: 'set',
          id: id
        }).c('pubsub', {
          'xmlns': 'http://jabber.org/protocol/pubsub'
        }).c('create', {
          'node': 'config_node'
        }).up().c('configure').cnode(config);

        helper.sendMessageWithRomeo(stanza.root()).then(function (stanza) {
          try {
            assert.equal(stanza.is('iq'), true, 'wrong stanza ' + stanza.root().toString());
            assert.equal(stanza.attrs.type, 'result');
            assert.equal(stanza.attrs.id, id);
            done();
          } catch (err) {
            done(err);
          }
        }).catch(function (err) {
          done(err);
        });
      });
Пример #6
0
        function(err, res, body) {
            that.currentRequests--

            if (err) {
                if (retry < that.maxHTTPRetries) {
                    return that.request(attrs, children, cb, retry + 1)
                } else {
                    return cb(err)
                }
            }
            if ((res.statusCode < 200) || (res.statusCode >= 400)) {
                return cb(new Error('HTTP status ' + res.statusCode))
            }

            var bodyEl
            try {
                bodyEl = ltx.parse(body)
            } catch(e) {
                return cb(e)
            }

            if (bodyEl && (bodyEl.attrs.type === 'terminate')) {
                cb(new Error(bodyEl.attrs.condition))
            } else if (bodyEl) {
                cb(null, bodyEl)
            } else {
                cb(new Error('no <body/>'))
            }
        }
 it('https://github.com/xmpp-ftw/xmpp-ftw-buddycloud/issues/25', function(done) {
     var stanza = ltx.parse('' +
         '<message from="channels.surevine.net"  ' +
              'to="lloyd.watkin@surevine.net/6daf60a8-eb12-4b18-b1fe-d93d64eadab0">' +
             '<event xmlns="http://jabber.org/protocol/pubsub#event">' +
                  '<subscription node="/user/invites@surevine.net/posts" ' +
                     'jid="*****@*****.**" subscription="invited" ' +
                     'invited-by="*****@*****.**" />' +
             '</event>' +
         '</message>'
     )
     socket.once('xmpp.buddycloud.push.subscription', function(data) {
         should.not.exist(data.from)
         data.node.should.equal('/user/invites@surevine.net/posts')
         data.subscription.should.equal('invited')
         data.invitedBy.should.eql({
             domain: 'surevine.net',
             user: '******'
         })
         data.jid.should.eql({
             domain: 'surevine.com',
             user: '******'
         })
         done()
     })
     buddycloud.channelServer = 'channels.surevine.net'
     buddycloud.handles(stanza).should.be.true
     buddycloud.handle(stanza).should.be.true
     
 })
Пример #8
0
exports.extractEntries = function(iq) {
  var rootEl = ltx.parse(iq.toString());
  return rootEl.getChildrenByFilter(function (c) {
    return typeof c != 'string' && 
      c.getName() == 'entry' && c.getNS() == atom.ns; 
  }, true);
}
Пример #9
0
PrivacyLists.prototype.handle = function (stanza) {

  var error = ltx.parse('<error type=\'cancel\'><item-not-found xmlns=\'urn:ietf:params:xml:ns:xmpp-stanzas\'/></error>'); // jshint ignore:line
  this.sendError(stanza, error);

  return true;
};
Пример #10
0
 client.on('outStanza', function(stz) {
     // Section 5.1.3 in http://xmpp.org/rfcs/rfc3921.html#presence
     // TODO : HANDLE THINGS WHENE THE CLIENT IS OFFLINE TOO!
     var stanza = ltx.parse(stz.toString());
     if (stanza.is('presence')) {
         if(stanza.attrs.type === "probe") {
             if(client.roster) {
                 client.roster.itemForJid(new xmpp.JID(stanza.attrs.from).bare().toString(), function(item) {
                     if(["from", "both"].indexOf(item.state) >= 0) {
                         // TODO: Blocking Outbound Presence Notifications.
                         var clients = client.router.connectedClientsForJid(new xmpp.JID(stanza.attrs.to).bare().toString());
                         var presence = null;
                         if(clients.length === 0) {
                             presence = new xmpp.Element('presence', {from: client.jid.bare().toString(), type: "error", to: stanza.attrs.from});
                         } else {
                             // We actually need to send the last received presence..; which means we have to store it! TODO
                             presence = new xmpp.Element('presence', {from: client.jid.bare().toString(),  to: stanza.attrs.from});
                         }
                         client.server.emit('inStanza', client, stanza); // TODO: Blocking Outbound Presence Notifications.
                     }
                     else {
                         // Send an error!
                         var error = new xmpp.Element('presence', {from: client.jid.bare().toString(), type: "error", to: stanza.attrs.from});
                         client.server.emit('inStanza', client, error); 
                     }
                 });
             }
         }
     }
 });
Пример #11
0
    }, function(err, res, body) {
	that.currentRequests--;

	if (err) {
	    if (retry < that.maxHTTPRetries)
		return that.request(attrs, children, cb, retry + 1);
	    else
		return cb(err);
	}
	if (res.statusCode < 200 || res.statusCode >= 400)
	    return cb(new Error("HTTP status " + res.statusCode));

	var bodyEl;
	try {
	    bodyEl = ltx.parse(body);
	} catch(e) {
	    return cb(e);
	}

	if (bodyEl && bodyEl.attrs.type === 'terminate')
	    cb(new Error(bodyEl.attrs.condition));
	else if (bodyEl)
	    cb(null, bodyEl);
	else
	    cb(new Error('no <body/>'));
    });
Пример #12
0
exports.extractThreads = function(iq) {
  var rootEl = ltx.parse(iq.toString());
  return rootEl.getChildrenByFilter(function (c) {
    return typeof c != 'string' && 
      c.getName() == 'thread' && c.getNS() == exports.ns; 
  }, true);
}
Пример #13
0
describe('Parsing posts with \'plain\'', function() {

    var item = ltx.parse('<item><body>This is <i>some</i> text</body></item>')

    it('shouldn\'t act if entity has data', function() {
        var entity = { not: 'empty' }
        parser.parse(item, entity)
        entity.should.eql({ not: 'empty' })
    })

    it('should add text from body element', function() {
        var entity = {}
        parser.parse(item, entity)
        entity.body.should.equal('This is <i>some</i> text')
    })

    it('should throw exception if missing expected element', function(done) {
        var entity = {}
        var badItem = ltx.parse('<item/>')
        try {
            parser.parse(badItem, entity)
        } catch (e) {
            return done()
        }
        should.fail('No exception was thrown')
    })
})
Пример #14
0
    it('9.2 Admin Requests Ban List', function (done) {

      var nickjid = room + '/' + nick;

      var msg =
        "<iq id='ban2' type='get'> \
                <query xmlns='http://jabber.org/protocol/muc#admin'> \
                  <item affiliation='outcast'/> \
                </query> \
            </iq>";

      var stanza = ltx.parse(msg);
      stanza.attrs.from = helper.userJulia.jid;
      stanza.attrs.to = nickjid;

      // start clients
      helper.sendMessageWithJulia(stanza.root()).then(function (stanza) {
        try {
          assert.equal(stanza.attrs.type, 'result');
          done();
        } catch (err) {
          done(err);
        }
      }).
      catch(function (err) {
        done(err);
      });
    });
Пример #15
0
		'ignore messages from self': function (topic) {
			topic.bot.handleMessage = sinon.stub();
			topic.client.send = sinon.stub();

			var stanza = ltx.parse(fixtures.selfMessage);
			topic.read(stanza);
			assert.equal(false, topic.bot.handleMessage.called);
		},
Пример #16
0
 it('Can handle \'fixed\' field', function() {
     var number = 555
     var stanza = ltx.parse('<field type="fixed" var="field1">' +
         '<value>' + number + '</value>' +
         '</field>')
     var value = dataForm.getValues(stanza, 'fixed')
     value.should.equal(number)
 })
Пример #17
0
 it('Can handle XML field - NOTE: non-standard', function() {
     var xml = '<entry><item><content>Some content</content></item></entry>'
     var stanza = ltx.parse('<field type="xml" var="field1">' +
         '<value>' + xml + '</value>' +
         '</field>')
     var value = dataForm.getValues(stanza, 'xml')
     value.should.equal(xml)
 })
Пример #18
0
function removeInsignificantWhitespace(stanza) {
  var doc = ltx.parse(stanza.toString().replace(/>\s+</g, '><'));
  if (typeof stanza != 'string') { // was an already-parsed document
    return doc;
  } else {
    return doc.toString();
  }
}
Пример #19
0
 it('Should accept an ID and capture', function(done) {
     var stanza = ltx.parse('<iq id="1" />')
     ftw.trackId('1', function(payload) {
         payload.should.eql(stanza)
         done()
     })
     ftw.catchTracked(stanza).should.be.true
 })
Пример #20
0
exports.postsToJSON = function(reply) {
  var items = ltx.parse(reply.toString()).getChild('query').getChildren('item')
  var jsonItems = [];
  items.forEach(function(e){
    jsonItems.push(postToJson(e));
  });
  return jsonItems;
}
Пример #21
0
 client.on('stanza', function(stz) {
     var self = this;
     var stanza = ltx.parse(stz.toString());
     var query = null;
     if (stanza.is('iq') && (query = stanza.getChild('query', "jabber:iq:roster"))) {
         if(stanza.attrs.type === "get") {
             stanza.attrs.type = "result";
             RosterStorage.find(new xmpp.JID(stanza.attrs.from).bare().toString(), function(roster) {
                 roster.items.forEach(function(item) {
                     query.c("item", {jid: item.jid, name: item.name, subscription: item.state});
                 });
                 stanza.attrs.to = stanza.attrs.from;
                 client.send(stanza); 
             });
         }
         else if(stanza.attrs.type === "set") {
             stanza.attrs.type = "result";
             var i = query.getChild('item', "jabber:iq:roster");
             RosterStorage.find(new xmpp.JID(stanza.attrs.from).bare().toString(), function(roster) {
                 RosterItemStorage.find(roster, new xmpp.JID(i.attrs.jid).bare().toString(), function(item) {
                     if(i.attrs.subscription === "remove") {
                         item.delete(function() {
                             // And now send to all sessions.
                             i.attrs.subscription = 'remove';
                             stanza.attrs.from = client.server.options.domain; // Remove the from field.
                             client.server.router.connectedClientsForJid(client.jid.toString()).forEach(function(jid) {
                                 stanza.attrs.to = jid.toString();
                                 client.send(stanza); // TODO: Blocking Outbound Presence Notifications.
                             });
                         });
                     } else {
                         if(item.state === "from" && i.attrs.subscription === "to") {
                             item.state = "both";
                         }
                         else if(item.state === "to" && i.attrs.subscription === "from") {
                             item.state = "both";
                         }
                         else {
                             item.state = i.attrs.subscription || "to";
                         }
                         item.name = i.attrs.name || i.attrs.jid;
                         item.save(function() {
                             // And now send to all sessions.
                             i.attrs.subscription = item.state;
                             stanza.attrs.from = client.server.options.domain; // Remove the from field.
                             client.server.router.connectedClientsForJid(client.jid.toString()).forEach(function(jid) {
                                 stanza.attrs.to = jid.toString();
                                 client.send(stanza); // TODO: Blocking Outbound Presence Notifications.
                             });
                         });
                     }
                 });
             });
         } else if(stanza.attrs.type === "result") {
             
         }
     }
 });
Пример #22
0
exports.extractItem = function(message) {
  var messageEl = ltx.parse(message.toString());

  var items = messageEl.getChild('event', exports.eventNS).getChild('items')
  var entry = items.getChild('item').getChild('entry', atom.NS);

  addSourceToEntry(entry, items.attr('node'));
  return entry;
}
Пример #23
0
function sendStanzas (stanzas, replacements) {
  for (var i = 0; i < stanzas.length; i++) {
    var stanza = xml.parse(stanzas[ i ])
    console.log(`Replace input: ${stanza}`)
    stanzaBuilder.replace(stanza, replacements)
    console.log(`Replace output: ${stanza}`)
    xmppC2sServer.send(stanza)
  }
}
Пример #24
0
exports.channelsToJSON = function(reply, ns) {
  var items = ltx.parse(reply.toString()).getChild('query', ns)
      .getChildren('item');
  var jsonItems = [];
  items.forEach(function(e) {
    jsonItems.push(channelToJson(e, ns));
  });
  return jsonItems;
}
Пример #25
0
         User.findOne({username: client.jid.user}, function(err, user_db) {
             if (stz.is('message')) {
                 var query = stz.getChild('body').children[0];
                 message = ltx.parse("<message from='"+stz.attrs.to+"/"+user_db.nickname+"' to='"+stz.attrs.from+"' type='groupchat'>"+
 		       		"<body>"+query+"</body>"+
 		       	"</message>");
 		       	client.send(message);
             }
         });
Пример #26
0
 it('should throw exception if missing expected element', function(done) {
     var entity = {}
     var badItem = ltx.parse('<item/>')
     try {
         parser.parse(badItem, entity)
     } catch (e) {
         return done()
     }
     should.fail('No exception was thrown')
 })
Пример #27
0
    it('Should build a basic IODEF document', function() {
        var emptyIodefDocument = '<item/>'
        var stanza = ltx.parse(emptyIodefDocument)

        var entity = iodefJson
        var expected = iodefXml

        parser.build(entity, stanza)
        stanza.root().getChild('IODEF-Document').toString().should.equal(expected)
    })
Пример #28
0
exports.rsmToJSON = function(reply) {
  var rsmSet = ltx.parse(reply.toString()).getChild('query').getChild('set', rsmNs);
  var firstNode = rsmSet.getChild('first');
  var index = 0;
  if (firstNode) {
    index = firstNode.attr('index');
  }
  var count = rsmSet.getChild('count').text();
  return {index: index, count: count};
}
Пример #29
0
 it('Should accept a stanza and capture', function(done) {
     var incomingStanza = ltx.parse('<iq id="4" />')
     var outGoingStanza = incomingStanza
     incomingStanza.attrs.from = ftw.fullJid.domain
     ftw.trackId(outGoingStanza, function(payload) {
         payload.should.eql(incomingStanza)
         done()
     })
     ftw.catchTracked(incomingStanza).should.be.true
 })
Пример #30
0
 it('Errors if stanza has no ID attribute', function(done) {
     try {
         var outgoingStanza = ltx.parse('<iq />')
         ftw.trackId(outgoingStanza, function() {})
         done('Expected exception')
     } catch (e) {
         e.message.should.equal(ftw.MISSING_STANZA_ID)
         done()
     }
 })