Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 84 additions & 68 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ test('authorize publish', function (t) {
cb()
})

s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
})
})
})

Expand Down Expand Up @@ -397,10 +399,12 @@ test('authorize waits for authenticate', function (t) {
keepalive: 0
})

s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
})
})
})

Expand Down Expand Up @@ -434,11 +438,12 @@ test('authorize publish from configOptions', function (t) {
t.deepEqual(packet, expected, 'packet matches')
cb()
})

s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
})
})
})

Expand Down Expand Up @@ -466,10 +471,12 @@ test('do not authorize publish', function (t) {
t.pass('ended')
})

s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world'
})
})
})

Expand All @@ -486,8 +493,9 @@ test('authorize subscribe', function (t) {
}, 'topic matches')
cb(null, sub)
}

subscribe(t, s, 'hello', 0)
s.broker.once('clientReady', () => {
subscribe(t, s, 'hello', 0)
})
})

test('authorize subscribe multiple same topics with same qos', function (t) {
Expand All @@ -502,8 +510,9 @@ test('authorize subscribe multiple same topics with same qos', function (t) {
}, 'topic matches')
cb(null, sub)
}

subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'hello', qos: 0 }], [0])
s.broker.once('clientReady', () => {
subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'hello', qos: 0 }], [0])
})
})

test('authorize subscribe multiple same topics with different qos', function (t) {
Expand All @@ -518,8 +527,9 @@ test('authorize subscribe multiple same topics with different qos', function (t)
}, 'topic matches')
cb(null, sub)
}

subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'hello', qos: 1 }], [1])
s.broker.once('clientReady', () => {
subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'hello', qos: 1 }], [1])
})
})

test('authorize subscribe multiple different topics', function (t) {
Expand All @@ -542,8 +552,9 @@ test('authorize subscribe multiple different topics', function (t) {
}
cb(null, sub)
}

subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'foo', qos: 0 }], [0, 0])
s.broker.once('clientReady', () => {
subscribeMultiple(t, s, [{ topic: 'hello', qos: 0 }, { topic: 'foo', qos: 0 }], [0, 0])
})
})

test('authorize subscribe from config options', function (t) {
Expand All @@ -559,8 +570,9 @@ test('authorize subscribe from config options', function (t) {
cb(null, sub)
}
})))

subscribe(t, s, 'hello', 0)
s.broker.once('clientReady', () => {
subscribe(t, s, 'hello', 0)
})
})

test('negate subscription', function (t) {
Expand All @@ -576,14 +588,15 @@ test('negate subscription', function (t) {
}, 'topic matches')
cb(null, null)
}

s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}]
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}]
})
})

s.outStream.once('data', function (packet) {
Expand All @@ -602,17 +615,18 @@ test('negate multiple subscriptions', function (t) {
t.ok(client, 'client exists')
cb(null, null)
}

s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
})
})

s.outStream.once('data', function (packet) {
Expand Down Expand Up @@ -651,17 +665,18 @@ test('negate subscription with correct persistence', function (t) {
})
t.equal(packet.messageId, 24)
})

s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
})
})
})

Expand All @@ -680,17 +695,18 @@ test('negate multiple subscriptions random times', function (t) {
cb(null, null)
}
}

s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
s.broker.once('clientReady', () => {
s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
})
})

s.outStream.once('data', function (packet) {
Expand Down
Loading