diff options
Diffstat (limited to 'mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs')
-rw-r--r-- | mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs new file mode 100644 index 0000000..fe5544d --- /dev/null +++ b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs @@ -0,0 +1,70 @@ +// +// 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, + identifier::MPacketIdentifier, + packet::{MConnack, MPublish}, + qos::MQualityOfService, + strings::MString, +}; + +use crate::{ + behaviour_test::BehaviourTest, + command::{Input, Output}, + executable::ClientExecutableCommand, + report::ReportResult, +}; + +pub struct PublishQosZeroWithIdentFails; + +#[async_trait::async_trait] +impl BehaviourTest for PublishQosZeroWithIdentFails { + 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_packet(MPublish { + dup: false, + qos: MQualityOfService::AtMostOnce, // QoS 0 + retain: false, + topic_name: MString { value: "a" }, + id: Some(MPacketIdentifier(1)), + payload: &[0x00], + }) + .await?; + Ok(()) + } + + fn report_name(&self) -> &str { + "A PUBLISH packet with QoS zero must not contain a packet identifier" + } + + fn report_desc(&self) -> &str { + "A PUBLISH Packet MUST NOT contain a Packet Identifier if its QoS value is set to 0." + } + + fn report_normative(&self) -> &str { + "[MQTT-2.3.1-5]" + } + + fn translate_client_exit_code(&self, success: bool) -> ReportResult { + if success { + ReportResult::Failure + } else { + ReportResult::Success + } + } +} |