kopia lustrzana https://github.com/Yakifo/amqtt
Pass code through `black` formatter
rodzic
29854264e3
commit
bf5279911b
|
@ -45,8 +45,8 @@ EVENT_BROKER_MESSAGE_RECEIVED = "broker_message_received"
|
|||
|
||||
|
||||
class Action(Enum):
|
||||
subscribe = 'subscribe'
|
||||
publish = 'publish'
|
||||
subscribe = "subscribe"
|
||||
publish = "publish"
|
||||
|
||||
|
||||
class BrokerException(Exception):
|
||||
|
@ -629,12 +629,13 @@ class Broker:
|
|||
|
||||
# See if the user is allowed to publish to this topic.
|
||||
permitted = await self.topic_filtering(
|
||||
client_session, topic=app_message.topic, action=Action.publish
|
||||
client_session, topic=app_message.topic, action=Action.publish
|
||||
)
|
||||
if not permitted:
|
||||
self.logger.info(
|
||||
"%s forbidden TOPIC %s sent in PUBLISH message.",
|
||||
client_session.client_id, app_message.topic
|
||||
"%s forbidden TOPIC %s sent in PUBLISH message.",
|
||||
client_session.client_id,
|
||||
app_message.topic,
|
||||
)
|
||||
else:
|
||||
await self.plugins_manager.fire_event(
|
||||
|
@ -792,7 +793,9 @@ class Broker:
|
|||
# [MQTT-4.7.1-3] + wildcard character must occupy entire level
|
||||
return 0x80
|
||||
# Check if the client is authorised to connect to the topic
|
||||
permitted = await self.topic_filtering(session, topic=a_filter, action=Action.subscribe)
|
||||
permitted = await self.topic_filtering(
|
||||
session, topic=a_filter, action=Action.subscribe
|
||||
)
|
||||
if not permitted:
|
||||
return 0x80
|
||||
qos = subscription[1]
|
||||
|
|
|
@ -26,28 +26,18 @@ test_config_acl = {
|
|||
"auth": {
|
||||
"plugins": ["auth_file"],
|
||||
"password-file": os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
'plugins',
|
||||
'passwd'
|
||||
)
|
||||
os.path.dirname(os.path.realpath(__file__)), "plugins", "passwd"
|
||||
),
|
||||
},
|
||||
"topic-check": {
|
||||
"enabled": True,
|
||||
"plugins": ["topic_acl"],
|
||||
"acl": {
|
||||
"user1": [
|
||||
"public/#"
|
||||
],
|
||||
"user2": [
|
||||
"#"
|
||||
],
|
||||
"user1": ["public/#"],
|
||||
"user2": ["#"],
|
||||
},
|
||||
"publish-acl": {
|
||||
"user1": [
|
||||
"public/subtopic/#"
|
||||
]
|
||||
},
|
||||
}
|
||||
"publish-acl": {"user1": ["public/subtopic/#"]},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +66,9 @@ async def broker(mock_plugin_manager):
|
|||
|
||||
@pytest.fixture(scope="function")
|
||||
async def acl_broker():
|
||||
broker = amqtt.broker.Broker(test_config_acl, plugin_namespace="amqtt.broker.plugins")
|
||||
broker = amqtt.broker.Broker(
|
||||
test_config_acl, plugin_namespace="amqtt.broker.plugins"
|
||||
)
|
||||
await broker.start()
|
||||
assert broker.transitions.is_started()
|
||||
assert broker._sessions == {}
|
||||
|
|
|
@ -38,10 +38,7 @@ async def test_base_no_config(logdog):
|
|||
)
|
||||
|
||||
assert log_records[1].levelno == logging.WARN
|
||||
assert (
|
||||
log_records[1].message
|
||||
== "'auth' section not found in context configuration"
|
||||
)
|
||||
assert log_records[1].message == "'auth' section not found in context configuration"
|
||||
assert pile.is_empty()
|
||||
|
||||
|
||||
|
@ -63,10 +60,7 @@ async def test_base_empty_config(logdog):
|
|||
log_records = list(pile.drain(name="testlog"))
|
||||
assert len(log_records) == 1
|
||||
assert log_records[0].levelno == logging.WARN
|
||||
assert (
|
||||
log_records[0].message
|
||||
== "'auth' section not found in context configuration"
|
||||
)
|
||||
assert log_records[0].message == "'auth' section not found in context configuration"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -132,10 +126,7 @@ async def test_taboo_empty_config(logdog):
|
|||
== "'topic-check' section not found in context configuration"
|
||||
)
|
||||
assert log_records[1].levelno == logging.WARN
|
||||
assert (
|
||||
log_records[1].message
|
||||
== "'auth' section not found in context configuration"
|
||||
)
|
||||
assert log_records[1].message == "'auth' section not found in context configuration"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -331,10 +322,7 @@ async def test_taclp_empty_config(logdog):
|
|||
log_records[0].message
|
||||
== "'topic-check' section not found in context configuration"
|
||||
)
|
||||
assert (
|
||||
log_records[1].message
|
||||
== "'auth' section not found in context configuration"
|
||||
)
|
||||
assert log_records[1].message == "'auth' section not found in context configuration"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
@ -275,9 +275,7 @@ async def test_client_publish_acl_permitted(acl_broker):
|
|||
ret = await sub_client.connect("mqtt://user2:user2password@127.0.0.1:1884/")
|
||||
assert ret == 0
|
||||
|
||||
ret = await sub_client.subscribe(
|
||||
[("public/subtopic/test", QOS_0)]
|
||||
)
|
||||
ret = await sub_client.subscribe([("public/subtopic/test", QOS_0)])
|
||||
assert ret == [QOS_0]
|
||||
|
||||
pub_client = MQTTClient()
|
||||
|
@ -302,9 +300,7 @@ async def test_client_publish_acl_forbidden(acl_broker):
|
|||
ret = await sub_client.connect("mqtt://user2:user2password@127.0.0.1:1884/")
|
||||
assert ret == 0
|
||||
|
||||
ret = await sub_client.subscribe(
|
||||
[("public/forbidden/test", QOS_0)]
|
||||
)
|
||||
ret = await sub_client.subscribe([("public/forbidden/test", QOS_0)])
|
||||
assert ret == [QOS_0]
|
||||
|
||||
pub_client = MQTTClient()
|
||||
|
@ -315,7 +311,7 @@ async def test_client_publish_acl_forbidden(acl_broker):
|
|||
|
||||
try:
|
||||
await sub_client.deliver_message(timeout=1)
|
||||
assert False, 'Should not have worked'
|
||||
assert False, "Should not have worked"
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
pass
|
||||
|
||||
|
@ -333,14 +329,10 @@ async def test_client_publish_acl_permitted_sub_forbidden(acl_broker):
|
|||
ret = await sub_client2.connect("mqtt://user3:user3password@127.0.0.1:1884/")
|
||||
assert ret == 0
|
||||
|
||||
ret = await sub_client1.subscribe(
|
||||
[("public/subtopic/test", QOS_0)]
|
||||
)
|
||||
ret = await sub_client1.subscribe([("public/subtopic/test", QOS_0)])
|
||||
assert ret == [QOS_0]
|
||||
|
||||
ret = await sub_client2.subscribe(
|
||||
[("public/subtopic/test", QOS_0)]
|
||||
)
|
||||
ret = await sub_client2.subscribe([("public/subtopic/test", QOS_0)])
|
||||
assert ret == [0x80]
|
||||
|
||||
pub_client = MQTTClient()
|
||||
|
@ -353,7 +345,7 @@ async def test_client_publish_acl_permitted_sub_forbidden(acl_broker):
|
|||
|
||||
try:
|
||||
await sub_client2.deliver_message(timeout=1)
|
||||
assert False, 'Should not have worked'
|
||||
assert False, "Should not have worked"
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
pass
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue