mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-14 21:10:02 +01:00
Ticket refs #5445: icwmp: SOAP messages unit tests
This commit is contained in:
parent
c023a232bc
commit
520aac547b
9 changed files with 1217 additions and 108 deletions
|
|
@ -24,8 +24,9 @@ run_unit_test:
|
|||
when: always
|
||||
paths:
|
||||
- timestamp.log
|
||||
- memory-report.xml
|
||||
- unit-test-coverage.xml
|
||||
|
||||
|
||||
run_api_test:
|
||||
stage: api_test
|
||||
image: iopsys/code-analysis:latest
|
||||
|
|
|
|||
|
|
@ -98,6 +98,6 @@ libicwmp_la_SOURCES = \
|
|||
../diagnostic.c \
|
||||
../reboot.c
|
||||
|
||||
libicwmp_la_CFLAGS=-I../inc
|
||||
libicwmp_la_CFLAGS=-g -I../inc
|
||||
libicwmp_la_LDFLAGS= $(AM_LIBS) -luci -lubox -lubus $(MICROXML_LIBS) $(LIBCURL_LIBS) -lpthread -lcrypto -lssl -ljson-c -lblobmsg_json -lz -lm
|
||||
endif
|
||||
|
|
|
|||
13
inc/xml.h
13
inc/xml.h
|
|
@ -21,12 +21,12 @@
|
|||
#define CWMP_MXML_TAB_SPACE " "
|
||||
#define MAX_SCHEDULE_INFORM_QUEUE 10
|
||||
|
||||
#define MXML_DELETE(X) \
|
||||
do { \
|
||||
if (X) { \
|
||||
mxmlDelete(X); \
|
||||
X = NULL; \
|
||||
} \
|
||||
#define MXML_DELETE(X) \
|
||||
do { \
|
||||
if (X) { \
|
||||
mxmlDelete(X); \
|
||||
X = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX];
|
||||
|
|
@ -66,6 +66,7 @@ int xml_prepare_msg_out(struct session *session);
|
|||
int xml_prepare_lwnotification_message(char **msg_out);
|
||||
int xml_set_cwmp_id_rpc_cpe(struct session *session);
|
||||
int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code);
|
||||
int xml_recreate_namespace(mxml_node_t *tree);
|
||||
|
||||
const char *whitespace_cb(mxml_node_t *node, int where);
|
||||
int xml_set_cwmp_id(struct session *session);
|
||||
|
|
|
|||
|
|
@ -121,9 +121,10 @@ int cwmp_session_rpc_destructor(struct rpc *rpc)
|
|||
int cwmp_session_destructor(struct session *session)
|
||||
{
|
||||
struct rpc *rpc;
|
||||
|
||||
while (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
|
||||
rpc = list_entry(session->head_rpc_acs.next, struct rpc, list);
|
||||
if (!rpc)
|
||||
break;
|
||||
if (rpc_acs_methods[rpc->type].extra_clean != NULL)
|
||||
rpc_acs_methods[rpc->type].extra_clean(session, rpc);
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
|
|
@ -131,12 +132,13 @@ int cwmp_session_destructor(struct session *session)
|
|||
|
||||
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
|
||||
rpc = list_entry(session->head_rpc_cpe.next, struct rpc, list);
|
||||
if (!rpc)
|
||||
break;
|
||||
cwmp_session_rpc_destructor(rpc);
|
||||
}
|
||||
|
||||
if (session->list.next != NULL && session->list.prev != NULL)
|
||||
list_del(&(session->list));
|
||||
|
||||
free(session);
|
||||
|
||||
return CWMP_OK;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
CC = gcc
|
||||
CFLAGS = -g -Wall -Werror
|
||||
CFLAGS = -g -Wall -I./inc
|
||||
LDFLAGS = -lcmocka -licwmp -lmicroxml
|
||||
UNIT_TESTS = unit_test_icwmpd
|
||||
UNIT_TESTS = icwmp_datamodel_interface_unit_testd icwmp_soap_msg_unit_testd
|
||||
|
||||
VALGRIND = valgrind --xml=yes --xml-file=/builds/iopsys/icwmp/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all
|
||||
|
||||
icwmp_datamodel_interface_unit_testd: icwmp_datamodel_interface_unit_test.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS)
|
||||
|
||||
icwmp_soap_msg_unit_testd: icwmp_soap_msg_unit_test.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS)
|
||||
|
||||
VALGRIND = valgrind --show-reachable=yes \
|
||||
--show-leak-kinds=all --errors-for-leak-kinds=all \
|
||||
--error-exitcode=1 --track-origins=yes
|
||||
|
||||
unit_test_icwmpd: unit_test_icwmp.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
unit-test: $(UNIT_TESTS)
|
||||
$(foreach testprog, $(UNIT_TESTS), sudo $(VALGRIND) ./$(testprog);)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,17 +12,7 @@
|
|||
#include <libicwmp/session.h>
|
||||
#include <libicwmp/log.h>
|
||||
|
||||
struct cwmp cwmp_main_test = { 0 };
|
||||
struct cwmp *cwmp_test;
|
||||
|
||||
static int group_setup(void **state)
|
||||
{
|
||||
cwmp_test = &cwmp_main_test;
|
||||
INIT_LIST_HEAD(&(cwmp_test->head_session_queue));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int group_teardown(void **state)
|
||||
static int dm_iface_unit_tests_clean(void **state)
|
||||
{
|
||||
icwmp_cleanmem();
|
||||
return 0;
|
||||
|
|
@ -320,7 +310,7 @@ static void dm_get_parameter_names_test(void **state)
|
|||
assert_string_equal(fault, "9005");
|
||||
}
|
||||
|
||||
static void dm_set_parameter_attributes_test(void **state)
|
||||
void dm_set_parameter_attributes_test(void **state)
|
||||
{
|
||||
char *fault = NULL;
|
||||
|
||||
|
|
@ -398,76 +388,6 @@ static void dm_get_parameter_attributes_test(void **state)
|
|||
cwmp_free_all_dm_parameter_list(¶meters_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* SOAP TESTS
|
||||
*/
|
||||
static void get_config_test(void **state)
|
||||
{
|
||||
struct cwmp *cwmp_test = &cwmp_main_test;
|
||||
int error = get_global_config(&(cwmp_test->conf));
|
||||
assert_int_equal(error, CWMP_OK);
|
||||
}
|
||||
|
||||
static void get_deviceid_test(void **state)
|
||||
{
|
||||
struct cwmp *cwmp_test = &cwmp_main_test;
|
||||
int error = cwmp_get_deviceid(cwmp_test);
|
||||
assert_int_equal(error, CWMP_OK);
|
||||
}
|
||||
|
||||
static void add_event_test(void **state)
|
||||
{
|
||||
struct event_container *event_container;
|
||||
event_container = cwmp_add_event_container(cwmp_test, EVENT_IDX_1BOOT, "");
|
||||
assert_non_null(event_container);
|
||||
assert_string_equal(EVENT_CONST[event_container->code].CODE, "1 BOOT");
|
||||
}
|
||||
|
||||
static void soap_inform_message_test(void **state)
|
||||
{
|
||||
struct session *session;
|
||||
mxml_node_t *env = NULL, *n = NULL, *device_id = NULL, *cwmp_inform = NULL;
|
||||
|
||||
memcpy(&(cwmp_test->env), &cwmp_test, sizeof(struct env));
|
||||
session = calloc(1, sizeof(struct session));
|
||||
if (session == NULL)
|
||||
return;
|
||||
|
||||
list_add_tail(&(session->list), &(cwmp_test->head_session_queue));
|
||||
|
||||
INIT_LIST_HEAD(&(session->head_event_container));
|
||||
session = list_entry((&(cwmp_test->head_session_queue))->next, struct session, list);
|
||||
struct rpc *rpc_acs;
|
||||
rpc_acs = list_entry(&(session->head_rpc_acs), struct rpc, list);
|
||||
|
||||
cwmp_rpc_acs_prepare_message_inform(cwmp_test, session, rpc_acs);
|
||||
|
||||
env = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(env);
|
||||
n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(n, n, "cwmp:ID", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(env, env, "soap_env:Body", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
cwmp_inform = mxmlFindElement(env, env, "cwmp:Inform", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(cwmp_inform);
|
||||
device_id = mxmlFindElement(cwmp_inform, cwmp_inform, "DeviceId", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(device_id);
|
||||
n = mxmlFindElement(device_id, device_id, "Manufacturer", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(device_id, device_id, "OUI", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(device_id, device_id, "ProductClass", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(device_id, device_id, "SerialNumber", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(cwmp_inform, cwmp_inform, "Event", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
n = mxmlFindElement(cwmp_inform, cwmp_inform, "ParameterList", NULL, NULL, MXML_DESCEND);
|
||||
assert_non_null(n);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
|
|
@ -478,11 +398,7 @@ int main(void)
|
|||
cmocka_unit_test(dm_get_parameter_names_test),
|
||||
cmocka_unit_test(dm_set_parameter_attributes_test),
|
||||
cmocka_unit_test(dm_get_parameter_attributes_test),
|
||||
cmocka_unit_test(get_config_test),
|
||||
cmocka_unit_test(get_deviceid_test),
|
||||
cmocka_unit_test(add_event_test),
|
||||
cmocka_unit_test(soap_inform_message_test),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, group_setup, group_teardown);
|
||||
return cmocka_run_group_tests(tests, NULL, dm_iface_unit_tests_clean);
|
||||
}
|
||||
1063
test/cmocka/icwmp_soap_msg_unit_test.c
Normal file
1063
test/cmocka/icwmp_soap_msg_unit_test.c
Normal file
File diff suppressed because it is too large
Load diff
126
test/cmocka/inc/icwmp_soap_msg_unit_test.h
Normal file
126
test/cmocka/inc/icwmp_soap_msg_unit_test.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#ifndef __SOAP_MSG_TEST__
|
||||
#define __SOAP_MSG_TEST__
|
||||
|
||||
#define CWMP_GETPARAMETERVALUES_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.GetParameterValues1623750334191.21093494</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:GetParameterValues>" \
|
||||
"<ParameterNames SOAP-ENC:arrayType=\"xsd:string[1]\">" \
|
||||
"</ParameterNames>" \
|
||||
"</cwmp:GetParameterValues>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_SETPARAMETERVALUES_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.SetParameterValues1624295944533.1489013116</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:SetParameterValues xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<ParameterList SOAP-ENC:arrayType=\"cwmp:ParameterValueStruct[1]\">" \
|
||||
"<ParameterValueStruct>" \
|
||||
"</ParameterValueStruct>" \
|
||||
"</ParameterList>" \
|
||||
"<ParameterKey>set_value_test</ParameterKey>" \
|
||||
"</cwmp:SetParameterValues>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_ADDOBJECT_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.AddObject1624461905714.1384387619</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:AddObject xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<ObjectName></ObjectName>" \
|
||||
"<ParameterKey>add_object_test</ParameterKey>" \
|
||||
"</cwmp:AddObject>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_DELOBJECT_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.DeleteObject1624464905078.1243670982</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:DeleteObject xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<ObjectName></ObjectName>" \
|
||||
"<ParameterKey>del_object_test</ParameterKey>" \
|
||||
"</cwmp:DeleteObject>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_GETATTRIBUTES_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.GetParameterAttributes1624541216937.139484077</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:GetParameterAttributes xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<ParameterNames SOAP-ENC:arrayType=\"xsd:string[1]\"></ParameterNames>" \
|
||||
"</cwmp:GetParameterAttributes>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_SETATTRIBUTES_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.SetParameterAttributes1624546080334.1155903494</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:SetParameterAttributes xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<ParameterList SOAP-ENC:arrayType=\"cwmp:SetParameterAttributesStruct[1]\">" \
|
||||
"<SetParameterAttributesStruct>" \
|
||||
"<Name></Name>" \
|
||||
"<NotificationChange>1</NotificationChange>" \
|
||||
"<Notification></Notification>" \
|
||||
"<AccessList SOAP-ENC:arrayType=\"xsd:string[1]\"><string xsi:type=\"xsd:string\">subscriber</string></AccessList>" \
|
||||
"<AccessListChange>1</AccessListChange>" \
|
||||
"</SetParameterAttributesStruct>" \
|
||||
"</ParameterList>" \
|
||||
"</cwmp:SetParameterAttributes>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#define CWMP_DOWNLOAD_REQ \
|
||||
"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" \
|
||||
"<SOAP-ENV:Header>" \
|
||||
"<cwmp:ID SOAP-ENV:mustUnderstand=\"1\">ID:intrnl.unset.id.Download1624556569149.1849926569</cwmp:ID>" \
|
||||
"<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>" \
|
||||
"</SOAP-ENV:Header>" \
|
||||
"<SOAP-ENV:Body>" \
|
||||
"<cwmp:Download xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\">" \
|
||||
"<CommandKey>download_test</CommandKey>" \
|
||||
"<FileType></FileType>" \
|
||||
"<URL></URL>" \
|
||||
"<Username></Username>" \
|
||||
"<Password></Password>" \
|
||||
"<FileSize>0</FileSize>" \
|
||||
"<TargetFileName></TargetFileName>" \
|
||||
"<DelaySeconds>0</DelaySeconds>" \
|
||||
"<SuccessURL></SuccessURL>" \
|
||||
"<FailureURL></FailureURL>" \
|
||||
"</cwmp:Download>" \
|
||||
"</SOAP-ENV:Body>" \
|
||||
"</SOAP-ENV:Envelope>"
|
||||
|
||||
#endif
|
||||
3
xml.c
3
xml.c
|
|
@ -92,7 +92,7 @@ mxmlFindElementOpaque(mxml_node_t *node, /* I - Current node */
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
static int xml_recreate_namespace(mxml_node_t *tree)
|
||||
int xml_recreate_namespace(mxml_node_t *tree)
|
||||
{
|
||||
const char *cwmp_urn;
|
||||
char *c;
|
||||
|
|
@ -1162,7 +1162,6 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
|
|||
parameter_list = mxmlNewElement(n, "ParameterList");
|
||||
if (!parameter_list)
|
||||
goto fault;
|
||||
|
||||
#ifdef ACS_MULTI
|
||||
mxmlElementSetAttr(parameter_list, "xsi:type", "soap_enc:Array");
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue