use of org.eclipse.californium.core.coap.CoAP.Code in project hono by eclipse.
the class CoapTestBase method testUploadMessageFailsForDisabledGateway.
/**
* Verifies that the CoAP adapter rejects messages from a disabled gateway
* for an enabled device with a 403.
*
* @param ctx The test context
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadMessageFailsForDisabledGateway(final VertxTestContext ctx) {
// GIVEN a device that is connected via a disabled gateway
final Tenant tenant = new Tenant();
final String gatewayId = helper.getRandomDeviceId(tenantId);
final Device gatewayData = new Device();
gatewayData.setEnabled(false);
final Device deviceData = new Device();
deviceData.setVia(Collections.singletonList(gatewayId));
helper.registry.addPskDeviceForTenant(tenantId, tenant, gatewayId, gatewayData, SECRET).compose(ok -> helper.registry.registerDevice(tenantId, deviceId, deviceData)).compose(ok -> {
// WHEN the gateway tries to upload a message for the device
final Promise<OptionSet> result = Promise.promise();
final CoapClient client = getCoapsClient(gatewayId, tenantId, SECRET);
// THEN a FORBIDDEN response code is returned
client.advanced(getHandler(result, ResponseCode.FORBIDDEN), createCoapsRequest(Code.PUT, getPutResource(tenantId, deviceId), 0));
return result.future();
}).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.californium.core.coap.CoAP.Code in project hono by eclipse.
the class CoapTestBase method testUploadMessageFailsForDisabledTenant.
/**
* Verifies that the CoAP adapter rejects messages from a device that belongs to a tenant for which the CoAP adapter
* has been disabled.
*
* @param ctx The test context
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadMessageFailsForDisabledTenant(final VertxTestContext ctx) {
// GIVEN a tenant for which the CoAP adapter is disabled
final Tenant tenant = new Tenant();
tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_COAP).setEnabled(false));
helper.registry.addPskDeviceForTenant(tenantId, tenant, deviceId, SECRET).compose(ok -> {
// WHEN a device that belongs to the tenant uploads a message
final CoapClient client = getCoapsClient(deviceId, tenantId, SECRET);
final Promise<OptionSet> result = Promise.promise();
// THEN a FORBIDDEN response code is returned
client.advanced(getHandler(result, ResponseCode.FORBIDDEN), createCoapsRequest(Code.POST, getPostResource(), 0));
return result.future();
}).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.californium.core.coap.CoAP.Code in project hono by eclipse.
the class TelemetryCoapIT method testUploadFailsForLargePayload.
/**
* Verifies that the upload of a telemetry message containing a payload that
* exceeds the CoAP adapter's configured max payload size fails with a 4.13
* response code.
*
* @param ctx The test context.
* @throws IOException if the CoAP request cannot be sent to the adapter.
* @throws ConnectorException if the CoAP request cannot be sent to the adapter.
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadFailsForLargePayload(final VertxTestContext ctx) throws ConnectorException, IOException {
final Tenant tenant = new Tenant();
helper.registry.addPskDeviceForTenant(tenantId, tenant, deviceId, SECRET).compose(ok -> {
final CoapClient client = getCoapsClient(deviceId, tenantId, SECRET);
final Request request = createCoapsRequest(Code.POST, Type.CON, getPostResource(), IntegrationTestSupport.getPayload(4096));
final Promise<OptionSet> result = Promise.promise();
client.advanced(getHandler(result, ResponseCode.REQUEST_ENTITY_TOO_LARGE), request);
return result.future();
}).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.californium.core.coap.CoAP.Code in project mule-coap-connector by teslanet-nl.
the class AbstractSecureClientTestCase method testOutbound.
@Test
public void testOutbound() throws Exception {
expectException();
String payload = "test-payload";
MuleEventSpy spy = spyMessage(payload.getBytes());
for (Code call : outboundCalls) {
spy.clear();
Request request = new Request(call);
request.setURI(uri.resolve(getPath(call)));
switch(call) {
case DELETE:
case GET:
request.setUnintendedPayload();
break;
default:
break;
}
request.setPayload("nothing important");
CoapResponse response = client.advanced(request);
assertNotNull("get gave no response", response);
assertTrue("response indicates failure: " + response.getCode() + " msg: " + response.getResponseText(), response.isSuccess());
assertArrayEquals("wrong payload in response", payload.getBytes(), response.getPayload());
assertEquals("wrong number of spied events", 1, spy.getEvents().size());
client.shutdown();
}
}
use of org.eclipse.californium.core.coap.CoAP.Code in project mule-coap-connector by teslanet-nl.
the class InsecureClientTest method testInsecureClientDelete.
@Test()
public void testInsecureClientDelete() throws Exception {
MuleEventSpy spy = spyMessage();
Code call = Code.DELETE;
CoapClient client = getClient(getPath(call));
Request request = new Request(call);
CoapResponse response = client.advanced(request);
assertNull("should not receive a response", response);
assertSpy(spy);
client.shutdown();
}
Aggregations