Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Allow published messages on an unauthorised publish topic to be pubacked #638

Merged
merged 5 commits into from May 19, 2017

Conversation

btsimonh
Copy link
Contributor

@btsimonh btsimonh commented May 12, 2017

A simple change to the client which if passed success === 'ignore' (as a string) from the user's authorizePublish function, will puback the message but not publish it.

This solves an issue for me where if a message is published to an unauthorized topic, the broker in node-red is disconnected (and does not reconnect). Since the broker module in NR could be serving multiple clients, one rouge flow can kill all access to the MQTT server.

Of course, you can have no way to know your message was not published apart from custom server code...

It goes some way towards:
'Client connection closed if publish is not authorized #596'

example authorize function:

var authorizePublish = function(client, topic, payload, callback) {
  var auth = 'ignore';
  if (client.token){
    if (client.token.data){
      if (client.token.data.write){
        client.token.data.write.forEach(function(grant){
          if (grantvalid(topic, grant)){
            auth = true;
          }
          });
       }
    }
  }

  console.log("auth "+auth+" for Pub topic " + topic + " client allowed " + util.inspect(client.token));

  callback(null, auth);
}

…ked rather than disconnected,

activated by returning success === 'suppress' from authorizePublish.
Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer "ignore" instead of "suppress". Can you add a unit test?

@btsimonh
Copy link
Contributor Author

hmm.. struggling with tests. on windows is failing at
two instances
√ support restoring from disk
1) "after each" hook: deleteLevel for "support restoring from disk"

139 passing (11s)
1 failing

  1. mosca.persistence.LevelUp "after each" hook: deleteLevel for "support restoring from disk":
    Error: EBUSY: resource busy or locked, unlink 'C:\Users\Simon\AppData\Local\Temp\level_1494834462971\000005.ldb'
    at Error (native)

not familiar with testing schemes.. leave it with me for a few days. if i can move my tests above this, maybe a I can get one in.

@btsimonh
Copy link
Contributor Author

hmm.. all done here too I think. Travis playing silly b****s.

@mcollina mcollina merged commit c4303c5 into moscajs:master May 19, 2017
@btsimonh btsimonh deleted the btsimonh-unauthpub branch May 19, 2017 17:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants