-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: suback Error Codes Handling #1887
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1887 +/- ##
==========================================
+ Coverage 80.96% 81.19% +0.23%
==========================================
Files 24 24
Lines 1408 1452 +44
Branches 331 340 +9
==========================================
+ Hits 1140 1179 +39
- Misses 185 188 +3
- Partials 83 85 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please add a unit test for this
The linter seems to have a problem with passing the error object to the callback
Which might be why this error was not passed in the first place. I am not sure why this is an error, given error is defined at the beginning of the method. Do we need to explicitly define this as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, please add a test for this and then I will merge
@robertsLando It seems like there is test coverage for the immediate subscribe method and the validation of the topic strings. This may be redundant as there is a return code for the MQTT Broker to do this validation and reject the subscription request as well. I think I found similar tests in it('should return an error (via callbacks) for topic it does not have access to', function _test(t, done) {
const client = connect()
client.subscribe('$SYS/#', (subErr) => {
client.end(true, (endErr) => {
if (subErr) {
return done(endErr)
}
done(new Error('Suback errors do NOT work'))
})
})
}) The output of this test is the following:
Since the topic filters are validated on the client side and don't get sent to the broker, I cannot set an invalid topic string to initate an error subnack from the broker. Other possible suback errors are listed here: #1886 What is the recommended way to emulate the suback packet or set an Access Control List (ACL) for the test broker? The suback packet I am getting from my test environment and would like to emulate is
|
I was able to find what I was looking for from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should also check that the error
event to be emitted as it was not before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsteinholz It's good now just remember to fix lint issues npm run lint-fix
Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>
Head branch was pushed to by a user without write access
Seems like the new unit test is passing:
Not exactly sure why the unit test suite are timing out
Seems like there is some side-effects added in the test suite. Is there a timeout configured in the test and adding the new test is making it take too long to execute? |
Increased timeout from 60 seconds / 1 minute to 90 seconds / 1 minute and 30 seconds. |
@tsteinholz it's not a timeout problem it's tests that are flacky, could you remove the change to timeout please? When I notice them are failing because of their "flackyness" I simply re-run them |
This reverts commit d648ee1.
@tsteinholz test was wrong, because it was running on both v5 and v3.1 tests and that reason codes are only supported in v5 |
@robertsLando While reason codes are only supported in the v5 specification. The v3 specification still returns an error, it's just always a "Unspecified Error". The v3 test would just need to be validating that 0x80 returns an "Unspecified Error". http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718068 |
@tsteinholz Yeah I know that but if I return 135 in granted the mqtt parser doens't like the packet and rejects it with protocol 3/4 (that's why test were failing) so I simply prefer to run this in mqtt v5 tests |
Now the error creates the expected Exception with detail and is available from all error callbacks, consistent with the rest of the library.
Test Cases
Subscribing to Unauthorized topic
Subscribing to authorized topic