Skip to content

Commit c6d3ebc

Browse files
committed
chore: initial test commit
1 parent fda257d commit c6d3ebc

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

src/config/acl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{path::Path, str::FromStr};
22

33
use tashi_collections::HashMap;
44

5-
use crate::mqtt::trie::{Filter, TopicName};
5+
use crate::mqtt::trie::Filter;
66

77
#[derive(serde::Deserialize, Default)]
88
pub struct AclConfig {

src/mqtt/broker/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub struct TlsConfig {
171171
}
172172

173173
impl MqttBroker {
174+
#[allow(clippy::too_many_arguments)]
174175
pub async fn bind(
175176
listen_addr: SocketAddr,
176177
tls_config: Option<TlsConfig>,

src/mqtt/trie/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151

5252
// fixme: This iterator is very inefficient (O(n) scans per tree depth) but it probably doesn't matter because this is a Debug impl.
5353
// it's O(1) memory usage though.
54-
impl<'a, T> Iterator for Iter<'a, T> {
54+
impl<T> Iterator for Iter<'_, T> {
5555
type Item = NodeId;
5656

5757
fn next(&mut self) -> Option<Self::Item> {

tests/foxmq.d/cla.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[permissions.test_user1]
2+
topic = [{ filter = "topic", allowed = ["publish"] }]
3+
4+
5+
[permissions.test_user2]
6+
topic = [{ filter = "topic", allowed = ["subscribe"] }]

tests/foxmq.d/users.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
[auth]
22
allow-anonymous-login = true
3+
4+
[users.test_user1]
5+
password-hash = "$argon2id$v=19$m=19456,t=2,p=1$TwFLGuZeIBQGjn02H9NpJQ$8s2JrmbxhLfHphYEfmZ4KjJmxS7tTCss06E27kZC6M0"
6+
7+
[users.test_user2]
8+
password-hash = "$argon2id$v=19$m=19456,t=2,p=1$TwFLGuZeIBQGjn02H9NpJQ$8s2JrmbxhLfHphYEfmZ4KjJmxS7tTCss06E27kZC6M0"

tests/mqtt/distribution.test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("publish to node 1, receive from node2", () => {
113113
test("synchronously, over Websockets", async () => {
114114
// Test v4 (3.1.1) and v5 (5.0) simultaneously
115115
const client1 = await mqtt.connectAsync("ws://127.0.0.1:8080", { protocolVersion: 4 });
116-
const client2 = await mqtt.connectAsync("ws://127.0.0.1:8081", {protocolVersion: 5});
116+
const client2 = await mqtt.connectAsync("ws://127.0.0.1:8081", { protocolVersion: 5 });
117117

118118
await client2.subscribeAsync("weather/los_angeles");
119119

@@ -267,5 +267,27 @@ describe("publish to node 1, receive from node2", () => {
267267

268268
await client1.endAsync();
269269
await client2.endAsync();
270-
});
270+
}),
271+
test("ACL", async () => {
272+
// Can publish to test_topic but not subscribe
273+
const client1 = await mqtt.connectAsync("mqtt://localhost:1884", { protocolVersion: 5, username: "test_user1", password: "1234" });
274+
// Can subscribe to test_topic but not publish
275+
const client2 = await mqtt.connectAsync("mqtt://localhost:1884", { protocolVersion: 5, username: "test_user2", password: "1234" });
276+
// Can do anything anywhere
277+
const client3 = await mqtt.connectAsync("mqtt://localhost:1884", { protocolVersion: 5 });
278+
279+
await client1.publishAsync("test_topic", "a test message");
280+
281+
const client_1_res = await client1.subscribe("test_topic");
282+
expect(client_1_res.reasonCode).toBe(1);
283+
284+
await client2.subscribe("test_topic");
285+
286+
const [topic, message] = await events.once(client2, 'message');
287+
288+
expect(topic.toString()).toBe("test_topic");
289+
expect(message.toString()).toBe("a test message");
290+
291+
})
292+
;
271293
});

0 commit comments

Comments
 (0)