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
9 changes: 4 additions & 5 deletions forge/comms/aclManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,18 +881,17 @@ module.exports = function (app) {
]
},
frontend: {
// TODO check the verify function is safe
sub: [
// - ff/v1/<team>/d/<device/logs
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/logs$/, verify: 'checkDeviceIsAssigned' },
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/logs$/, verify: 'checkTeamAndObjectIds' },
// - ff/v1/<team>/d/<device/resources
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/resources$/, verify: 'checkDeviceIsAssigned' }
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/resources$/, verify: 'checkTeamAndObjectIds' }
],
pub: [
// - ff/v1/<team>/d/<device/logs/heartbeat
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/logs\/heartbeat$/, verify: 'checkDeviceIsAssigned' },
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/logs\/heartbeat$/, verify: 'checkTeamAndObjectIds' },
// - ff/v1/<team>/d/<device/resources/heartbeat
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/resources\/heartbeat$/, verify: 'checkDeviceIsAssigned' }
{ topic: /^ff\/v1\/([^/]+)\/d\/([^/]+)\/resources\/heartbeat$/, verify: 'checkTeamAndObjectIds' }
]
},
// browser-side team channel (per-tab, per-team)
Expand Down
30 changes: 30 additions & 0 deletions test/unit/forge/comms/authRoutesV2_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,36 @@ describe('Broker Auth v2 API', async function () {
topic: `${frontendTopic}/heartbeat`
})
})
it('frontend can subscribe to own device resources', async function () {
const resourcesTopic = `ff/v1/${TestObjects.ATeam.hashid}/d/${TestObjects.DeviceB.hashid}/resources`
await allowRead({ username: frontendUsername, topic: resourcesTopic })
await allowWrite({ username: frontendUsername, topic: `${resourcesTopic}/heartbeat` })
})
it('frontend for an unassigned device can subscribe to its own logs', async function () {
const device = await factory.createDevice({ name: 'unassigned log device', type: 'test device' }, TestObjects.ATeam, null, null)
await allowRead({
username: `frontend:${TestObjects.ATeam.hashid}:${device.hashid}`,
topic: `ff/v1/${TestObjects.ATeam.hashid}/d/${device.hashid}/logs`
})
})
it('frontend cannot subscribe to another device\'s logs', async function () {
await denyRead({ username: frontendUsername, topic: deviceLogTopic })
})
it('frontend cannot subscribe to another device\'s resources', async function () {
await denyRead({ username: frontendUsername, topic: `ff/v1/${TestObjects.ATeam.hashid}/d/${TestObjects.DeviceA.hashid}/resources` })
})
it('frontend cannot subscribe to all device logs', async function () {
await denyRead({ username: frontendUsername, topic: `ff/v1/${TestObjects.ATeam.hashid}/d/+/logs` })
})
it('frontend cannot subscribe to another team\'s device logs', async function () {
await denyRead({ username: frontendUsername, topic: `ff/v1/other-team/d/${TestObjects.DeviceB.hashid}/logs` })
await denyRead({ username: frontendUsername, topic: `ff/v1/+/d/${TestObjects.DeviceB.hashid}/logs` })
})
it('frontend cannot publish another device\'s heartbeats', async function () {
const otherDevice = `ff/v1/${TestObjects.ATeam.hashid}/d/${TestObjects.DeviceA.hashid}`
await denyWrite({ username: frontendUsername, topic: `${otherDevice}/logs/heartbeat` })
await denyWrite({ username: frontendUsername, topic: `${otherDevice}/resources/heartbeat` })
})
})
})
})
Expand Down
Loading