Skip to content

Commit 9cf029a

Browse files
committed
Fix missing properties.
1 parent 89c7890 commit 9cf029a

File tree

5 files changed

+222
-15
lines changed

5 files changed

+222
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.7.2
2+
3+
* Fix missing properties on CONNACK packet. #44
4+
15
# 0.7.1
26

37
* Add rust-version 1.86.0 to Cargo.toml. #41

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Add this to your `Cargo.toml`:
3838

3939
```toml
4040
[dependencies]
41-
mqtt-protocol-core = "0.7.1"
41+
mqtt-protocol-core = "0.7.2"
4242
```
4343

4444
### No-std Support
@@ -47,7 +47,7 @@ For `no_std` environments (embedded systems), disable the default `std` feature:
4747

4848
```toml
4949
[dependencies]
50-
mqtt-protocol-core = { version = "0.7.1", default-features = false }
50+
mqtt-protocol-core = { version = "0.7.2", default-features = false }
5151
```
5252

5353
Caveats:
@@ -64,15 +64,15 @@ The library supports several optional features that can be enabled/disabled as n
6464
```toml
6565
# Enable tracing support (independent of std)
6666
[dependencies]
67-
mqtt-protocol-core = { version = "0.7.1", default-features = false, features = ["tracing"] }
67+
mqtt-protocol-core = { version = "0.7.2", default-features = false, features = ["tracing"] }
6868

6969
# Use with std but without tracing
7070
[dependencies]
71-
mqtt-protocol-core = { version = "0.7.1", default-features = false, features = ["std"] }
71+
mqtt-protocol-core = { version = "0.7.2", default-features = false, features = ["std"] }
7272

7373
# Full-featured (std + tracing)
7474
[dependencies]
75-
mqtt-protocol-core = { version = "0.7.1", features = ["tracing"] }
75+
mqtt-protocol-core = { version = "0.7.2", features = ["tracing"] }
7676
```
7777

7878
### Small String Optimization (SSO) Features
@@ -87,11 +87,11 @@ This crate provides SSO features to optimize memory usage for small string and b
8787
```toml
8888
# Use specific SSO optimization level
8989
[dependencies]
90-
mqtt-protocol-core = { version = "0.7.1", features = ["sso-lv10"] }
90+
mqtt-protocol-core = { version = "0.7.2", features = ["sso-lv10"] }
9191

9292
# Combine with other features
9393
[dependencies]
94-
mqtt-protocol-core = { version = "0.7.1", features = ["std", "sso-lv20", "tracing"] }
94+
mqtt-protocol-core = { version = "0.7.2", features = ["std", "sso-lv20", "tracing"] }
9595
```
9696

9797
#### ⚠️ **Important: Feature Flag Propagation Requirement**
@@ -110,7 +110,7 @@ When your crate depends on `mqtt-protocol-core` and is used by other crates or a
110110
```toml
111111
# Your crate's Cargo.toml
112112
[dependencies]
113-
mqtt-protocol-core = { version = "0.7.1", features = ["sso-lv10"] }
113+
mqtt-protocol-core = { version = "0.7.2", features = ["sso-lv10"] }
114114

115115
[features]
116116
# You MUST re-export ALL SSO features to allow downstream configuration

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
//!
122122
//! ```toml
123123
//! [dependencies]
124-
//! mqtt-protocol-core = { version = "0.7.1", default-features = false }
124+
//! mqtt-protocol-core = { version = "0.7.2", default-features = false }
125125
//! ```
126126
//!
127127
//! **No-std usage example:**
@@ -173,15 +173,15 @@
173173
//! ```toml
174174
//! # Enable tracing support (independent of std)
175175
//! [dependencies]
176-
//! mqtt-protocol-core = { version = "0.7.1", default-features = false, features = ["tracing"] }
176+
//! mqtt-protocol-core = { version = "0.7.2", default-features = false, features = ["tracing"] }
177177
//!
178178
//! # Use with std but without tracing overhead
179179
//! [dependencies]
180-
//! mqtt-protocol-core = { version = "0.7.1", default-features = false, features = ["std"] }
180+
//! mqtt-protocol-core = { version = "0.7.2", default-features = false, features = ["std"] }
181181
//!
182182
//! # Full-featured (std + tracing)
183183
//! [dependencies]
184-
//! mqtt-protocol-core = { version = "0.7.1", features = ["tracing"] }
184+
//! mqtt-protocol-core = { version = "0.7.2", features = ["tracing"] }
185185
//! ```
186186
//!
187187
//! ### Small String Optimization (SSO) Features
@@ -208,11 +208,11 @@
208208
//! ```toml
209209
//! # Use specific SSO optimization level
210210
//! [dependencies]
211-
//! mqtt-protocol-core = { version = "0.7.1", features = ["sso-lv10"] }
211+
//! mqtt-protocol-core = { version = "0.7.2", features = ["sso-lv10"] }
212212
//!
213213
//! # Combine with other features
214214
//! [dependencies]
215-
//! mqtt-protocol-core = { version = "0.7.1", features = ["std", "sso-lv20", "tracing"] }
215+
//! mqtt-protocol-core = { version = "0.7.2", features = ["std", "sso-lv20", "tracing"] }
216216
//! ```
217217
//!
218218
//! #### ⚠️ **Critical: SSO Feature Flag Propagation**
@@ -234,7 +234,7 @@
234234
//! ```toml
235235
//! # Your crate's Cargo.toml
236236
//! [dependencies]
237-
//! mqtt-protocol-core = { version = "0.7.1", features = ["sso-lv10"] }
237+
//! mqtt-protocol-core = { version = "0.7.2", features = ["sso-lv10"] }
238238
//!
239239
//! [features]
240240
//! # MANDATORY: Re-export ALL SSO features to allow downstream configuration

src/mqtt/packet/v5_0/connack.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,14 @@ fn validate_connack_properties(props: &[Property]) -> Result<(), MqttError> {
844844
let mut count_assigned_client_identifier = 0;
845845
let mut count_topic_alias_maximum = 0;
846846
let mut count_reason_string = 0;
847+
let mut count_wildcard_subscription_available = 0;
848+
let mut count_subscription_identifier_available = 0;
849+
let mut count_shared_subscription_available = 0;
847850
let mut count_server_keep_alive = 0;
851+
let mut count_response_information = 0;
852+
let mut count_server_reference = 0;
853+
let mut count_authentication_method = 0;
854+
let mut count_authentication_data = 0;
848855
for prop in props {
849856
match prop {
850857
Property::SessionExpiryInterval(_) => count_session_expiry_interval += 1,
@@ -855,7 +862,18 @@ fn validate_connack_properties(props: &[Property]) -> Result<(), MqttError> {
855862
Property::AssignedClientIdentifier(_) => count_assigned_client_identifier += 1,
856863
Property::TopicAliasMaximum(_) => count_topic_alias_maximum += 1,
857864
Property::ReasonString(_) => count_reason_string += 1,
865+
Property::WildcardSubscriptionAvailable(_) => {
866+
count_wildcard_subscription_available += 1
867+
}
868+
Property::SubscriptionIdentifierAvailable(_) => {
869+
count_subscription_identifier_available += 1
870+
}
871+
Property::SharedSubscriptionAvailable(_) => count_shared_subscription_available += 1,
858872
Property::ServerKeepAlive(_) => count_server_keep_alive += 1,
873+
Property::ResponseInformation(_) => count_response_information += 1,
874+
Property::ServerReference(_) => count_server_reference += 1,
875+
Property::AuthenticationMethod(_) => count_authentication_method += 1,
876+
Property::AuthenticationData(_) => count_authentication_data += 1,
859877
Property::UserProperty(_) => {}
860878
_ => return Err(MqttError::ProtocolError),
861879
}
@@ -868,7 +886,14 @@ fn validate_connack_properties(props: &[Property]) -> Result<(), MqttError> {
868886
|| count_assigned_client_identifier > 1
869887
|| count_topic_alias_maximum > 1
870888
|| count_reason_string > 1
889+
|| count_wildcard_subscription_available > 1
890+
|| count_subscription_identifier_available > 1
891+
|| count_shared_subscription_available > 1
871892
|| count_server_keep_alive > 1
893+
|| count_response_information > 1
894+
|| count_server_reference > 1
895+
|| count_authentication_method > 1
896+
|| count_authentication_data > 1
872897
{
873898
return Err(MqttError::ProtocolError);
874899
}

tests/packet-v5_0-connack.rs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,162 @@ fn build_fail_valid_prop_rs_mt() {
195195
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
196196
}
197197

198+
#[test]
199+
fn build_fail_valid_prop_wsa_mt() {
200+
common::init_tracing();
201+
let err = mqtt::packet::v5_0::Connack::builder()
202+
.session_present(true)
203+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
204+
.props(vec![
205+
mqtt::packet::WildcardSubscriptionAvailable::new(1)
206+
.unwrap()
207+
.into(),
208+
mqtt::packet::WildcardSubscriptionAvailable::new(0)
209+
.unwrap()
210+
.into(),
211+
])
212+
.build()
213+
.unwrap_err();
214+
215+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
216+
}
217+
218+
#[test]
219+
fn build_fail_valid_prop_sia_mt() {
220+
common::init_tracing();
221+
let err = mqtt::packet::v5_0::Connack::builder()
222+
.session_present(true)
223+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
224+
.props(vec![
225+
mqtt::packet::SubscriptionIdentifierAvailable::new(1)
226+
.unwrap()
227+
.into(),
228+
mqtt::packet::SubscriptionIdentifierAvailable::new(0)
229+
.unwrap()
230+
.into(),
231+
])
232+
.build()
233+
.unwrap_err();
234+
235+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
236+
}
237+
238+
#[test]
239+
fn build_fail_valid_prop_ssa_mt() {
240+
common::init_tracing();
241+
let err = mqtt::packet::v5_0::Connack::builder()
242+
.session_present(true)
243+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
244+
.props(vec![
245+
mqtt::packet::SharedSubscriptionAvailable::new(1)
246+
.unwrap()
247+
.into(),
248+
mqtt::packet::SharedSubscriptionAvailable::new(0)
249+
.unwrap()
250+
.into(),
251+
])
252+
.build()
253+
.unwrap_err();
254+
255+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
256+
}
257+
258+
#[test]
259+
fn build_fail_valid_prop_ska_mt() {
260+
common::init_tracing();
261+
let err = mqtt::packet::v5_0::Connack::builder()
262+
.session_present(true)
263+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
264+
.props(vec![
265+
mqtt::packet::ServerKeepAlive::new(10).unwrap().into(),
266+
mqtt::packet::ServerKeepAlive::new(20).unwrap().into(),
267+
])
268+
.build()
269+
.unwrap_err();
270+
271+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
272+
}
273+
274+
#[test]
275+
fn build_fail_valid_prop_ri_mt() {
276+
common::init_tracing();
277+
let err = mqtt::packet::v5_0::Connack::builder()
278+
.session_present(true)
279+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
280+
.props(vec![
281+
mqtt::packet::ResponseInformation::new("info1")
282+
.unwrap()
283+
.into(),
284+
mqtt::packet::ResponseInformation::new("info2")
285+
.unwrap()
286+
.into(),
287+
])
288+
.build()
289+
.unwrap_err();
290+
291+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
292+
}
293+
294+
#[test]
295+
fn build_fail_valid_prop_sr_mt() {
296+
common::init_tracing();
297+
let err = mqtt::packet::v5_0::Connack::builder()
298+
.session_present(true)
299+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
300+
.props(vec![
301+
mqtt::packet::ServerReference::new("server1")
302+
.unwrap()
303+
.into(),
304+
mqtt::packet::ServerReference::new("server2")
305+
.unwrap()
306+
.into(),
307+
])
308+
.build()
309+
.unwrap_err();
310+
311+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
312+
}
313+
314+
#[test]
315+
fn build_fail_valid_prop_am_mt() {
316+
common::init_tracing();
317+
let err = mqtt::packet::v5_0::Connack::builder()
318+
.session_present(true)
319+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
320+
.props(vec![
321+
mqtt::packet::AuthenticationMethod::new("method1")
322+
.unwrap()
323+
.into(),
324+
mqtt::packet::AuthenticationMethod::new("method2")
325+
.unwrap()
326+
.into(),
327+
])
328+
.build()
329+
.unwrap_err();
330+
331+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
332+
}
333+
334+
#[test]
335+
fn build_fail_valid_prop_ad_mt() {
336+
common::init_tracing();
337+
let err = mqtt::packet::v5_0::Connack::builder()
338+
.session_present(true)
339+
.reason_code(mqtt::result_code::ConnectReasonCode::Success)
340+
.props(vec![
341+
mqtt::packet::AuthenticationData::new(b"data1")
342+
.unwrap()
343+
.into(),
344+
mqtt::packet::AuthenticationData::new(b"data2")
345+
.unwrap()
346+
.into(),
347+
])
348+
.build()
349+
.unwrap_err();
350+
351+
assert_eq!(err, mqtt::result_code::MqttError::ProtocolError);
352+
}
353+
198354
// build success tests
199355

200356
#[test]
@@ -216,6 +372,28 @@ fn build_succes_svalid_prop() {
216372
mqtt::packet::ReasonString::new("Connection successful")
217373
.unwrap()
218374
.into(),
375+
mqtt::packet::WildcardSubscriptionAvailable::new(1)
376+
.unwrap()
377+
.into(),
378+
mqtt::packet::SubscriptionIdentifierAvailable::new(1)
379+
.unwrap()
380+
.into(),
381+
mqtt::packet::SharedSubscriptionAvailable::new(1)
382+
.unwrap()
383+
.into(),
384+
mqtt::packet::ServerKeepAlive::new(30).unwrap().into(),
385+
mqtt::packet::ResponseInformation::new("response info")
386+
.unwrap()
387+
.into(),
388+
mqtt::packet::ServerReference::new("mqtt.example.com")
389+
.unwrap()
390+
.into(),
391+
mqtt::packet::AuthenticationMethod::new("SCRAM-SHA-256")
392+
.unwrap()
393+
.into(),
394+
mqtt::packet::AuthenticationData::new(b"auth_data")
395+
.unwrap()
396+
.into(),
219397
mqtt::packet::UserProperty::new("key1", "value1")
220398
.unwrap()
221399
.into(),

0 commit comments

Comments
 (0)