Search in sources :

Example 36 with ResourceIdentifier

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));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.jupiter.api.Test)

Example 37 with ResourceIdentifier

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));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.jupiter.api.Test)

Example 38 with ResourceIdentifier

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));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.jupiter.api.Test)

Example 39 with ResourceIdentifier

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));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.jupiter.api.Test)

Example 40 with ResourceIdentifier

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));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)82 Message (org.apache.qpid.proton.message.Message)30 Future (io.vertx.core.Future)24 HttpURLConnection (java.net.HttpURLConnection)22 MessageHelper (org.eclipse.hono.util.MessageHelper)22 ClientErrorException (org.eclipse.hono.client.ClientErrorException)20 Test (org.junit.Test)20 Test (org.junit.jupiter.api.Test)19 Handler (io.vertx.core.Handler)18 Map (java.util.Map)18 Span (io.opentracing.Span)17 Buffer (io.vertx.core.buffer.Buffer)17 SpanContext (io.opentracing.SpanContext)16 Constants (org.eclipse.hono.util.Constants)16 Promise (io.vertx.core.Promise)15 Objects (java.util.Objects)14 AsyncResult (io.vertx.core.AsyncResult)13 Vertx (io.vertx.core.Vertx)13 ProtonConnection (io.vertx.proton.ProtonConnection)13 ProtonReceiver (io.vertx.proton.ProtonReceiver)13