openvibers/openvibe.network Commits

Connect may publish its own events (CON-15 hooks) (#540)

OP OpenVibers committed 10 days ago · 64f7b39f4e · 2 files, +19 −0

Hooks that wait for your computer: Connect keeps a webhook and publishes a pointer to it, then consumes it through
its own subscription, which Events retries for up to seven days.

Changes

ddiff --git a/server/identity/principals.js b/server/identity/principals.js
iindex 28146166..f279a8dc 100644
---- a/server/identity/principals.js
++++ b/server/identity/principals.js
@@@ -668,6 +668,9 @@ const DEFAULT_GRANTS = [
// OpenVibe Connect (contracts 0.279.0, Website Connect v0): its account-event subscriptions at boot. It publishes
// nothing yet; export and deletion are above.
['connect', 'events.subscription.manage', 'openvibe.events', []],
++ // Hooks that wait for your computer (CON-15, contracts 0.282.0): Connect publishes connect.hook.received, a
++ // pointer to a webhook it keeps, and consumes it through its own subscription (retried up to seven days).
++ ['connect', 'events.event.publish', 'openvibe.events', []],
// "Tell me when it's back" (CON-17, 11-02): one notification, as app connect, to a person who asked when a share's
// computer connects again. Nothing else of Network's notifications.
['connect', 'network.notifications.push', SELF_AUDIENCE, ['connect']],
ddiff --git a/test/connect-hooks-grant.test.js b/test/connect-hooks-grant.test.js
nnew file mode 100644
iindex 00000000..ae6985ce
---- /dev/null
++++ b/test/connect-hooks-grant.test.js
@@@ -0,0 +1,16 @@
++/**
++ * OpenVibe Connect's Events grants (CON-15, hooks that wait for your computer): Connect manages its own subscriptions
++ * and publishes its own events (connect.hook.received, contracts 0.282.0), and holds nothing else of Events.
++ *
++ * node test/connect-hooks-grant.test.js
++ */
++'use strict';
++const assert = require('assert');
++const contracts = require('openvibe-contracts');
++const principals = require('../server/identity/principals');
++
++const rows = principals.DEFAULT_GRANTS.filter((g) => g[0] === 'connect' && g[2] === 'openvibe.events');
++assert.deepStrictEqual(rows.map((g) => [g[1], g[3]]).sort(), [['events.event.publish', []], ['events.subscription.manage', []]], 'publish and its own subscriptions; never delivery admin or another service\'s reads');
++const cap = contracts.capabilities.get('events.event.publish');
++assert.ok(cap && cap.status === 'active', 'an active capability');
++console.log('connect hooks grant: ok');