use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class RegistrationMessageFilterTest method testVerifyDetectsDeviceIdMismatch.
/**
* Verifies that a request that contains another device ID than the link it has been
* sent on does not pass the filter.
*/
@Test
public void testVerifyDetectsDeviceIdMismatch() {
// GIVEN a registration message with device id not matching the link target
final Message msg = givenAMessageHavingProperties(MY_DEVICE + "_1", RegistrationConstants.ACTION_ASSERT);
// WHEN receiving the message via a link
final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT, MY_DEVICE);
// THEN message validation fails
assertFalse(RegistrationMessageFilter.verify(linkTarget, msg));
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class RegistrationMessageFilterTest method testVerifyDetectsMissingDeviceId.
/**
* Verifies that a request that does not contain a device ID
* does not pass the filter.
*/
@Test
public void testVerifyDetectsMissingDeviceId() {
// GIVEN a registration message lacking the device id
final Message msg = givenAMessageHavingProperties(null, RegistrationConstants.ACTION_ASSERT);
// WHEN receiving the message via a link
final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT);
// THEN message validation fails
assertFalse(RegistrationMessageFilter.verify(linkTarget, msg));
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class RegistrationMessageFilterTest method testVerifySucceedsForTenantOnlyLinkTarget.
/**
* Verifies that a request with a tenant-level target address containing
* all required properties passes the filter.
*/
@Test
public void testVerifySucceedsForTenantOnlyLinkTarget() {
// GIVEN a valid registration message for myDevice
final Message msg = givenAMessageHavingProperties(MY_DEVICE, RegistrationConstants.ACTION_ASSERT);
// WHEN receiving the message via a link with matching tenant-level target address
final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT);
// THEN message validation succeeds
assertTrue(RegistrationMessageFilter.verify(linkTarget, msg));
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class RegistrationMessageFilterTest method testVerifySucceedsForMatchingDevice.
/**
* Verifies that a valid request that contains the same device ID as the link it
* has been sent on passes the filter.
*/
@Test
public void testVerifySucceedsForMatchingDevice() {
// GIVEN a registration message for myDevice
final Message msg = givenAMessageHavingProperties(MY_DEVICE, RegistrationConstants.ACTION_ASSERT);
// WHEN receiving the message via a link with matching device-level address
final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT, MY_DEVICE);
// THEN message validation succeeds
assertTrue(RegistrationMessageFilter.verify(linkTarget, msg));
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class TenantMessageFilterTest method testVerifyDetectsMissingSubject.
/**
* Verifies that the filter detects a missing subject.
*/
@Test
public void testVerifyDetectsMissingSubject() {
// GIVEN a request message without a subject
final Message msg = ProtonHelper.message();
msg.setMessageId("msg");
msg.setReplyTo("reply");
// WHEN receiving the message via a link with any tenant
final ResourceIdentifier linkTarget = getResourceIdentifier(DEFAULT_TENANT);
// THEN message validation fails
assertFalse(TenantMessageFilter.verify(linkTarget, msg));
}
Aggregations