Closed mefly2012 closed 8 months ago
我用paho.mqtt.testing测试了,这个问题确实存在,我看看是哪里出问题了。 I have tested it using paho.mqtt.testing, and indeed, there is an issue. I'll take a look to see where the problem is.
@mefly2012 我用mosquitto作为broker也同样存在这个问题,我看了paho client_test.py的代码:
nosubscribe_topics = ("test/nosubscribe",)
//...
def test_subscribe_failure(self):
# Subscribe failure. A new feature of MQTT 3.1.1 is the ability to send back negative reponses to subscribe
# requests. One way of doing this is to subscribe to a topic which is not allowed to be subscribed to.
print("Subscribe failure test starting")
succeeded = True
try:
callback.clear()
aclient.connect(host=host, port=port, keepalive=60)
print('topic:', nosubscribe_topics[0])
aclient.subscribe([nosubscribe_topics[0]], [2])
time.sleep(.2)
# subscribeds is a list of (msgid, [qos])
assert callback.subscribeds[0][1][0] == 0x80, "return code should be 0x80 %s" % callback.subscribeds
except:
traceback.print_exc()
succeeded = False
print("Subscribe failure test", "succeeded" if succeeded else "failed")
self.assertEqual(succeeded, True)
return succeeded
意思这个主题test/nosubscribe在broker要设置成不被允许订阅的主题时,SUBACK包里面的 code应该返回0x80表示订阅失败。 Allowed return codes: 0x00 - Success - Maximum QoS 0 0x01 - Success - Maximum QoS 1 0x02 - Success - Maximum QoS 2 0x80 - Failure
你可以使用ACL限制客户端订阅test/nosubscribe这个主题应该就能通过测试用例了。 I encountered the same issue when using Mosquitto as a broker.I examined the code in the paho client_test.py file. When the topic "test/nosubscribe" is set on the broker to disallow subscription, the code in the SUBACK packet should return 0x80 to indicate a subscription failure. You can use ACL to restrict client subscription to the topic "test/nosubscribe," and this should pass the test case.
@mefly2012 Has there been any progress on this issue? Can it be closed now?
谢谢你的讲解,auth.yaml配置文件如下,即可跑完所有用例。 这里这个auth控制一定要填东西,ip地址的模糊匹配似乎不能填:,所以搞个10.*
- remote: 10.*:*
allow: true
acl:
#0 = deny, 1 = read only, 2 = write only, 3 = read and write
- filters:
'test/nosubscribe': 0```
用例说是3.1.1新特性,不清楚是不是哪儿没配置正确。