|
|
@ -9,39 +9,56 @@ from deltachat.capi import lib as dclib
|
|
|
|
TIMEOUT = 20
|
|
|
|
TIMEOUT = 20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.timeout(60)
|
|
|
|
def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
|
|
|
|
def test_not_relay_groups(relaycrew, outsider):
|
|
|
|
"""Get the Team chat from the team member's point of view.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param crewuser: the account object of the team member
|
|
|
|
|
|
|
|
:return: the chat object of the team chat
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
for chat in crewuser.get_chats():
|
|
|
|
|
|
|
|
print(chat.id, chat.get_name())
|
|
|
|
|
|
|
|
user_crew = crewuser.get_chat_by_id(11)
|
|
|
|
|
|
|
|
assert user_crew.get_name().startswith("Team")
|
|
|
|
|
|
|
|
return user_crew
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.timeout(TIMEOUT * 3)
|
|
|
|
|
|
|
|
def test_not_relay_groups(relaycrew, outsider, lp):
|
|
|
|
bot = relaycrew.bot
|
|
|
|
bot = relaycrew.bot
|
|
|
|
user = relaycrew.user
|
|
|
|
user = relaycrew.user
|
|
|
|
|
|
|
|
|
|
|
|
# bot <-> outsider 1:1 chat
|
|
|
|
lp.sec("bot <-> outsider 1:1 chat")
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
|
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
|
|
|
|
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
|
|
|
|
outsider_outside_chat.send_text("test 1:1 message to bot")
|
|
|
|
outsider_outside_chat.send_text("test 1:1 message to bot")
|
|
|
|
|
|
|
|
|
|
|
|
bot_message_from_outsider = bot.wait_next_incoming_message()
|
|
|
|
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
|
|
|
bot_outside_chat = bot_message_from_outsider.chat
|
|
|
|
bot_outside_chat = bot_message_from_outsider.chat
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
|
|
|
|
|
|
|
|
|
|
|
# bot <-> outsider group chat
|
|
|
|
lp.sec("bot <-> outsider group chat")
|
|
|
|
outsider_bot_group = outsider.create_group_chat(
|
|
|
|
outsider_bot_group = outsider.create_group_chat(
|
|
|
|
"test with outsider", contacts=[outsider_botcontact]
|
|
|
|
"test with outsider", contacts=[outsider_botcontact]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
outsider_bot_group.send_text("test message to outsider group")
|
|
|
|
outsider_bot_group.send_text("test message to outsider group")
|
|
|
|
bot_message_from_outsider = bot.wait_next_incoming_message()
|
|
|
|
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_outsider.chat)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_outsider.chat)
|
|
|
|
|
|
|
|
|
|
|
|
# bot <-> user 1:1 chat
|
|
|
|
lp.sec("bot <-> user 1:1 chat")
|
|
|
|
user_botcontact = user.create_contact(bot.get_config("addr"))
|
|
|
|
user_botcontact = user.create_contact(bot.get_config("addr"))
|
|
|
|
user_to_bot = user.create_chat(user_botcontact)
|
|
|
|
user_to_bot = user.create_chat(user_botcontact)
|
|
|
|
user_to_bot.send_text("test message to bot")
|
|
|
|
user_to_bot.send_text("test message to bot")
|
|
|
|
bot_message_from_user = bot.wait_next_incoming_message()
|
|
|
|
# somehow the message doesn't trigger DC_EVENT_INCOMING_MSG
|
|
|
|
|
|
|
|
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
|
|
|
|
|
|
|
|
while bot_message_from_user.text != "test message to bot":
|
|
|
|
|
|
|
|
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
|
|
|
|
|
|
|
|
|
|
|
# bot <-> user group chat
|
|
|
|
lp.sec("bot <-> user group chat")
|
|
|
|
user_group = user.create_group_chat("test with user", contacts=[user_botcontact])
|
|
|
|
user_group = user.create_group_chat("test with user", contacts=[user_botcontact])
|
|
|
|
user_group.send_text("testing message to user group")
|
|
|
|
user_group.send_text("testing message to user group")
|
|
|
|
bot_message_from_user = bot.wait_next_incoming_message()
|
|
|
|
bot_message_from_user = bot._evtracker.wait_next_incoming_message()
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,18 +73,18 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|
|
|
outsider_outside_chat.send_text("test 1:1 message to bot")
|
|
|
|
outsider_outside_chat.send_text("test 1:1 message to bot")
|
|
|
|
|
|
|
|
|
|
|
|
# get outside chat
|
|
|
|
# get outside chat
|
|
|
|
message_from_outsider = bot.wait_next_incoming_message()
|
|
|
|
message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
|
|
|
bot_outside_chat = message_from_outsider.chat
|
|
|
|
bot_outside_chat = message_from_outsider.chat
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
|
|
|
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
|
|
|
|
|
|
|
|
|
|
|
# get relay group
|
|
|
|
# get relay group
|
|
|
|
user.wait_next_incoming_message() # group added message
|
|
|
|
user._evtracker.wait_next_incoming_message() # group added message
|
|
|
|
user_forwarded_message_from_outsider = user.wait_next_incoming_message()
|
|
|
|
user_forwarded_message_from_outsider = user._evtracker.wait_next_incoming_message()
|
|
|
|
user_relay_group = user_forwarded_message_from_outsider.create_chat()
|
|
|
|
user_relay_group = user_forwarded_message_from_outsider.create_chat()
|
|
|
|
user_relay_group.send_text(
|
|
|
|
user_relay_group.send_text(
|
|
|
|
"Chatter in relay group"
|
|
|
|
"Chatter in relay group"
|
|
|
|
) # send normal reply, not forwarded
|
|
|
|
) # send normal reply, not forwarded
|
|
|
|
bot_chatter_in_relay_group = bot.wait_next_incoming_message()
|
|
|
|
bot_chatter_in_relay_group = bot._evtracker.wait_next_incoming_message()
|
|
|
|
bot_relay_group = bot_chatter_in_relay_group.chat
|
|
|
|
bot_relay_group = bot_chatter_in_relay_group.chat
|
|
|
|
|
|
|
|
|
|
|
|
# check if relay group has relay group properties
|
|
|
|
# check if relay group has relay group properties
|
|
|
@ -91,7 +108,7 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|
|
|
assert sent_id == user_direct_reply.id
|
|
|
|
assert sent_id == user_direct_reply.id
|
|
|
|
|
|
|
|
|
|
|
|
# check that direct reply was forwarded to outsider
|
|
|
|
# check that direct reply was forwarded to outsider
|
|
|
|
outsider_direct_reply = outsider.wait_next_incoming_message()
|
|
|
|
outsider_direct_reply = outsider._evtracker.wait_next_incoming_message()
|
|
|
|
assert outsider_direct_reply.text == "This should be forwarded to the outsider"
|
|
|
|
assert outsider_direct_reply.text == "This should be forwarded to the outsider"
|
|
|
|
assert outsider_direct_reply.chat == outsider_outside_chat
|
|
|
|
assert outsider_direct_reply.chat == outsider_outside_chat
|
|
|
|
assert outsider_direct_reply.get_sender_contact() == outsider_botcontact
|
|
|
|
assert outsider_direct_reply.get_sender_contact() == outsider_botcontact
|
|
|
@ -105,7 +122,7 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|
|
|
outsider_outside_chat.send_text("Second message by outsider")
|
|
|
|
outsider_outside_chat.send_text("Second message by outsider")
|
|
|
|
|
|
|
|
|
|
|
|
# check that outsider's reply ends up in the same chat
|
|
|
|
# check that outsider's reply ends up in the same chat
|
|
|
|
user_second_message_from_outsider = user.wait_next_incoming_message()
|
|
|
|
user_second_message_from_outsider = user._evtracker.wait_next_incoming_message()
|
|
|
|
assert user_second_message_from_outsider.chat == user_relay_group
|
|
|
|
assert user_second_message_from_outsider.chat == user_relay_group
|
|
|
|
|
|
|
|
|
|
|
|
# check that relay group explanation is not forwarded to outsider
|
|
|
|
# check that relay group explanation is not forwarded to outsider
|
|
|
@ -124,7 +141,7 @@ def test_default_outside_help(relaycrew, outsider):
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
|
|
|
|
|
|
|
|
# get response
|
|
|
|
# get response
|
|
|
|
outside_help_message = outsider.wait_next_incoming_message()
|
|
|
|
outside_help_message = outsider._evtracker.wait_next_incoming_message()
|
|
|
|
assert "I forward messages to the " in outside_help_message.text
|
|
|
|
assert "I forward messages to the " in outside_help_message.text
|
|
|
|
|
|
|
|
|
|
|
|
# assert no relay group was created
|
|
|
|
# assert no relay group was created
|
|
|
@ -143,7 +160,7 @@ def test_empty_outside_help(relaycrew, outsider):
|
|
|
|
assert user_crew.get_name().startswith("Team")
|
|
|
|
assert user_crew.get_name().startswith("Team")
|
|
|
|
user_crew.send_text("/set_outside_help")
|
|
|
|
user_crew.send_text("/set_outside_help")
|
|
|
|
# ensure /set_outside_help arrives before sending /help
|
|
|
|
# ensure /set_outside_help arrives before sending /help
|
|
|
|
bot.wait_next_incoming_message()
|
|
|
|
bot._evtracker.wait_next_incoming_message()
|
|
|
|
|
|
|
|
|
|
|
|
# create outside chat
|
|
|
|
# create outside chat
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
@ -151,9 +168,10 @@ def test_empty_outside_help(relaycrew, outsider):
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
|
|
|
|
|
|
|
|
# get forwarded /help message
|
|
|
|
# get forwarded /help message
|
|
|
|
user.wait_next_incoming_message() # group added message
|
|
|
|
user._evtracker.wait_next_incoming_message() # group added message
|
|
|
|
user.wait_next_incoming_message() # explanation message
|
|
|
|
user._evtracker.wait_next_incoming_message() # "Removed help message for outsiders"
|
|
|
|
user_forwarded_message_from_outsider = user.wait_next_incoming_message()
|
|
|
|
user._evtracker.wait_next_incoming_message() # explanation message
|
|
|
|
|
|
|
|
user_forwarded_message_from_outsider = user._evtracker.wait_next_incoming_message()
|
|
|
|
assert user_forwarded_message_from_outsider.text == "/help"
|
|
|
|
assert user_forwarded_message_from_outsider.text == "/help"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -169,7 +187,7 @@ def test_changed_outside_help(relaycrew, outsider):
|
|
|
|
outside_help_text = "Hi friend :) send me messages to chat with the team"
|
|
|
|
outside_help_text = "Hi friend :) send me messages to chat with the team"
|
|
|
|
user_crew.send_text("/set_outside_help " + outside_help_text)
|
|
|
|
user_crew.send_text("/set_outside_help " + outside_help_text)
|
|
|
|
# ensure /set_outside_help arrives before sending /help
|
|
|
|
# ensure /set_outside_help arrives before sending /help
|
|
|
|
bot.wait_next_incoming_message()
|
|
|
|
bot._evtracker.wait_next_incoming_message()
|
|
|
|
|
|
|
|
|
|
|
|
# create outside chat
|
|
|
|
# create outside chat
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
|
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
|
|
@ -177,7 +195,7 @@ def test_changed_outside_help(relaycrew, outsider):
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
outsider_outside_chat.send_text("/help")
|
|
|
|
|
|
|
|
|
|
|
|
# get response
|
|
|
|
# get response
|
|
|
|
outside_help_message = outsider.wait_next_incoming_message()
|
|
|
|
outside_help_message = outsider._evtracker.wait_next_incoming_message()
|
|
|
|
assert outside_help_message.text == outside_help_text
|
|
|
|
assert outside_help_message.text == outside_help_text
|
|
|
|
|
|
|
|
|
|
|
|
# assert no relay group was created
|
|
|
|
# assert no relay group was created
|
|
|
@ -202,21 +220,19 @@ def test_change_avatar(relaycrew):
|
|
|
|
pytest.skip(f"example image not available: {example_png_path}")
|
|
|
|
pytest.skip(f"example image not available: {example_png_path}")
|
|
|
|
|
|
|
|
|
|
|
|
# set avatar to example image
|
|
|
|
# set avatar to example image
|
|
|
|
for chat in user.get_chats():
|
|
|
|
user_crew = get_user_crew(user)
|
|
|
|
print(chat.id, chat.get_name())
|
|
|
|
|
|
|
|
user_crew = user.get_chat_by_id(11)
|
|
|
|
|
|
|
|
assert user_crew.get_name().startswith("Team")
|
|
|
|
|
|
|
|
msg = deltachat.Message.new_empty(user, "image")
|
|
|
|
msg = deltachat.Message.new_empty(user, "image")
|
|
|
|
msg.set_text("/set_avatar")
|
|
|
|
msg.set_text("/set_avatar")
|
|
|
|
msg.set_file(example_png_path)
|
|
|
|
msg.set_file(example_png_path)
|
|
|
|
sent_id = dclib.dc_send_msg(user._dc_context, user_crew.id, msg._dc_msg)
|
|
|
|
sent_id = dclib.dc_send_msg(user._dc_context, user_crew.id, msg._dc_msg)
|
|
|
|
assert sent_id == msg.id
|
|
|
|
assert sent_id == msg.id
|
|
|
|
|
|
|
|
|
|
|
|
group_avatar_changed_msg = user.wait_next_incoming_message()
|
|
|
|
user._evtracker.wait_next_incoming_message() # chat successfully created
|
|
|
|
|
|
|
|
group_avatar_changed_msg = user._evtracker.wait_next_incoming_message()
|
|
|
|
assert "Group image changed" in group_avatar_changed_msg.text
|
|
|
|
assert "Group image changed" in group_avatar_changed_msg.text
|
|
|
|
assert user_crew.get_profile_image()
|
|
|
|
assert user_crew.get_profile_image()
|
|
|
|
|
|
|
|
|
|
|
|
confirmation_msg = user.wait_next_incoming_message()
|
|
|
|
confirmation_msg = user._evtracker.wait_next_incoming_message()
|
|
|
|
assert confirmation_msg.text == "Avatar changed to this image."
|
|
|
|
assert confirmation_msg.text == "Avatar changed to this image."
|
|
|
|
assert botcontact.get_profile_image()
|
|
|
|
assert botcontact.get_profile_image()
|
|
|
|
|
|
|
|
|
|
|
@ -237,7 +253,9 @@ def test_forward_sending_errors_to_relay_group(relaycrew):
|
|
|
|
|
|
|
|
|
|
|
|
while len(relaycrew.user.get_chats()) < 2 and int(time.time()) < begin + TIMEOUT:
|
|
|
|
while len(relaycrew.user.get_chats()) < 2 and int(time.time()) < begin + TIMEOUT:
|
|
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(0.1)
|
|
|
|
relay_group = relaycrew.user.get_chats()[-2]
|
|
|
|
for chat in relaycrew.user.get_chats():
|
|
|
|
|
|
|
|
if "This Message will fail" in chat.get_name():
|
|
|
|
|
|
|
|
relay_group = chat
|
|
|
|
|
|
|
|
|
|
|
|
while len(relay_group.get_messages()) < 3 and int(time.time()) < begin + TIMEOUT:
|
|
|
|
while len(relay_group.get_messages()) < 3 and int(time.time()) < begin + TIMEOUT:
|
|
|
|
print(relay_group.get_messages()[-1].text)
|
|
|
|
print(relay_group.get_messages()[-1].text)
|
|
|
@ -250,3 +268,19 @@ def test_forward_sending_errors_to_relay_group(relaycrew):
|
|
|
|
"Invalid unencrypted mail to <alice@example.org>"
|
|
|
|
"Invalid unencrypted mail to <alice@example.org>"
|
|
|
|
in relay_group.get_messages()[-1].text
|
|
|
|
in relay_group.get_messages()[-1].text
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.timeout(TIMEOUT * 2)
|
|
|
|
|
|
|
|
def test_public_invite(relaycrew, outsider):
|
|
|
|
|
|
|
|
crew = get_user_crew(relaycrew.user)
|
|
|
|
|
|
|
|
crew.send_text("/generate-invite")
|
|
|
|
|
|
|
|
result = relaycrew.user._evtracker.wait_next_incoming_message()
|
|
|
|
|
|
|
|
assert result.filename
|
|
|
|
|
|
|
|
assert result.text.startswith("https://i.delta.chat")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qr = result.filename
|
|
|
|
|
|
|
|
chat = outsider.qr_setup_contact(qr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while not chat.is_protected():
|
|
|
|
|
|
|
|
print(chat.get_messages()[:-1].text)
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|