Disable session ACLs during unit testing
authorPetr Štetiar <ynezz@true.cz>
Mon, 12 Oct 2020 11:30:18 +0000 (13:30 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 27 Oct 2020 22:03:04 +0000 (23:03 +0100)
Otherwise we would need to setup ubus infrastructure etc.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
CMakeLists.txt
main.c

index b60d08e96e3c6afc97302586325344b72de1ab4b..ae37f1f68cfa6308d1901ebe98fb50fe2ebe4a41 100644 (file)
@@ -25,6 +25,7 @@ ADD_EXECUTABLE(cgi-io main.c)
 TARGET_LINK_LIBRARIES(cgi-io cgi-lib ${ubox} ${ubus})
 
 IF(UNIT_TESTING)
+  ADD_DEFINITIONS(-DUNIT_TESTING)
   ENABLE_TESTING()
   ADD_SUBDIRECTORY(tests)
 ENDIF()
diff --git a/main.c b/main.c
index ff9bb63f5cd8fabbb91aa06c61095c93379e8189..95a62b827011ce911967705c21dae5180c5ac70d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -72,6 +72,10 @@ struct state
        int tempfd;
 };
 
+static struct state st;
+
+#ifndef UNIT_TESTING
+
 enum {
        SES_ACCESS,
        __SES_MAX,
@@ -81,9 +85,6 @@ static const struct blobmsg_policy ses_policy[__SES_MAX] = {
        [SES_ACCESS] = { .name = "access", .type = BLOBMSG_TYPE_BOOL },
 };
 
-
-static struct state st;
-
 static void
 session_access_cb(struct ubus_request *req, int type, struct blob_attr *msg)
 {
@@ -98,10 +99,14 @@ session_access_cb(struct ubus_request *req, int type, struct blob_attr *msg)
        if (tb[SES_ACCESS])
                *allow = blobmsg_get_bool(tb[SES_ACCESS]);
 }
+#endif
 
 static bool
 session_access(const char *sid, const char *scope, const char *obj, const char *func)
 {
+#ifdef UNIT_TESTING
+       return true;
+#else
        uint32_t id;
        bool allow = false;
        struct ubus_context *ctx;
@@ -125,6 +130,7 @@ out:
                ubus_free(ctx);
 
        return allow;
+#endif
 }
 
 static char *