diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2023-01-12 15:56:43 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2023-01-18 09:07:18 +0100 |
commit | a474433d12e72a353bb6fcc347dd18d1b4c6ebb2 (patch) | |
tree | 1e8f983c1d75cba7a9659bccad8b96c3b1da8dbb /mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs | |
parent | 8732e5e0f14fa65ad9e330ee3c6d69e37157b8ec (diff) |
Reimplement check_invalid_utf8_is_rejected as BehaviourTest
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs')
-rw-r--r-- | mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs new file mode 100644 index 0000000..eea0fa5 --- /dev/null +++ b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs @@ -0,0 +1,47 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use mqtt_format::v3::{connect_return::MConnectReturnCode, packet::MConnack}; + +use crate::{ + behaviour_test::BehaviourTest, + command::{Input, Output}, + executable::ClientExecutableCommand, +}; + +pub struct InvalidUtf8IsRejected; + +#[async_trait::async_trait] +impl BehaviourTest for InvalidUtf8IsRejected { + fn commands(&self) -> Vec<Box<dyn ClientExecutableCommand>> { + vec![] + } + + async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> { + input + .send_packet(MConnack { + session_present: false, + connect_return_code: MConnectReturnCode::Accepted, + }) + .await?; + + input + .send(&[ + 0b0011_0000, // PUBLISH packet, DUP = 0, QoS = 0, Retain = 0 + 0b0000_0111, // Length + // Now the variable header + 0b0000_0000, + 0b0000_0010, + 0x61, + 0xC1, // An invalid UTF-8 byte + 0b0000_0000, // Packet identifier + 0b0000_0001, + 0x1, // Payload + ]) + .await?; + Ok(()) + } +} |