summaryrefslogtreecommitdiffstats
path: root/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs')
-rw-r--r--mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
new file mode 100644
index 0000000..17525b6
--- /dev/null
+++ b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
@@ -0,0 +1,63 @@
+//
+// 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::packet::MPacket;
+
+use crate::{
+ behaviour_test::BehaviourTest,
+ command::{Input, Output},
+ executable::ClientExecutableCommand,
+ report::ReportResult,
+};
+
+pub struct FirstPacketFromClientIsConnect;
+
+#[async_trait::async_trait]
+impl BehaviourTest for FirstPacketFromClientIsConnect {
+ fn commands(&self) -> Vec<Box<dyn ClientExecutableCommand>> {
+ vec![]
+ }
+
+ async fn execute(&self, _input: Input, mut output: Output) -> Result<(), miette::Error> {
+ output
+ .wait_and_check(
+ &(|bytes: &[u8]| -> bool {
+ let packet = match nom::combinator::all_consuming(
+ mqtt_format::v3::packet::mpacket,
+ )(bytes)
+ {
+ Ok((_, packet)) => packet,
+ Err(_e) => return false,
+ };
+
+ std::matches!(packet, MPacket::Connect { .. })
+ }),
+ )
+ .await?;
+
+ Ok(())
+ }
+
+ fn report_name(&self) -> &str {
+ "First packet send by client must be CONNECT"
+ }
+
+ fn report_desc(&self) -> &str {
+ "After a Network Connection is established by a Client to a Server, the first Packet sent from the Client to the Server MUST be a CONNECT Packet."
+ }
+
+ fn report_normative(&self) -> &str {
+ "[MQTT-3.1.0-1]"
+ }
+
+ fn translate_client_exit_code(&self, success: bool) -> ReportResult {
+ if success {
+ ReportResult::Failure
+ } else {
+ ReportResult::Success
+ }
+ }
+}