From 54fa739d6b5d2cc0b3704eda32c7abac47708b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 12 Apr 2017 17:53:44 +0200 Subject: Limit of 100 MAM messages, if no other limit has been set by the client fix #3256 --- src/xmpp/biboumi_component.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 8b2e541..c808eec 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -627,6 +627,12 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) if (max) limit = std::atoi(max->get_inner().data()); } + // If the archive is really big, and the client didn’t specify any + // limit, we avoid flooding it: we set an arbitrary max limit. + if (limit == -1 && start.empty() && end.empty()) + { + limit = 100; + } const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end); for (const db::MucLogLine& line: lines) { -- cgit v1.2.3 From c2cc9cb96f90586ed6bb2361b82e77fae79c4d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 19 Apr 2017 21:40:50 +0200 Subject: Remove the flood limit in our e2e charybdis configuration --- tests/end_to_end/__main__.py | 1 + tests/end_to_end/ircd.conf | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 8acfe14..4483f31 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -454,6 +454,7 @@ def connection_end_sequence(irc_host, jid): xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]" irc_host = 'irc.localhost' return ( + partial(expect_stanza, xpath_re % (r'^%s: \*\*\* You are exempt from flood limits$' % irc_host)), partial(expect_stanza, xpath_re % (r'^%s: Your host is .*$' % irc_host)), partial(expect_stanza, diff --git a/tests/end_to_end/ircd.conf b/tests/end_to_end/ircd.conf index ec55884..0c0afa9 100644 --- a/tests/end_to_end/ircd.conf +++ b/tests/end_to_end/ircd.conf @@ -221,6 +221,7 @@ auth { auth { user = "*@*"; class = "users"; + flags = flood_exempt; }; /* privset {} blocks MUST be specified before anything that uses them. That -- cgit v1.2.3 From a4e2e56ad3050f8e48a57638b13c0b23849f76ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 19 Apr 2017 21:41:17 +0200 Subject: Add an e2e test for the mam default limit We send 150 messages, then retrieve the archive. We should receive messages from 50 to 149 only. --- tests/end_to_end/__main__.py | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 4483f31..aca6ffd 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -423,6 +423,7 @@ def connection_begin_sequence(irc_host, jid): xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % 'irc.localhost')), partial(expect_stanza, xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % 'irc.localhost')), + partial(expect_stanza, xpath_re % (r'^%s: \*\*\* You are exempt from flood limits$' % 'irc.localhost')), ) def connection_tls_begin_sequence(irc_host, jid): @@ -446,6 +447,7 @@ def connection_tls_begin_sequence(irc_host, jid): xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % irc_host)), partial(expect_stanza, xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % irc_host)), + partial(expect_stanza, xpath_re % (r'^%s: \*\*\* You are exempt from flood limits$' % 'irc.localhost')), ) def connection_end_sequence(irc_host, jid): @@ -454,7 +456,6 @@ def connection_end_sequence(irc_host, jid): xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]" irc_host = 'irc.localhost' return ( - partial(expect_stanza, xpath_re % (r'^%s: \*\*\* You are exempt from flood limits$' % irc_host)), partial(expect_stanza, xpath_re % (r'^%s: Your host is .*$' % irc_host)), partial(expect_stanza, @@ -492,9 +493,15 @@ def extract_attribute(xpath, name, stanza): return matched[0].get(name) +def extract_text(xpath, stanza): + matched = match(stanza, xpath) + return matched[0].text + + def save_value(name, func, stanza, xmpp): xmpp.saved_values[name] = func(stanza) + if __name__ == '__main__': atexit.register(asyncio.get_event_loop().close) @@ -1673,6 +1680,51 @@ if __name__ == '__main__': "/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo@{biboumi_host}/{nick_one}'][@type='groupchat']/client:body[text()='coucou 2']") ), ], conf="fixed_server"), + Scenario("default_mam_limit", + [ + handshake_sequence(), + partial(send_stanza, + ""), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + "/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]", + after = partial(save_value, "counter", lambda x: 0)), + ] + [ + partial(send_stanza, "{counter}"), + partial(expect_stanza, + "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='{counter}']", + after = partial(save_value, "counter", lambda stanza: str(1 + int(extract_text("/message/body", stanza)))) + ), + ] * 150 + [ + # Retrieve the archive, without any restriction + partial(send_stanza, ""), + # Since we should only receive the last 100 messages from the archive, + # it should start with message "50" + partial(expect_stanza, + ("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay", + "/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='50']") + ), + ] + [ + # followed by 98 more messages + partial(expect_stanza, + ("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay", + "/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body") + ), + ] * 98 + [ + # and finally the message "149" + partial(expect_stanza, + ("/message/mam:result[@queryid='qid1']/forward:forwarded/delay:delay", + "/message/mam:result[@queryid='qid1']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='149']") + ), + partial(expect_stanza, + "/iq[@type='result'][@id='id1'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']"), + + ]), Scenario("channel_history_on_fixed_server", [ handshake_sequence(), -- cgit v1.2.3 From 96d460de480617ec2ade3b5cc428bd144a1659f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 19 Apr 2017 23:05:08 +0200 Subject: Add the default MAM limit in the changelog --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ae1ee29..74d60f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,8 @@ Version 5.0 - Use the udns library instead of c-ares, for asynchronous DNS resolution. It’s still fully optional. - Update MAM implementation to version 6.0 (namespace mam:2) + - If the client doesn’t specify any limit, MAM results contain at most 100 + messages, instead of the whole archive. - Multiline topics are now properly handled Version 4.1 - 2017-03-21 -- cgit v1.2.3