esl / escalus

An XMPP client library in Erlang for conveniently testing XMPP servers
Apache License 2.0
129 stars 76 forks source link

Error starting escalus story when user have offline messages #197

Open pdorofiejczyk opened 5 years ago

pdorofiejczyk commented 5 years ago

I'm trying to test offline messages using escalus. When I'm trying to start escalus story for user who have offline messages, I'm getting following error:

     ** (ErlangError) Erlang error: {:assertion_failed, :assert, :is_presence, {:xmlel, "message", [{"xml:lang", "en"}, {"to", "1000571-9@example2.com/res1"}, {"from", "1000571-8@example.com/res1"}], [{:xmlel, "archived", [{"by", "1000571-8@example.com"}, {"id", "8512ba7a-04fd-11e9-bc0e-69dacdbc2072"}, {"xmlns", "urn:xmpp:mam:tmp"}], []}, {:xmlel, "stanza-id", [{"by", "1000571-8@example.com"}, {"id", "8512ba7a-04fd-11e9-bc0e-69dacdbc2072"}, {"xmlns", "urn:xmpp:sid:0"}], []}, {:xmlel, "seq", [{"id", "2"}, {"xmlns", "urn:message:seq"}], []}, {:xmlel, "delay", [{"from", "example2.com"}, {"stamp", "2018-12-21T08:50:51.830393Z"}, {"xmlns", "urn:xmpp:delay"}], [xmlcdata: "Offline storage"]}, {:xmlel, "body", [], [xmlcdata: "offline message"]}]}, '<message xml:lang=\'en\' to=\'1000571-9@example2.com/res1\' from=\'1000571-8@example.com/res1\'><archived by=\'1000571-8@example.com\' id=\'8512ba7a-04fd-11e9-bc0e-69dacdbc2072\' xmlns=\'urn:xmpp:mam:tmp\'/><stanza-id by=\'1000571-8@example.com\' id=\'8512ba7a-04fd-11e9-bc0e-69dacdbc2072\' xmlns=\'urn:xmpp:sid:0\'/><seq id=\'2\' xmlns=\'urn:message:seq\'/><delay from=\'example2.com\' stamp=\'2018-12-21T08:50:51.830393Z\' xmlns=\'urn:xmpp:delay\'>Offline storage</delay><body>offline message</body></message>'}

Short investigation shows that escalus story aways wait for presences after starting client (https://github.com/esl/escalus/blob/master/src/escalus_story.erl#L136) but this behaviour is not fully correct in my case.

michalwski commented 5 years ago

Sorry for such a late response. Usually, regular XMPP clients sends initial presence to the server just after establishing the session and waits for the presence reply. This is what escalus_story tries to simulate in https://github.com/esl/escalus/blob/master/src/escalus_story.erl#L133-L134. You can set your own initial_activity if you don't want to send the initial presence.

pdorofiejczyk commented 5 years ago

It is ok that client sends initial presence. The wrong thing is that escalus waits ONLY for presence reply. It means that server should not send offline messages to client until it send presence reply first. I 'm using ejabberd server version 18.04 and default mod_offline, sends offline messages before presence reply. What's more this behaviour of escalus is not consistent with XEP-0160 (https://xmpp.org/extensions/xep-0160.html).

michalwski commented 5 years ago

I see your point. You can change the way escalus_story behaves by providing other function to initial_activity by setting is in escalus_overrides. Sth like the following should work

[{escalus_overrides, 
  [{initial_activity, [{your_module, your_function}]}]} | Config]

In your function you can stop sending the initial presence, or send it but consume all the offline messages.

Please consult the escalus_overridables module for more details.