Skip to content

Commit

Permalink
fix(platform): do not transport intents to other applications if not …
Browse files Browse the repository at this point in the history
…declaring a respective intention

This commit addresses the issue that previously, if having an implicit intention due
to a provided capability, the message broker would have transported the intent to other
applications which provide a matching public capability.
mofogasy authored and danielwiehl committed Nov 5, 2021
1 parent e39804c commit 24681e3
Showing 4 changed files with 226 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -69,7 +69,8 @@ export namespace IntendBasedMessagingSpecs {
}

/**
* Tests that an application can issue intents to its private capabilities.
* Tests that an application can issue intents to its private capabilities without registering an intention.
* However, because not explicitly registered an intention, the intent should not be transported to other applications which provide a matching, public capability.
*/
export async function dispatchToOwnPrivateCapabilitiesSpec(): Promise<void> {
const testingAppPO = new TestingAppPO();
@@ -78,22 +79,33 @@ export namespace IntendBasedMessagingSpecs {
managerOutlet: 'about:blank',
publisher_app3: {useClass: PublishMessagePagePO, origin: TestingAppOrigins.APP_3},
receiver_app3: {useClass: ReceiveMessagePagePO, origin: TestingAppOrigins.APP_3},
receiver_app4: {useClass: ReceiveMessagePagePO, origin: TestingAppOrigins.APP_4},
});

const managerOutlet = pagePOs.get<BrowserOutletPO>('managerOutlet');

// do not register intention, an application can always issue intents to its private capabilities

// register the capability
// register the capability of app-3
const capabilityManager_app3 = await managerOutlet.enterUrl<RegisterCapabilityPagePO>({useClass: RegisterCapabilityPagePO, origin: TestingAppOrigins.APP_3});
await capabilityManager_app3.registerCapability({type: 'testing', qualifier: {key: 'value'}, private: true});

// receive the intent
// register the capability of app-4
const capabilityManager_app4 = await managerOutlet.enterUrl<RegisterCapabilityPagePO>({useClass: RegisterCapabilityPagePO, origin: TestingAppOrigins.APP_4});
await capabilityManager_app4.registerCapability({type: 'testing', qualifier: {key: 'value'}, private: false});

// receive the intent in app-3
const receiverPO_app3 = pagePOs.get<ReceiveMessagePagePO>('receiver_app3');
await receiverPO_app3.selectFlavor(MessagingFlavor.Intent);
await receiverPO_app3.enterIntentSelector('testing', {key: 'value'});
await receiverPO_app3.clickSubscribe();

// receive the intent in app-4
const receiverPO_app4 = pagePOs.get<ReceiveMessagePagePO>('receiver_app4');
await receiverPO_app4.selectFlavor(MessagingFlavor.Intent);
await receiverPO_app4.enterIntentSelector('testing', {key: 'value'});
await receiverPO_app4.clickSubscribe();

// issue the intent
const publisherPO_app3 = pagePOs.get<PublishMessagePagePO>('publisher_app3');
await publisherPO_app3.selectFlavor(MessagingFlavor.Intent);
@@ -103,12 +115,15 @@ export namespace IntendBasedMessagingSpecs {

await expect(publisherPO_app3.getPublishError()).toBeNull();

// assert intent to be received
// assert intent to be received in app-3
const intent = await receiverPO_app3.getFirstMessageOrElseReject();
await expect(await intent.getIntentType()).toEqual('testing');
await expect(await intent.getBody()).toEqual('some payload');
await expect(await intent.getIntentQualifier()).toEqual({key: 'value'});
await expect(await intent.getReplyTo()).toBeUndefined();

// assert intent not to be received in app-4
await expect(await receiverPO_app4.getMessages()).toEqual([]);
}

/**
@@ -154,7 +169,8 @@ export namespace IntendBasedMessagingSpecs {
}

/**
* Tests that an application can issue intents to its public capabilities.
* Tests that an application can issue intents to its public capabilities without registering an intention.
* However, because not explicitly registered an intention, the intent should not be transported to other applications which provide a matching, public capability.
*/
export async function dispatchToOwnPublicCapabilitiesSpec(): Promise<void> {
const testingAppPO = new TestingAppPO();
@@ -163,22 +179,33 @@ export namespace IntendBasedMessagingSpecs {
managerOutlet: 'about:blank',
publisher_app3: {useClass: PublishMessagePagePO, origin: TestingAppOrigins.APP_3},
receiver_app3: {useClass: ReceiveMessagePagePO, origin: TestingAppOrigins.APP_3},
receiver_app4: {useClass: ReceiveMessagePagePO, origin: TestingAppOrigins.APP_4},
});

const managerOutlet = pagePOs.get<BrowserOutletPO>('managerOutlet');

// do not register intention, an application can always issue intents to its public capabilities

// register the capability
// register the capability of app-3
const capabilityManagerPO_app3 = await managerOutlet.enterUrl<RegisterCapabilityPagePO>({useClass: RegisterCapabilityPagePO, origin: TestingAppOrigins.APP_3});
await capabilityManagerPO_app3.registerCapability({type: 'testing', qualifier: {key: 'value'}, private: false});

// receive the intent
// register the capability of app-4
const capabilityManager_app4 = await managerOutlet.enterUrl<RegisterCapabilityPagePO>({useClass: RegisterCapabilityPagePO, origin: TestingAppOrigins.APP_4});
await capabilityManager_app4.registerCapability({type: 'testing', qualifier: {key: 'value'}, private: false});

// receive the intent in app-3
const receiverPO = pagePOs.get<ReceiveMessagePagePO>('receiver_app3');
await receiverPO.selectFlavor(MessagingFlavor.Intent);
await receiverPO.enterIntentSelector('testing', {key: 'value'});
await receiverPO.clickSubscribe();

// receive the intent in app-4
const receiverPO_app4 = pagePOs.get<ReceiveMessagePagePO>('receiver_app4');
await receiverPO_app4.selectFlavor(MessagingFlavor.Intent);
await receiverPO_app4.enterIntentSelector('testing', {key: 'value'});
await receiverPO_app4.clickSubscribe();

// issue the intent
const publisherPO = pagePOs.get<PublishMessagePagePO>('publisher_app3');
await publisherPO.selectFlavor(MessagingFlavor.Intent);
@@ -188,12 +215,15 @@ export namespace IntendBasedMessagingSpecs {

await expect(publisherPO.getPublishError()).toBeNull();

// assert intent to be received
// assert intent to be received in app-3
const intent = await receiverPO.getFirstMessageOrElseReject();
await expect(await intent.getIntentType()).toEqual('testing');
await expect(await intent.getBody()).toEqual('some payload');
await expect(await intent.getIntentQualifier()).toEqual({key: 'value'});
await expect(await intent.getReplyTo()).toBeUndefined();

// assert intent not to be received in app-4
await expect(await receiverPO_app4.getMessages()).toEqual([]);
}

/**
Original file line number Diff line number Diff line change
@@ -116,11 +116,11 @@ describe('Messaging', () => {
await IntendBasedMessagingSpecs.intentNotFulfilledSpec();
});

it('allows issuing intents to own private capabilities', async () => {
it('allows issuing intents to own private capabilities with implicit intention', async () => {
await IntendBasedMessagingSpecs.dispatchToOwnPrivateCapabilitiesSpec();
});

it('allows issuing intents to own public capabilities', async () => {
it('allows issuing intents to own public capabilities with implicit intention', async () => {
await IntendBasedMessagingSpecs.dispatchToOwnPublicCapabilitiesSpec();
});

Loading

0 comments on commit 24681e3

Please sign in to comment.