Skip to content

Commit

Permalink
oc_ace: refactor code and add tests
Browse files Browse the repository at this point in the history
Enhance the oc_ace module by refactoring the existing code and adding comprehensive tests. The primary goals are to improve the code's structure, functionality, and overall maintainability.

Key improvements include:

- Code Refactoring: The code has been reorganized to adhere to best practices, making it more readable and easier to maintain. This restructuring helps developers understand the codebase more quickly and collaborate more effectively.
- Enhanced Testing: New tests have been introduced to ensure the reliability of the oc_ace module. These tests cover various aspects of the module's functionality, helping to catch potential issues early and ensure that future changes do not introduce regressions.

Overall, these changes contribute to a more robust and maintainable codebase, facilitating future development and improving the quality of the software.
  • Loading branch information
Danielius1922 authored Aug 5, 2024
1 parent 122d8f5 commit 9120a25
Show file tree
Hide file tree
Showing 16 changed files with 2,177 additions and 703 deletions.
2 changes: 1 addition & 1 deletion api/oc_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ oc_handle_collection_create_request(oc_method_t method, oc_request_t *request)
oc_rep_end_root_object();
#ifdef OC_SECURITY
oc_sec_acl_add_created_resource_ace(
oc_string(new_res->resource->uri), request->origin,
oc_string_view2(&new_res->resource->uri), request->origin,
request->resource->device,
false); /* TODO: handle creation of Collections */
#endif /* OC_SECURITY */
Expand Down
8 changes: 5 additions & 3 deletions include/oc_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ typedef enum {
*/
typedef struct oc_ace_res_t
{
struct oc_ace_res_t *next; ///< pointer to next entry
oc_string_t href; ///< href
struct oc_ace_res_t *next; ///< pointer to next entry
oc_string_t href; ///< href
#if 0
oc_interface_mask_t interfaces; ///< applicable interfaces (as bit mask)
oc_string_array_t types; ///< resource types (rt)
oc_ace_wildcard_t wildcard; ///< wildcard info
#endif
oc_ace_wildcard_t wildcard; ///< wildcard info
} oc_ace_res_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion port/android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ ifeq ($(PLGD_DEV_TIME),1)
endif

ifneq ($(SECURE),0)
SRC += $(addprefix ../../security/, oc_acl.c oc_acl_util.c oc_ael.c oc_audit.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
SRC += $(addprefix ../../security/,oc_ace.c oc_acl.c oc_acl_util.c oc_ael.c oc_audit.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
oc_cred.c oc_cred_util.c oc_csr.c oc_doxm.c oc_entropy.c oc_keypair.c oc_pki.c oc_pstat.c oc_roles.c oc_sdi.c \
oc_security.c oc_sp.c oc_store.c oc_svr.c oc_tls.c)
SRC_COMMON += $(addprefix $(MBEDTLS_DIR)/library/,${DTLS})
Expand Down
2 changes: 1 addition & 1 deletion port/arduino/adapter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ifeq ($(DYNAMIC),1)
endif

ifeq ($(SECURE),1)
SEC_SRC += $(addprefix $(ROOT_DIR)/security/, oc_acl.c oc_acl_util.c oc_cred.c oc_cred_util.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
SEC_SRC += $(addprefix $(ROOT_DIR)/security/,oc_ace.c oc_acl.c oc_acl_util.c oc_cred.c oc_cred_util.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
oc_csr.c oc_doxm.c oc_entropy.c oc_keypair.c oc_pki.c oc_pstat.c oc_roles.c oc_security.c oc_sp.c oc_store.c oc_svr.c \
oc_tls.c)
SRC += $(SEC_SRC)
Expand Down
1 change: 1 addition & 0 deletions port/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ endif()
if(CONFIG_SECURE)
list(APPEND OC_DEFINITIONS -DOC_SECURITY -DOC_PKI)
list(APPEND sources
${CMAKE_CURRENT_SOURCE_DIR}/../../../security/oc_ace.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../security/oc_acl.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../security/oc_acl_util.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../security/oc_ael.c
Expand Down
2 changes: 1 addition & 1 deletion port/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ endif
endif

ifneq ($(SECURE),0)
SRC += $(addprefix ../../security/, oc_acl.c oc_acl_util.c oc_ael.c oc_audit.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
SRC += $(addprefix ../../security/,oc_ace.c oc_acl.c oc_acl_util.c oc_ael.c oc_audit.c oc_certs.c oc_certs_generate.c oc_certs_validate.c \
oc_cred.c oc_cred_util.c oc_csr.c oc_doxm.c oc_entropy.c oc_keypair.c oc_oscore_engine.c oc_oscore_crypto.c \
oc_oscore_context.c oc_pki.c oc_pstat.c oc_roles.c oc_sdi.c oc_security.c oc_sp.c oc_store.c oc_svr.c oc_tls.c)
SRC_COMMON += $(addprefix $(MBEDTLS_DIR)/library/,${DTLS})
Expand Down
2 changes: 1 addition & 1 deletion port/openthread/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ifeq ($(MEMORY_TRACE), 1)
endif

ifeq ($(SECURE),1)
SRC_COMMON += oc_acl.c oc_acl_util.c oc_cred.c oc_cred_util.c oc_doxm.c oc_pstat.c oc_dtls.c oc_svr.c oc_store.c oc_sdi.c
SRC_COMMON += oc_ace.c oc_acl.c oc_acl_util.c oc_cred.c oc_cred_util.c oc_doxm.c oc_pstat.c oc_dtls.c oc_svr.c oc_store.c oc_sdi.c
SRC_COMMON += memory_buffer_alloc.c
CFLAGS += -DOC_SECURITY
endif
Expand Down
2 changes: 2 additions & 0 deletions port/windows/vs2015/IoTivity-lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
<ClInclude Include="..\..\..\messaging\coap\oc_coap.h" />
<ClInclude Include="..\..\..\messaging\coap\separate_internal.h" />
<ClInclude Include="..\..\..\messaging\coap\transactions_internal.h" />
<ClInclude Include="..\..\..\security\oc_ace_internal.h" />
<ClInclude Include="..\..\..\security\oc_acl_internal.h" />
<ClInclude Include="..\..\..\security\oc_acl_util_internal.h" />
<ClInclude Include="..\..\..\security\oc_ael_internal.h" />
Expand Down Expand Up @@ -461,6 +462,7 @@
<ClCompile Include="..\..\..\port\common\oc_poll_loop.c" />
<ClCompile Include="..\..\..\port\common\posix\oc_socket.c" />
<ClCompile Include="..\..\..\port\common\posix\oc_tcp_socket.c" />
<ClCompile Include="..\..\..\security\oc_ace.c" />
<ClCompile Include="..\..\..\security\oc_acl.c" />
<ClCompile Include="..\..\..\security\oc_acl_util.c" />
<ClCompile Include="..\..\..\security\oc_ael.c" />
Expand Down
6 changes: 6 additions & 0 deletions port/windows/vs2015/IoTivity-lite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@
<ClCompile Include="..\..\..\security\oc_sp.c">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\..\..\security\oc_ace.c">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\..\..\security\oc_acl.c">
<Filter>Security</Filter>
</ClCompile>
Expand Down Expand Up @@ -730,6 +733,9 @@
<ClInclude Include="..\..\..\security\oc_sp_internal.h">
<Filter>Security</Filter>
</ClInclude>
<ClInclude Include="..\..\..\security\oc_ace_internal.h">
<Filter>Security</Filter>
</ClInclude>
<ClInclude Include="..\..\..\security\oc_acl_internal.h">
<Filter>Security</Filter>
</ClInclude>
Expand Down
Loading

0 comments on commit 9120a25

Please sign in to comment.