kopia lustrzana https://github.com/Yakifo/amqtt
plugin.topic_checking tests: Fix code formatting.
Yes, too lazy to hold down shift when hitting the `'` key.pull/69/head
rodzic
18cf5cdd1e
commit
66568122c5
|
|
@ -212,18 +212,14 @@ def test_topic_ac_not_match_longer_acl():
|
||||||
"""
|
"""
|
||||||
Test TopicAccessControlListPlugin.topic_ac returns false if topics do not match and ACL topic is longer.
|
Test TopicAccessControlListPlugin.topic_ac returns false if topics do not match and ACL topic is longer.
|
||||||
"""
|
"""
|
||||||
assert (
|
assert TopicAccessControlListPlugin.topic_ac("topic", "topic/is/longer") is False
|
||||||
TopicAccessControlListPlugin.topic_ac("topic", "topic/is/longer") is False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_topic_ac_not_match_longer_rq():
|
def test_topic_ac_not_match_longer_rq():
|
||||||
"""
|
"""
|
||||||
Test TopicAccessControlListPlugin.topic_ac returns false if topics do not match and RQ topic is longer.
|
Test TopicAccessControlListPlugin.topic_ac returns false if topics do not match and RQ topic is longer.
|
||||||
"""
|
"""
|
||||||
assert (
|
assert TopicAccessControlListPlugin.topic_ac("topic/is/longer", "topic") is False
|
||||||
TopicAccessControlListPlugin.topic_ac("topic/is/longer", "topic") is False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_topic_ac_match_exact():
|
def test_topic_ac_match_exact():
|
||||||
|
|
@ -290,17 +286,15 @@ async def test_taclp_true_no_pub_acl():
|
||||||
"""
|
"""
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {"topic-check": {"enabled": True}}
|
||||||
'topic-check': {
|
|
||||||
'enabled': True
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='publish', session=session, topic='a/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="publish", session=session, topic="a/topic"
|
||||||
|
)
|
||||||
assert authorised is True
|
assert authorised is True
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -312,22 +306,19 @@ async def test_taclp_false_sub_no_topic():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'acl': {
|
"acl": {"anotheruser": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'anotheruser': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='subscribe', session=session, topic='')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="subscribe", session=session, topic=""
|
||||||
|
)
|
||||||
assert authorised is False
|
assert authorised is False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -339,22 +330,19 @@ async def test_taclp_false_sub_unknown_user():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'acl': {
|
"acl": {"anotheruser": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'anotheruser': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='subscribe', session=session, topic='allowed/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="subscribe", session=session, topic="allowed/topic"
|
||||||
|
)
|
||||||
assert authorised is False
|
assert authorised is False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -366,22 +354,19 @@ async def test_taclp_false_sub_no_permission():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'acl': {
|
"acl": {"user": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'user': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='subscribe', session=session, topic='forbidden/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="subscribe", session=session, topic="forbidden/topic"
|
||||||
|
)
|
||||||
assert authorised is False
|
assert authorised is False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -393,22 +378,19 @@ async def test_taclp_true_sub_permission():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'acl': {
|
"acl": {"user": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'user': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='subscribe', session=session, topic='allowed/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="subscribe", session=session, topic="allowed/topic"
|
||||||
|
)
|
||||||
assert authorised is True
|
assert authorised is True
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -420,22 +402,19 @@ async def test_taclp_true_pub_permission():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'publish-acl': {
|
"publish-acl": {"user": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'user': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = "user"
|
session.username = "user"
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='publish', session=session, topic='allowed/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="publish", session=session, topic="allowed/topic"
|
||||||
|
)
|
||||||
assert authorised is True
|
assert authorised is True
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -447,20 +426,17 @@ async def test_taclp_true_anon_sub_permission():
|
||||||
context = BaseContext()
|
context = BaseContext()
|
||||||
context.logger = DummyLogger()
|
context.logger = DummyLogger()
|
||||||
context.config = {
|
context.config = {
|
||||||
'topic-check': {
|
"topic-check": {
|
||||||
'enabled': True,
|
"enabled": True,
|
||||||
'acl': {
|
"acl": {"anonymous": ["allowed/topic", "another/allowed/topic/#"]},
|
||||||
'anonymous': [
|
}
|
||||||
'allowed/topic',
|
|
||||||
'another/allowed/topic/#'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
session.username = None
|
session.username = None
|
||||||
|
|
||||||
plugin = TopicAccessControlListPlugin(context)
|
plugin = TopicAccessControlListPlugin(context)
|
||||||
authorised = await plugin.topic_filtering(action='subscribe', session=session, topic='allowed/topic')
|
authorised = await plugin.topic_filtering(
|
||||||
|
action="subscribe", session=session, topic="allowed/topic"
|
||||||
|
)
|
||||||
assert authorised is True
|
assert authorised is True
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue