message_edit: Reject buggy noop topic edit requests.

A buggy client might send a message_edit request to change the topic
field, sending the current topic as the new value. Previously, we
would treat that as a normal request to edit the topic; now we act as
though the API request had not requested a topic change.  In the
common case that only the topic was in the edit request, this now
results in an error that should help client implementations identify
their bug.

This fixes a bad interaction with the "unresolve topic" logic, which
assumed that upstream logic had verified that the topic was actually
changing.
This commit is contained in:
Tim Abbott 2021-06-21 12:11:32 -07:00
parent 5a47e1f289
commit b2dd15fd86
2 changed files with 15 additions and 0 deletions

View File

@ -2852,6 +2852,9 @@ def check_update_message(
# use REQ_topic as well (or otherwise are guaranteed to strip input).
if topic_name is not None:
topic_name = topic_name.strip()
if topic_name == message.topic_name():
topic_name = None
validate_message_edit_payload(message, stream_id, topic_name, propagate_mode, content)
is_no_topic_msg = message.topic_name() == "(no topic)"

View File

@ -1968,6 +1968,18 @@ class EditMessageTest(EditMessageTestCase):
)
id2 = self.send_stream_message(admin_user, "new", topic_name=original_topic)
# Check that we don't incorrectly send "unresolve topic"
# notifications when asking the preserve the current topic.
result = self.client_patch(
"/json/messages/" + str(id1),
{
"message_id": id1,
"topic": original_topic,
"propagate_mode": "change_all",
},
)
self.assert_json_error(result, "Nothing to change")
resolved_topic = RESOLVED_TOPIC_PREFIX + original_topic
result = self.client_patch(
"/json/messages/" + str(id1),