openvibers/openvibe.events Commits
Accept watch.* publishes from a svc:watch token (#14)
Changes
@@@ -21,7 +21,9 @@ const DEFAULT_SOURCES = ['live', 'media', 'network', 'community', 'chat', 'openr// Publication products (Waves 16-19): each publishes <product>.<type>.<action> via openvibe-publishing.'wiki', 'blog', 'news', 'reviews', 'deals', 'coupons', 'trade',// Robot control (OpenVibe.Bot): bot.robot.*, bot.estop.*, bot.command.*-- 'bot'];++ 'bot',++ // Watch (OpenVibe.Watch): watch.observation.recorded, watch.watch.triggered, watch.check.failed++ 'watch'];/*** Namespaces that belong to the network rather than to one service. `provider.*` carries storage@@@ -103,6 +103,20 @@ t('a bot service principal publishes bot.* only', async () => {assert.strictEqual(r.body.code, 'events.type_not_allowed');});++t('a watch service principal publishes watch.* only', async () => {++ const watch = serviceToken('watch', ['events.event.publish']);++ // Real ids from openvibe-contracts (Watch, v0.102.0+): watch.watch.triggered, not watch.triggered.++ let r = await request(h.base, 'POST', '/api/v1/events', { token: watch, body: envelope('watch', { event_type: 'watch.watch.triggered' }) });++ assert.strictEqual(r.status, 201, r.text);++ r = await request(h.base, 'POST', '/api/v1/events', { token: watch, body: envelope('watch', { event_type: 'live.stream.started' }) });++ assert.strictEqual(r.status, 403);++ assert.strictEqual(r.body.code, 'events.type_not_allowed');++ // A source not in the list cannot claim the watch namespace.++ r = await request(h.base, 'POST', '/api/v1/events', { token: serviceToken('stranger', ['events.event.publish']), body: envelope('stranger', { event_type: 'watch.watch.triggered' }) });++ assert.strictEqual(r.status, 403);++ assert.strictEqual(r.body.code, 'events.unknown_source');++});++t('unknown source (not in the manifest map) -> 403', async () => {const r = await request(h.base, 'POST', '/api/v1/events', { token: serviceToken('stranger', ['events.event.publish']), body: envelope('stranger') });assert.strictEqual(r.status, 403);
@@ -21,7 +21,9 @@ const DEFAULT_SOURCES = ['live', 'media', 'network', 'community', 'chat', 'openr
@@ -21,7 +21,9 @@ const DEFAULT_SOURCES = ['live', 'media', 'network', 'community', 'chat', 'openr
// Publication products (Waves 16-19): each publishes <product>.<type>.<action> via openvibe-publishing.
// Publication products (Waves 16-19): each publishes <product>.<type>.<action> via openvibe-publishing.
'wiki', 'blog', 'news', 'reviews', 'deals', 'coupons', 'trade',
'wiki', 'blog', 'news', 'reviews', 'deals', 'coupons', 'trade',
// Robot control (OpenVibe.Bot): bot.robot.*, bot.estop.*, bot.command.*
// Robot control (OpenVibe.Bot): bot.robot.*, bot.estop.*, bot.command.*
- 'bot'];
+ 'bot',
+ // Watch (OpenVibe.Watch): watch.observation.recorded, watch.watch.triggered, watch.check.failed
+ 'watch'];
/**
/**
* Namespaces that belong to the network rather than to one service. `provider.*` carries storage
* Namespaces that belong to the network rather than to one service. `provider.*` carries storage
@@ -103,6 +103,20 @@ t('a bot service principal publishes bot.* only', async () => {
@@ -103,6 +103,20 @@ t('a bot service principal publishes bot.* only', async () => {
assert.strictEqual(r.body.code, 'events.type_not_allowed');
assert.strictEqual(r.body.code, 'events.type_not_allowed');
});
});
+t('a watch service principal publishes watch.* only', async () => {
+ const watch = serviceToken('watch', ['events.event.publish']);
+ // Real ids from openvibe-contracts (Watch, v0.102.0+): watch.watch.triggered, not watch.triggered.
+ let r = await request(h.base, 'POST', '/api/v1/events', { token: watch, body: envelope('watch', { event_type: 'watch.watch.triggered' }) });
+ assert.strictEqual(r.status, 201, r.text);
+ r = await request(h.base, 'POST', '/api/v1/events', { token: watch, body: envelope('watch', { event_type: 'live.stream.started' }) });
+ assert.strictEqual(r.status, 403);
+ assert.strictEqual(r.body.code, 'events.type_not_allowed');
+ // A source not in the list cannot claim the watch namespace.
+ r = await request(h.base, 'POST', '/api/v1/events', { token: serviceToken('stranger', ['events.event.publish']), body: envelope('stranger', { event_type: 'watch.watch.triggered' }) });
+ assert.strictEqual(r.status, 403);
+ assert.strictEqual(r.body.code, 'events.unknown_source');
+});
+
t('unknown source (not in the manifest map) -> 403', async () => {
t('unknown source (not in the manifest map) -> 403', async () => {
const r = await request(h.base, 'POST', '/api/v1/events', { token: serviceToken('stranger', ['events.event.publish']), body: envelope('stranger') });
const r = await request(h.base, 'POST', '/api/v1/events', { token: serviceToken('stranger', ['events.event.publish']), body: envelope('stranger') });
assert.strictEqual(r.status, 403);
assert.strictEqual(r.status, 403);