From 39b5511344023394c1099048e1e49659f15628bb Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Mon, 2 Dec 2024 16:57:09 +0100 Subject: [PATCH] fix: SMS inbound and outbound lists stack overflow [DHIS2-18542] (#19364) --- .../dhis/webapi/controller/SmsInboundControllerTest.java | 8 ++++++++ .../dhis/webapi/controller/SmsOutboundControllerTest.java | 8 ++++++++ .../dhis/webapi/controller/sms/SmsInboundController.java | 4 ++-- .../dhis/webapi/controller/sms/SmsOutboundController.java | 5 +++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsInboundControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsInboundControllerTest.java index 1fad2629914d..5d29fa4c17a9 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsInboundControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsInboundControllerTest.java @@ -28,8 +28,10 @@ package org.hisp.dhis.webapi.controller; import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hisp.dhis.http.HttpStatus; +import org.hisp.dhis.jsontree.JsonObject; import org.hisp.dhis.sms.incoming.IncomingSms; import org.hisp.dhis.sms.incoming.IncomingSmsService; import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase; @@ -51,6 +53,12 @@ class SmsInboundControllerTest extends H2ControllerIntegrationTestBase { @Test void testGetInboundSMSMessage() { + JsonObject list = GET("/sms/inbound").content(); + assertEquals(0, list.getArray("inboundsmss").size()); + } + + @Test + void testGetInboundSMSMessage_Forbidden() { User guestUser = createUserWithAuth("guestuser", "NONE"); injectSecurityContextUser(guestUser); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsOutboundControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsOutboundControllerTest.java index 3d4157130a72..33eb7e104718 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsOutboundControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/SmsOutboundControllerTest.java @@ -28,8 +28,10 @@ package org.hisp.dhis.webapi.controller; import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hisp.dhis.http.HttpStatus; +import org.hisp.dhis.jsontree.JsonObject; import org.hisp.dhis.sms.outbound.OutboundSms; import org.hisp.dhis.sms.outbound.OutboundSmsService; import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase; @@ -52,6 +54,12 @@ class SmsOutboundControllerTest extends H2ControllerIntegrationTestBase { @Test void testGetOutboundSMSMessage() { + JsonObject list = GET("/sms/outbound").content(); + assertEquals(0, list.getArray("outboundsmss").size()); + } + + @Test + void testGetOutboundSMSMessage_Forbidden() { User guestUser = createUserWithAuth("guestuser", "NONE"); injectSecurityContextUser(guestUser); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsInboundController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsInboundController.java index d73448e7f6b9..fcc2c2e12b96 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsInboundController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/sms/SmsInboundController.java @@ -106,8 +106,8 @@ public class SmsInboundController extends AbstractCrudController