Skip to content

Commit

Permalink
GH-1387: Fix BootstrapDeleteRequest always delete all instances
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 26, 2023
1 parent a6e55d7 commit 250c8e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,19 @@ public void visit(BootstrapReadRequest request) {

@Override
public void visit(BootstrapDeleteRequest request) {
response = toSendableResponse(bootstrapHandler.delete(sender, request));
if (request.getPath().isRoot()) {
response = toSendableResponse(bootstrapHandler.delete(sender, request));
} else {
LwM2mObjectEnabler objectEnabler = getObjectEnabler(request);
if (objectEnabler == null) {
// Bootstrap delete operation does not support Not Found Response code :
// See
// http://www.openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/HTML-Version/OMA-TS-LightweightM2M_Transport-V1_1_1-20190617-A.html#Table-642-1-Operation-to-Method-and-URI-Mapping-Bootstrap-Interface
response = toSendableResponse(BootstrapDeleteResponse.badRequest("not found"));
} else {
response = toSendableResponse(objectEnabler.delete(sender, request));
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -430,7 +431,7 @@ public void bootstrap_with_auto_id_for_security_object() {
}

@Test
public void bootstrapDeleteSecurity() {
public void bootstrap_delete_access_control_and_connectivity_statistics() {
// Create DM Server without security & start it
helper.createServer();
helper.server.start();
Expand All @@ -444,6 +445,7 @@ public void bootstrapDeleteSecurity() {
ObjectsInitializer initializer = new TestObjectsInitializer();
initializer.setInstancesForObject(LwM2mId.ACCESS_CONTROL, new SimpleInstanceEnabler());
initializer.setInstancesForObject(LwM2mId.CONNECTIVITY_STATISTICS, new SimpleInstanceEnabler());
initializer.setInstancesForObject(LwM2mId.LOCATION, new SimpleInstanceEnabler());
helper.createClient(helper.withoutSecurity(), initializer);
helper.assertClientNotRegisterered();

Expand All @@ -460,6 +462,19 @@ public void bootstrapDeleteSecurity() {
.read(ServerIdentity.SYSTEM, new ReadRequest(LwM2mId.CONNECTIVITY_STATISTICS));
assertTrue("Connectvity instance is not deleted",
((LwM2mObject) response.getContent()).getInstances().isEmpty());

// ensure other instances are not deleted.
response = helper.client.getObjectTree().getObjectEnabler(LwM2mId.DEVICE).read(ServerIdentity.SYSTEM,
new ReadRequest(LwM2mId.DEVICE));
assertFalse("Device instance is deleted", ((LwM2mObject) response.getContent()).getInstances().isEmpty());

response = helper.client.getObjectTree().getObjectEnabler(LwM2mId.SECURITY).read(ServerIdentity.SYSTEM,
new ReadRequest(LwM2mId.SECURITY));
assertFalse("Security instance is deleted", ((LwM2mObject) response.getContent()).getInstances().isEmpty());

response = helper.client.getObjectTree().getObjectEnabler(LwM2mId.LOCATION).read(ServerIdentity.SYSTEM,
new ReadRequest(LwM2mId.LOCATION));
assertFalse("Location instance is deleted", ((LwM2mObject) response.getContent()).getInstances().isEmpty());
}

@Test
Expand Down

0 comments on commit 250c8e2

Please sign in to comment.