Coder Social home page Coder Social logo

stabber's Introduction

Stabber

Stubbed XMPP (Jabber) Server.

Overview

Stabber acts as a stubbed XMPP service for testing purposes, supporting:

The project is work in progress, and is being developed alongside https://github.com/boothj5/profanity

Installing

./bootstrap.sh
./configure
make
make install (as root)

C API

Include the following header in your tests:

#include <stabber.h>

Include the following in the linker path when compiling tests:

-lstabber

Starting

To start Stabber:

stbbr_start(stbbr_log_t loglevel, int port, int httpport);

loglevel - Must be one of STBBR_LOGDEBUG, STBBR_LOGINFO, STBBR_LOGWARN, STBBR_LOGERROR.

port - The port on which to run the stubbed XMPP server.

httpport - The port on which to run the HTTP API, a value of 0 will not run the HTTP daemon.

Stopping

To stop Stabber:

stbbr_stop();

Authentication

Currently only legacy authentication is supported, to set the password that stabber expects when an account connects:

stbbr_auth_passwd("mypassword");

The default if not set is "password".

Sending stanzas

To make Stabber send an XMPP stanza:

stbbr_send(
    "<iq id=\"ping1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
        "<ping xmlns=\"urn:xmpp:ping\"/>"
    "</iq>"
);

Responding to stanzas

As well as being able to send an XMPP stanza at any time, you can also respond to a stanza by its id attribute:

stbbr_for_id("msg_21",
    "<message id=\"message17\" to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\" type=\"chat\">"
        "<body>I'm not real!</body>"
    "</message>"
);

To respond to an IQ get query (for example a roster request), use the following:

stbbr_for_query("jabber:iq:roster",
    "<iq type=\"result\" to=\"stabber@localhost/profanity\">"
        "<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
            "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
            "<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
        "</query>"
    "</iq>"
);

Note that no ID is included in the stubbed response, Stabber will use the ID sent in the query. If an ID is supplied, it wil be overwitten by Stabber, again using the ID sent in the query.

Verify sent stanzas

To verify that you sent a particular stanza to Stabber:

stbbr_received(
    "<message id=\"msg24415\" to=\"buddy1@localhost/mobile\" type=\"chat\">"
        "<body>I know, its a test.</body>"
    "</message>"
);

The above function returns 1 if the stanza has been received, and 0 if it hasn't. The following function check that it was specifically the last stanza received:

stbbr_last_received(
    "<message id=\"msg24415\" to=\"buddy1@localhost/mobile\" type=\"chat\">"
        "<body>I know, its a test.</body>"
    "</message>"
);

Both verifications allow for wildcards (*) as attribute values, for example, if you don't know the id's that are generated by your client:

stbbr_received(
    "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">"
        "<body>I know, its a test.</body>"
    "</message>"
);

By default the verification calls block for up to 10 seconds, the timeout in seconds can be set with:

stbbr_set_timeout(3);

A value of 0 or less is non-blocking and will return immediately.

Waiting

Sometimes a test needs to wait until the client being tested has had time to send some specific stanzas. The following will block until a stanza with a particular ID has been received by Stabber:

stbbr_wait_for("someid");

HTTP API

To start stabber in standalone mode:

stabber -p <port> -h <httpport> -l <loglevel> 

<port> - The port on which to run the stubbed XMPP server.

<httpport> - The port on which to run the HTTP API, optional.

<loglevel> - The log level for Stabber, one of DEBUG, INFO, WARN, ERROR. Optional with a default of INFO.

Sending stanzas

To send a message to a client currently connected to Stabber on port 5230, send a POST request to http://localhost:5231/send with the body containing the stanza to send, e.g.:

curl --data '<message id="mesg10" to="stabber@localhost/profanity" from="buddy1@localhost/laptop" type="chat"><body>Here is a message sent from stabber, using the HTTP api</body></message>' http://localhost:5231/send

Responding to stanzas

To respond to a stanza with a specfic id sent from the client, send a POST request to http://localhost:5231/for?id=<id> where <id> is the the id you wish to respond to, e.g.:

curl --data '<message id="messageid1" to="stabber@localhost/profanity" from="buddy1@localhost/work" type="chat"><body>heres my answer!</body></message>' http://localhost:5231/for?id=prof_msg_1

To respond to a stanza with a specfic query namespace sent from the client, send a POST request to http://localhost:5231/for?query=<xmlns> where <xmlns> is the the query namespace you wish to respond to, e.g.:

curl --data '<iq type="result" to="stabber@localhost/profanity"><query xmlns="jabber:iq:roster" ver="362"><item jid="buddy1@localhost" subscription="both" name="Buddy1"/><item jid="buddy2@localhost" subscription="both" name="Buddy2"/></query></iq>' http://localhost:5231/for?query=jabber:iq:roster

Verify sent stanzas

To verify that a stanza was received by Stabber, send a POST request to http://localhost:5231/verify where the body is the expected stanza, e.g.:

curl --data '<iq id="*" type="get"><ping xmlns="urn:xmpp:ping"/></iq>' http://localhost:5231/verify

The request will return immediately with a body containing either true or false.

Logs

Stabber logs to:

~/.local/share/stabber/logs/stabber.log

Examples

Example tests for Profanity can be found at: https://github.com/boothj5/profanity/tree/master/tests/functionaltests

stabber's People

Contributors

boothj5 avatar jubalh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.