diff options
Diffstat (limited to 'mqtt-tester/src/behaviour')
-rw-r--r-- | mqtt-tester/src/behaviour/mod.rs | 2 | ||||
-rw-r--r-- | mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs | 70 |
2 files changed, 72 insertions, 0 deletions
diff --git a/mqtt-tester/src/behaviour/mod.rs b/mqtt-tester/src/behaviour/mod.rs index e831a05..39a7d03 100644 --- a/mqtt-tester/src/behaviour/mod.rs +++ b/mqtt-tester/src/behaviour/mod.rs @@ -7,6 +7,7 @@ pub mod connack_flags_are_set_as_reserved; pub mod invalid_first_packet_is_rejected; pub mod invalid_utf8_is_rejected; +pub mod publish_qos_zero_with_ident_fails; pub mod receiving_server_packet; pub mod utf8_with_nullchar_is_rejected; pub mod wait_for_connect; @@ -14,6 +15,7 @@ pub mod wait_for_connect; pub use self::connack_flags_are_set_as_reserved::ConnackFlagsAreSetAsReserved; pub use self::invalid_first_packet_is_rejected::InvalidFirstPacketIsRejected; pub use self::invalid_utf8_is_rejected::InvalidUtf8IsRejected; +pub use self::publish_qos_zero_with_ident_fails::PublishQosZeroWithIdentFails; pub use self::receiving_server_packet::ReceivingServerPacket; pub use self::utf8_with_nullchar_is_rejected::Utf8WithNullcharIsRejected; pub use self::wait_for_connect::WaitForConnect; 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 + } + } +} |