IOTData: publish() should be able to handle non-Unicode bytes (#6509)

This commit is contained in:
Bert Blommers 2023-07-11 09:31:44 +00:00 committed by GitHub
parent 971568f226
commit 2dbbdc3123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
from moto.core.responses import BaseResponse
from .models import iotdata_backends, IoTDataPlaneBackend
import json
from typing import Any
from urllib.parse import unquote
@ -8,6 +9,11 @@ class IoTDataPlaneResponse(BaseResponse):
def __init__(self) -> None:
super().__init__(service_name="iot-data")
def setup_class(
self, request: Any, full_url: str, headers: Any, use_raw_body: bool = False
) -> None:
super().setup_class(request, full_url, headers, use_raw_body=True)
def _get_action(self) -> str:
if self.path and self.path.startswith("/topics/"):
# Special usecase - there is no way identify this action, besides the URL

View File

@ -112,14 +112,14 @@ def test_publish():
client = boto3.client("iot-data", region_name=region_name)
client.publish(topic="test/topic1", qos=1, payload=b"pl1")
client.publish(topic="test/topic2", qos=1, payload=b"pl2")
client.publish(topic="test/topic3", qos=1, payload=b"pl3")
client.publish(topic="test/topic3", qos=1, payload=b"\xbf")
if not settings.TEST_SERVER_MODE:
mock_backend = moto.iotdata.models.iotdata_backends[ACCOUNT_ID][region_name]
mock_backend.published_payloads.should.have.length_of(3)
mock_backend.published_payloads.should.contain(("test/topic1", "pl1"))
mock_backend.published_payloads.should.contain(("test/topic2", "pl2"))
mock_backend.published_payloads.should.contain(("test/topic3", "pl3"))
mock_backend.published_payloads.should.contain(("test/topic1", b"pl1"))
mock_backend.published_payloads.should.contain(("test/topic2", b"pl2"))
mock_backend.published_payloads.should.contain(("test/topic3", b"\xbf"))
@mock_iot