kopia lustrzana https://github.com/Yakifo/amqtt
test cases: Add fixture for ACL-enabled test server
This uses the real plug-ins to test the broker correctly responds to the return values when publishing and subscribing. The plug-ins themselves are tested elsewhere.pull/69/head
rodzic
f30aa9245d
commit
33531c2f23
|
@ -1,4 +1,5 @@
|
|||
import unittest.mock
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -15,6 +16,39 @@ test_config = {
|
|||
}
|
||||
|
||||
|
||||
test_config_acl = {
|
||||
"listeners": {
|
||||
"default": {"type": "tcp", "bind": "127.0.0.1:1884", "max_connections": 10},
|
||||
},
|
||||
"sys_interval": 0,
|
||||
"auth": {
|
||||
"plugins": ["auth_file"],
|
||||
"password-file": os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
'plugins',
|
||||
'passwd'
|
||||
)
|
||||
},
|
||||
"topic-check": {
|
||||
"enabled": True,
|
||||
"plugins": ["topic_acl"],
|
||||
"acl": {
|
||||
"user1": [
|
||||
"public/#"
|
||||
],
|
||||
"user2": [
|
||||
"#"
|
||||
],
|
||||
},
|
||||
"publish-acl": {
|
||||
"user1": [
|
||||
"public/subtopic/#"
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_plugin_manager():
|
||||
with unittest.mock.patch("amqtt.broker.PluginManager") as plugin_manager:
|
||||
|
@ -36,3 +70,17 @@ async def broker(mock_plugin_manager):
|
|||
|
||||
if not broker.transitions.is_stopped():
|
||||
await broker.shutdown()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def acl_broker():
|
||||
broker = amqtt.broker.Broker(test_config_acl, plugin_namespace="amqtt.broker.plugins")
|
||||
await broker.start()
|
||||
assert broker.transitions.is_started()
|
||||
assert broker._sessions == {}
|
||||
assert "default" in broker._servers
|
||||
|
||||
yield broker
|
||||
|
||||
if not broker.transitions.is_stopped():
|
||||
await broker.shutdown()
|
||||
|
|
Ładowanie…
Reference in New Issue