mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	Although our POST /messages handler accepts the ‘to’ parameter with or without JSON encoding, there are two problems with passing it as an unencoded string. Firstly, you’d fail to send a message to a stream named ‘true’ or ‘false’ or ‘null’ or ‘2022’, as the JSON interpretation is prioritized over the plain string interpretation. Secondly, and more importantly for our tests, it violates our OpenAPI schema, which requires the parameter to be JSON-encoded. This is because OpenAPI has no concept of a parameter that’s “optionally JSON-encoded”, nor should it: such a parameter cannot be unambiguously decoded for the reason above. Our version of openapi-core doesn’t currently detect this schema violation, but after the next upgrade it will. Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			24 lines
		
	
	
		
			711 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			711 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import orjson
 | 
						|
 | 
						|
from zerver.lib.test_classes import ZulipTestCase
 | 
						|
 | 
						|
 | 
						|
class LegacySubjectTest(ZulipTestCase):
 | 
						|
    def test_legacy_subject(self) -> None:
 | 
						|
        self.login("hamlet")
 | 
						|
 | 
						|
        payload = dict(
 | 
						|
            type="stream",
 | 
						|
            to=orjson.dumps("Verona").decode(),
 | 
						|
            content="Test message",
 | 
						|
        )
 | 
						|
 | 
						|
        payload["subject"] = "whatever"
 | 
						|
        result = self.client_post("/json/messages", payload)
 | 
						|
        self.assert_json_success(result)
 | 
						|
 | 
						|
        # You can't use both subject and topic.
 | 
						|
        payload["topic"] = "whatever"
 | 
						|
        result = self.client_post("/json/messages", payload)
 | 
						|
        self.assert_json_error(result, "Can't decide between 'topic' and 'subject' arguments")
 |