Skip to content
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

[bug] Failure to authorize old wills #767

Closed
friesendrywall opened this issue Jul 30, 2022 · 2 comments
Closed

[bug] Failure to authorize old wills #767

friesendrywall opened this issue Jul 30, 2022 · 2 comments
Labels

Comments

@friesendrywall
Copy link

System Information

  • Aedes: 0.47.0
  • NodeJS: Any
  • OS: Any

Describe the bug
Wills on startup are not authorized

To Reproduce
Steps to reproduce the behavior:
Add test to will.js and npm run test

Expected behavior
Wills should be authorized

This seems to me that it will require adding to the persistence layer, as extra client information will need to be added, namely any important information like username, etc that gets passed to the authorizePublish handler.

Here is a failing test example.

test('authorize old will in case of a crash', function (t) {
  t.plan(3)

  const persistence = memory()
  const will = {
    topic: 'mywill',
    payload: Buffer.from('last will'),
    qos: 0,
    retain: false
  }

  persistence.broker = {
    id: 'anotherBroker'
  }

  persistence.putWill({
    id: 'myClientId42'
  }, will, function (err) {
    t.error(err, 'no error')

    const interval = 10 // ms, so that the will check happens fast!
    const broker = aedes({
      persistence: persistence,
      heartbeatInterval: interval
    })
    let authorized = false
    broker.authorizePublish = function (client, packet, callback) {
      authorized = true
      callback(null)
    }

    t.teardown(broker.close.bind(broker))

    const start = Date.now()

    broker.mq.on('mywill', check)

    function check (packet, cb) {
      broker.mq.removeListener('mywill', check)
      t.ok(Date.now() - start >= 3 * interval, 'the will needs to be emitted after 3 heartbeats')
      t.equal(authorized, true, 'topic authorized')
      broker.mq.on('mywill', function (packet) {
        t.fail('the will must be delivered only once')
      })
      cb()
    }
  })
})
@robertsLando robertsLando changed the title [bug]Failure to authorize old wills [bug] Failure to authorize old wills Aug 1, 2022
@gnought gnought closed this as completed Aug 1, 2022
@friesendrywall
Copy link
Author

Why was this closed? I'm a bit confused, because the present code doesn't authorize these re-sent wills, or maybe that is ok.

@gnought
Copy link
Collaborator

gnought commented Aug 1, 2022

The #769 is merged to fix this issue. @friesendrywall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants