Skip to content
Merged
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
10 changes: 6 additions & 4 deletions forge/ee/lib/projectComms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ module.exports.init = function (app) {
)
// Receive messages sent to this device (instance owned)
// - ff/v1/<team>/p/<project>/in/+/#
// project = the instance the device is assigned to
app.comms.aclManager.addACL(
'device',
'sub',
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/in\/[^/]+($|\/.*$)$/, verify: 'checkDeviceCanAccessProject' }
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/in\/[^/]+($|\/.*$)$/, verify: 'checkDeviceAssignedToProject' }
)
// Receive messages sent to this device (app owned)
// - ff/v1/<team>/p/dev:<deviceid>/in/+/#
Expand All @@ -95,10 +96,11 @@ module.exports.init = function (app) {
)
// Receive link-call response messages sent to this device (instance owned)
// - ff/v1/<team>/p/<project>/res/+/#
// project = the instance the device is assigned to
app.comms.aclManager.addACL(
'device',
'sub',
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/res\/[^/]+($|\/.*$)$/, verify: 'checkDeviceCanAccessProject', deviceOwnerType: 'instance' }
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/res\/[^/]+($|\/.*$)$/, verify: 'checkDeviceAssignedToProject' }
)
// Receive link-call response messages sent to this device (app owned)
// - ff/v1/<team>/p/dev:<deviceid>/res/+/#
Expand All @@ -121,12 +123,12 @@ module.exports.init = function (app) {
'pub',
{ topic: /^ff\/v1\/([^/]+)\/p\/dev:([^/]+)\/in\/[^/]+($|\/.*$)/, verify: 'checkDeviceIsAssigned' }
)
// Send broadcast messages (from instance owned devices in the team)
// Send broadcast messages (from instance owned devices, as the instance they are assigned to)
// - ff/v1/<team>/p/<project>/out/+/#
app.comms.aclManager.addACL(
'device',
'pub',
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/out\/[^/]+($|\/.*$)/, verify: 'checkDeviceCanAccessProject', deviceOwnerType: 'instance' }
{ topic: /^ff\/v1\/([^/]+)\/p\/(?!dev:)([^/]+)\/out\/[^/]+($|\/.*$)/, verify: 'checkDeviceAssignedToProject' }
)
// Send broadcast messages (from app owned devices in the team)
// - ff/v1/<team>/p/dev:<deviceid>/out/+/#
Expand Down
4 changes: 2 additions & 2 deletions forge/routes/api/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ module.exports = async function (app) {
includeSettings: true,
includeMeta
})
if (request.session.ownerType === 'project') {
// This request is from a project token. Filter the list to return
if (request.session.ownerType === 'project' || request.session.ownerType === 'device') {
// This request is from a project or device token. Filter the list to return
// the minimal information needed
result = result.map(e => {
return { id: e.id, name: e.name }
Expand Down
4 changes: 2 additions & 2 deletions test/unit/forge/comms/authRoutesV2_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ describe('Broker Auth v2 API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/a/${TestObjects.ApplicationA.hashid}/command`
})
})
it('can subscribe to project inbox', async function () {
await allowRead({
it('cannot subscribe to project inbox', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/in/foo`
})
Expand Down
190 changes: 188 additions & 2 deletions test/unit/forge/comms/authRoutes_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,76 @@ describe('Broker Auth API', async function () {
topic: 'ff/v1/abc/p/dev:some-device/in/foo'
})
})
it('allows project to publish to an app owned device response topic', async function () {
await allowWrite({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/dev:some-device/res/foo'
})
})
it('prevents project from subscribing to another projects response topic', async function () {
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/another-project/res/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/another-project/res-random/foo'
})
})
it('prevents project from subscribing to inbox or response topics with a wildcard', async function () {
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/+/in/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: '$share/xyz/ff/v1/abc/p/+/in/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/+/res/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/+/res-random/foo'
})
})
it('prevents project from publishing broadcast as an app owned device', async function () {
await denyWrite({
username: 'project:abc:xyz',
topic: 'ff/v1/abc/p/dev:some-device/out/foo'
})
})
it('prevents project from using another teams project link topics', async function () {
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/another-project/out/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: '$share/xyz/ff/v1/other-team/p/+/out/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/xyz/in/foo'
})
await denyRead({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/xyz/res/foo'
})
await denyWrite({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/xyz/out/foo'
})
await denyWrite({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/another-project/in/foo'
})
await denyWrite({
username: 'project:abc:xyz',
topic: 'ff/v1/other-team/p/another-project/res/foo'
})
})
describe('application scoped broadcast', async function () {
let projectUsername
let appTopicPrefix
Expand Down Expand Up @@ -874,6 +944,24 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/in/foo`
})
})
it('cannot subscribe to another project inbox', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectB.id}/in/foo`
})
})
it('can subscribe to project response if assigned', async function () {
await allowRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/res/foo`
})
})
it('cannot subscribe to another project response', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectB.id}/res/foo`
})
})
it('can subscribe to project broadcast if assigned', async function () {
await allowRead({
username: deviceUsername,
Expand All @@ -898,6 +986,12 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/out/foo`
})
})
it('cannot publish to another project output', async function () {
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectB.id}/out/foo`
})
})
it('can publish to project response if assigned', async function () {
await allowWrite({
username: deviceUsername,
Expand Down Expand Up @@ -946,6 +1040,43 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/a/${TestObjects.ApplicationA.hashid}/p/${TestObjects.ProjectB.id}/out/foo`
})
})
it('can subscribe to app owned device broadcast', async function () {
await allowRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceB.hashid}/out/foo`
})
})
it('cannot subscribe to inbox or response topics with a wildcard', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/+/in/foo`
})
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/+/res/foo`
})
})
it('cannot subscribe to app owned device response topic', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceA.hashid}/res/foo`
})
})
it('cannot publish broadcast as an app owned device', async function () {
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceA.hashid}/out/foo`
})
})
it('cannot publish to project inbox in another team', async function () {
const otherTeam = await factory.createTeam({ name: 'other-team' })
const otherProject = await app.db.models.Project.create({ name: 'other-team-project', type: '', url: '' })
await otherTeam.addProject(otherProject)
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${otherProject.id}/in/foo`
})
})
})
describe('assigned to application', async function () {
before(async function () {
Expand Down Expand Up @@ -978,12 +1109,18 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/a/${TestObjects.ApplicationA.hashid}/command`
})
})
it('can subscribe to project inbox', async function () {
await allowRead({
it('cannot subscribe to project inbox', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/in/foo`
})
})
it('cannot subscribe to project response', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/res/foo`
})
})
it('can subscribe to project broadcast', async function () {
await allowRead({
username: deviceUsername,
Expand Down Expand Up @@ -1020,6 +1157,12 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:invalid dev id/out/foo`
})
})
it('cannot publish broadcast as a project', async function () {
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${TestObjects.ProjectA.id}/out/foo`
})
})
it('can publish broadcast with `dev:` topic prefix', async function () {
await allowWrite({
username: deviceUsername,
Expand Down Expand Up @@ -1089,6 +1232,49 @@ describe('Broker Auth API', async function () {
topic: `ff/v1/${TestObjects.ATeam.hashid}/a/${TestObjects.ApplicationA.hashid}/p/${TestObjects.ProjectA.id}/out/foo`
})
})
it('can subscribe to own response topic', async function () {
await allowRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceA.hashid}/res/foo`
})
})
it('cannot subscribe to another device response topic', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceB.hashid}/res/foo`
})
})
it('can subscribe to app owned device broadcast', async function () {
await allowRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceB.hashid}/out/foo`
})
})
it('cannot subscribe to inbox or response topics with a wildcard', async function () {
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/+/in/foo`
})
await denyRead({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/+/res/foo`
})
})
it('cannot publish broadcast as another device', async function () {
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/dev:${TestObjects.DeviceB.hashid}/out/foo`
})
})
it('cannot publish to project inbox in another team', async function () {
const otherTeam = await factory.createTeam({ name: 'other-team-2' })
const otherProject = await app.db.models.Project.create({ name: 'other-team-project-2', type: '', url: '' })
await otherTeam.addProject(otherProject)
await denyWrite({
username: deviceUsername,
topic: `ff/v1/${TestObjects.ATeam.hashid}/p/${otherProject.id}/in/foo`
})
})
})
describe('device log topics', async function () {
it('can publish its logs', async function () {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/forge/routes/api/team_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,10 @@ describe('Team API', function () {
const result = response.json()
result.should.have.property('projects').and.be.an.Array()
result.projects.should.have.a.property('length', 4)
// Only the minimal information is returned to a device
result.projects.forEach(project => {
Object.keys(project).should.eql(['id', 'name'])
})
})

it('Device can not get a list of team projects without a valid token', async function () {
Expand Down
Loading