summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2023-01-13 08:55:04 +0100
committerMatthias Beyer <mail@beyermatthias.de>2023-01-18 09:07:19 +0100
commit1551929eb814d805e181bf432d217a4314e20f9c (patch)
tree347fdff38b22c460b5233be18b7483b5d3ebc084
parent7248a578c841312bfc00e0b74fede405e80e992c (diff)
Reimpl test as BehaviourTest: InvalidFirstPacketIsRejected
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs59
-rw-r--r--mqtt-tester/src/behaviour/mod.rs2
-rw-r--r--mqtt-tester/src/client_report.rs40
3 files changed, 62 insertions, 39 deletions
diff --git a/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs
new file mode 100644
index 0000000..a4c95ad
--- /dev/null
+++ b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs
@@ -0,0 +1,59 @@
+//
+// 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::MConnect, strings::MString};
+
+use crate::{
+ behaviour_test::BehaviourTest,
+ command::{Input, Output},
+ executable::ClientExecutableCommand,
+ report::ReportResult,
+};
+
+pub struct InvalidFirstPacketIsRejected;
+
+#[async_trait::async_trait]
+impl BehaviourTest for InvalidFirstPacketIsRejected {
+ fn commands(&self) -> Vec<Box<dyn ClientExecutableCommand>> {
+ vec![]
+ }
+
+ async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ input
+ .send_packet(MConnect {
+ protocol_name: MString { value: "foo" },
+ protocol_level: 0,
+ clean_session: true,
+ will: None,
+ username: None,
+ password: None,
+ keep_alive: 0,
+ client_id: MString { value: "client" },
+ })
+ .await?;
+ Ok(())
+ }
+
+ fn report_name(&self) -> &str {
+ "Check if invalid first packet is rejected"
+ }
+
+ fn report_desc(&self) -> &str {
+ "The first packet from the server must be a ConnAck. Any other packet is invalid and the client should close the connection"
+ }
+
+ fn report_normative(&self) -> &str {
+ "[MQTT-3.2.0-1]"
+ }
+
+ fn translate_client_exit_code(&self, success: bool) -> ReportResult {
+ if success {
+ ReportResult::Failure
+ } else {
+ ReportResult::Success
+ }
+ }
+}
diff --git a/mqtt-tester/src/behaviour/mod.rs b/mqtt-tester/src/behaviour/mod.rs
index b6fda19..4a15faf 100644
--- a/mqtt-tester/src/behaviour/mod.rs
+++ b/mqtt-tester/src/behaviour/mod.rs
@@ -4,10 +4,12 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
+pub mod invalid_first_packet_is_rejected;
pub mod invalid_utf8_is_rejected;
pub mod receiving_server_packet;
pub mod wait_for_connect;
+pub use self::invalid_first_packet_is_rejected::InvalidFirstPacketIsRejected;
pub use self::invalid_utf8_is_rejected::InvalidUtf8IsRejected;
pub use self::receiving_server_packet::ReceivingServerPacket;
pub use self::wait_for_connect::WaitForConnect;
diff --git a/mqtt-tester/src/client_report.rs b/mqtt-tester/src/client_report.rs
index 81fbf1c..4f3de51 100644
--- a/mqtt-tester/src/client_report.rs
+++ b/mqtt-tester/src/client_report.rs
@@ -33,7 +33,6 @@ pub async fn create_client_report(
let executable = ClientExecutable::new(client_exe_path);
let reports = vec![
- check_invalid_first_packet_is_rejected(&executable).boxed_local(),
check_utf8_with_nullchar_is_rejected(&executable).boxed_local(),
check_connack_flags_are_set_as_reserved(&executable).boxed_local(),
check_publish_qos_zero_with_ident_fails(&executable).boxed_local(),
@@ -50,6 +49,7 @@ pub async fn create_client_report(
Box::new(crate::behaviour::WaitForConnect),
Box::new(crate::behaviour::InvalidUtf8IsRejected),
Box::new(crate::behaviour::ReceivingServerPacket),
+ Box::new(crate::behaviour::InvalidFirstPacketIsRejected),
];
let invariants: Vec<Arc<dyn PacketInvariant>> = vec![Arc::new(NoUsernameMeansNoPassword)];
@@ -156,44 +156,6 @@ macro_rules! wait_for_output {
}};
}
-async fn check_invalid_first_packet_is_rejected(
- executable: &ClientExecutable,
-) -> miette::Result<Report> {
- let (client, mut input, _output) = executable
- .call(&[])
- .map(crate::command::Command::new)?
- .spawn()?;
-
- input
- .send_packet(MConnect {
- protocol_name: MString { value: "foo" },
- protocol_level: 0,
- clean_session: true,
- will: None,
- username: None,
- password: None,
- keep_alive: 0,
- client_id: MString { value: "client" },
- })
- .await?;
-
- let output = client.wait_with_output();
- let (result, output) = wait_for_output! {
- output,
- timeout_ms: 100,
- out_success => { ReportResult::Failure },
- out_failure => { ReportResult::Success }
- };
-
- Ok(mk_report! {
- name: "Check if invalid first packet is rejected",
- desc: "The first packet from the server must be a ConnAck. Any other packet is invalid and the client should close the connection",
- normative: "[MQTT-3.2.0-1]",
- result,
- output
- })
-}
-
async fn check_utf8_with_nullchar_is_rejected(
executable: &ClientExecutable,
) -> miette::Result<Report> {