Added additional test cases for stc-manager firewall dbus methods 37/191337/2
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Tue, 16 Oct 2018 06:34:16 +0000 (12:04 +0530)
committerAbhishek Sansanwal <abhishek.s94@samsung.com>
Thu, 18 Oct 2018 06:31:24 +0000 (12:01 +0530)
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: I1e9fa8f54507950f8b0c7f45f688546bed1081d1

unittest/CMakeLists.txt
unittest/common.cpp [new file with mode: 0644]
unittest/common.h [new file with mode: 0644]
unittest/firewall.cpp [new file with mode: 0644]
unittest/firewall.h [new file with mode: 0644]
unittest/gdbus.h
unittest/restriction.cpp
unittest/restriction.h
unittest/statistics.cpp
unittest/stcmgr.h
unittest/unittest.cpp

index 7cb1f4f0bbfccf99b3f29a29000ba1c4a5ba3bc9..6ae9e4827dfdbceb0aa0a4fd7b3f46ba60534e9e 100644 (file)
@@ -10,7 +10,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        gmock
        dlog
 )
-
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
 
diff --git a/unittest/common.cpp b/unittest/common.cpp
new file mode 100644 (file)
index 0000000..3fbaf8d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common.h"
+
+GMainLoop *MainLoop::m_mainLoop = NULL;
+guint MainLoop::m_timerId = 0;
+
+MainLoop::MainLoop(void)
+{
+}
+
+MainLoop::~MainLoop(void)
+{
+       if (m_mainLoop)
+               g_main_loop_quit(m_mainLoop);
+       if (m_timerId)
+               g_source_remove(m_timerId);
+
+       m_mainLoop = NULL;
+       m_timerId = 0;
+}
+
+gboolean MainLoop::timeoutCb(gpointer data)
+{
+       if (m_mainLoop)
+               g_main_loop_quit(m_mainLoop);
+       if (m_timerId)
+               g_source_remove(m_timerId);
+
+       m_mainLoop = NULL;
+       m_timerId = 0;
+
+       return false;
+}
+
+void MainLoop::run(unsigned int timeout)
+{
+       if (m_timerId > 0)
+               return;
+
+       m_mainLoop = g_main_loop_new(NULL, false);
+       m_timerId = g_timeout_add(timeout,
+                       (GSourceFunc) &MainLoop::timeoutCb,
+                       NULL);
+       g_main_loop_run(m_mainLoop);
+}
+
+void MainLoop::quit(void)
+{
+       timeoutCb(NULL);
+}
+
diff --git a/unittest/common.h b/unittest/common.h
new file mode 100644 (file)
index 0000000..c0f97aa
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+class MainLoop {
+private:
+               static GMainLoop *m_mainLoop;
+               static guint m_timerId;
+
+               static gboolean timeoutCb(gpointer data);
+public:
+               MainLoop(void);
+               ~MainLoop(void);
+               void run(unsigned int timeout);
+               void quit(void);
+};
diff --git a/unittest/firewall.cpp b/unittest/firewall.cpp
new file mode 100644 (file)
index 0000000..44bcfe5
--- /dev/null
@@ -0,0 +1,539 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "firewall.h"
+#include "common.h"
+
+static void AsyncReadyCallback(GObject *source_object,
+       GAsyncResult *res, gpointer user_data)
+{
+       MainLoop *M = (MainLoop *)user_data;
+       GLOGD("Succeeded to response async callback");
+       M->quit();
+}
+
+FRule::FRule()
+{
+       this->chain[0] = '\0';
+       this->direction = 0;
+       this->siptype = 0;
+       this->diptype = 0;
+       this->sporttype = 0;
+       this->dporttype = 0;
+       this->protocol = 0;
+       this->family = 0;
+       this->sip1[0] = '\0';
+       this->dip1[0] = '\0';
+       this->sip2[0] = '\0';
+       this->dip2[0] = '\0';
+       this->dport1 = 0;
+       this->dport2 = 0;
+       this->sport1 = 0;
+       this->sport2 = 0;
+       this->iface[0] = '\0';
+       this->target = 0;
+}
+
+FRule::~FRule()
+{
+}
+
+Firewall::Firewall()
+{
+       Create();
+}
+
+Firewall::~Firewall()
+{
+       Destroy();
+}
+
+error_e Firewall::SetRule(const char *chain, guint16 direction,
+               guint16 siptype, guint16 diptype, guint16 sporttype,
+               guint16 dporttype, guint16 protocol, guint16 family,
+               const char *sip1, const char *dip1, const char *sip2,
+               const char *dip2, guint32 dport1, guint32 dport2,
+               guint32 sport1, guint32 sport2, const char *iface,
+               guint16 target)
+{
+       if (chain == NULL || strlen(chain) == 0)
+               this->m_Rule.chain[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.chain, chain, CHAIN_LEN);
+
+       if (sip1 == NULL || strlen(sip1) == 0)
+               this->m_Rule.sip1[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.sip1, sip1, IP_LEN);
+
+       if (sip2 == NULL || strlen(sip2) == 0)
+               this->m_Rule.sip2[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.sip2, sip2, IP_LEN);
+
+       if (dip1 == NULL || strlen(dip1) == 0)
+               this->m_Rule.dip1[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.dip1, dip1, IP_LEN);
+
+       if (dip2 == NULL || strlen(dip2) == 0)
+               this->m_Rule.dip2[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.dip2, dip2, IP_LEN);
+
+       if (iface == NULL || strlen(iface) == 0)
+               this->m_Rule.iface[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.iface, iface, IFACE_LEN);
+
+
+       this->m_Rule.direction = direction;
+       this->m_Rule.siptype = siptype;
+       this->m_Rule.diptype = diptype;
+       this->m_Rule.sporttype = sporttype;
+       this->m_Rule.dporttype = dporttype;
+       this->m_Rule.protocol = protocol;
+       this->m_Rule.family = family;
+       this->m_Rule.dport1 = dport1;
+       this->m_Rule.dport2 = dport2;
+       this->m_Rule.sport1 = sport1;
+       this->m_Rule.sport2 = sport2;
+       this->m_Rule.target = target;
+
+       return ERROR_NONE;
+}
+
+void Firewall::MakeRuleParams(GVariant **params)
+{
+       GVariantBuilder *builder;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_CHAIN,
+                       g_variant_new_string(this->m_Rule.chain));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DIRECTION,
+                       g_variant_new_uint16(this->m_Rule.direction));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_IFNAME,
+                       g_variant_new_string(this->m_Rule.iface));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_PROTOCOL,
+                       g_variant_new_uint16(this->m_Rule.protocol));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_TARGET,
+                       g_variant_new_uint16(this->m_Rule.target));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_FAMILY,
+                       g_variant_new_uint16(this->m_Rule.family));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SIPTYPE,
+                       g_variant_new_uint16(this->m_Rule.siptype));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SIP1,
+                       g_variant_new_string(this->m_Rule.sip1));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SIP2,
+                       g_variant_new_string(this->m_Rule.sip2));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DIPTYPE,
+                       g_variant_new_uint16(this->m_Rule.diptype));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DIP1,
+                       g_variant_new_string(this->m_Rule.dip1));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DIP2,
+                       g_variant_new_string(this->m_Rule.dip2));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SPORTTYPE,
+                       g_variant_new_uint16(this->m_Rule.sporttype));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SPORT1,
+                       g_variant_new_uint32(this->m_Rule.sport1));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_SPORT2,
+                       g_variant_new_uint32(this->m_Rule.sport2));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DPORTTYPE,
+                       g_variant_new_uint16(this->m_Rule.dporttype));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DPORT1,
+                       g_variant_new_uint32(this->m_Rule.dport1));
+
+       g_variant_builder_add(builder, "{sv}",
+                       FIREWALL_RULE_DPORT2,
+                       g_variant_new_uint32(this->m_Rule.dport2));
+
+       *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+       g_variant_builder_unref(builder);
+}
+
+error_e Firewall::GetAllRule(void)
+{
+       MainLoop M;
+       error_e error = ERROR_NONE;
+
+       error = InvokeMethodNonblock(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_GET_ALL,
+               NULL,
+               DBUS_REPLY_TIMEOUT,
+               AsyncReadyCallback,
+               &M);
+
+       if (error != ERROR_NONE) {
+               GLOGD("Failed to invoke dbus method nonblock");
+               return error;
+       }
+
+       GLOGD("Succeeded to get all restriction");
+
+       M.run(GMAINTIMEOUT);
+       return ERROR_NONE;
+}
+
+error_e Firewall::UpdateRule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_UPDATE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::RemoveRule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_REMOVE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::AddRule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_ADD,
+               params,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::SetChain(const char *chain, unsigned int target)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_SET,
+               g_variant_new("(su)", chain, target),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::UnsetChain(const char *chain)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_UNSET,
+               g_variant_new("(s)", chain),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::FlushChain(const char *chain)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_FLUSH,
+               g_variant_new("(s)", chain),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::GetAllChain(void)
+{
+       MainLoop M;
+       error_e error = ERROR_NONE;
+
+       error = InvokeMethodNonblock(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_GET_CHAIN,
+               NULL,
+               DBUS_REPLY_TIMEOUT,
+               AsyncReadyCallback,
+               &M);
+
+       if (error != ERROR_NONE) {
+               GLOGD("Failed to invoke dbus method nonblock");
+               return error;
+       }
+
+       GLOGD("Succeeded to get all restriction");
+
+       M.run(GMAINTIMEOUT);
+       return ERROR_NONE;
+}
+
+error_e Firewall::RemoveChain(const char *chain)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_REMOVE_CHAIN,
+               g_variant_new("(s)", chain),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::AddChain(const char *chain)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_ADD_CHAIN,
+               g_variant_new("(s)", chain),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to set restriction [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::GetLock(int *state)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_GET_LOCK,
+               NULL,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &state);
+       GLOGD("Succeeded to get lock state[%d]", state);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::Unlock()
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_UNLOCK,
+               NULL,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to unlock result[%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Firewall::Lock()
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_MGR_SERVICE,
+               STC_MGR_FIREWALL_PATH,
+               STC_MGR_FIREWALL_INTERFACE,
+               STC_MGR_METHOD_FIREWALL_LOCK,
+               NULL,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to unlock result[%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
diff --git a/unittest/firewall.h b/unittest/firewall.h
new file mode 100644 (file)
index 0000000..f52e10b
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_MGR_FIREWALL_H__
+#define __STC_MGR_FIREWALL_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define FIREWALL_RULE_CHAIN      "chain"
+#define FIREWALL_RULE_DIRECTION  "direction"
+#define FIREWALL_RULE_IFNAME     "ifname"
+#define FIREWALL_RULE_PROTOCOL   "protocol"
+#define FIREWALL_RULE_TARGET     "target"
+#define FIREWALL_RULE_TARGETTYPE "target_type"
+
+#define FIREWALL_RULE_FAMILY     "family"
+#define FIREWALL_RULE_SIPTYPE    "s_ip_type"
+#define FIREWALL_RULE_SIP1       "s_ip1"
+#define FIREWALL_RULE_SIP2       "s_ip2"
+#define FIREWALL_RULE_DIPTYPE    "d_ip_type"
+#define FIREWALL_RULE_DIP1       "d_ip1"
+#define FIREWALL_RULE_DIP2       "d_ip2"
+#define FIREWALL_RULE_SPORTTYPE  "s_port_type"
+#define FIREWALL_RULE_SPORT1     "s_port1"
+#define FIREWALL_RULE_SPORT2     "s_port2"
+#define FIREWALL_RULE_DPORTTYPE  "d_port_type"
+#define FIREWALL_RULE_DPORT1     "d_port1"
+#define FIREWALL_RULE_DPORT2     "d_port2"
+
+#define FIREWALL_RULE_LOG_LEVEL       "log_level"
+#define FIREWALL_RULE_LOG_PREFIX      "log_prefix"
+#define FIREWALL_RULE_NFLOG_GROUP     "nflog_group"
+#define FIREWALL_RULE_NFLOG_PREFIX    "nflog_prefix"
+#define FIREWALL_RULE_NFLOG_RANGE     "nflog_range"
+#define FIREWALL_RULE_NFLOG_THRESHOLD "nflog_threshold"
+
+#define CHAIN_LEN 256
+#define IFACE_LEN 256
+#define IP_LEN 16
+
+class FRule {
+private:
+public:
+       char chain[CHAIN_LEN];
+       guint16 direction;
+       guint16 siptype;
+       guint16 diptype;
+       guint16 sporttype;
+       guint16 dporttype;
+       guint16 protocol;
+       guint16 family;
+       char sip1[IP_LEN];
+       char dip1[IP_LEN];
+       char sip2[IP_LEN];
+       char dip2[IP_LEN];
+       guint32 dport1;
+       guint32 dport2;
+       guint32 sport1;
+       guint32 sport2;
+       char iface[IFACE_LEN];
+       guint16 target;
+
+       FRule();
+       ~FRule();
+};
+
+class Firewall : public GDbus {
+private:
+       FRule m_Rule;
+public:
+       Firewall();
+       ~Firewall();
+       error_e SetRule(const char *app_id, const char *iface_name,
+               const char *subscriber_id, iface_type_e iface_type,
+               int64_t data_limit, int64_t data_warn_limit,
+               roaming_type_e roaming_type, const char *mac);
+       void MakeRuleParams(GVariant **params);
+       void MakeGetParams(GVariant **params);
+       void MakeStatusParams(GVariant **params);
+       error_e Lock(void);
+       error_e Unlock(void);
+       error_e GetLock(int *state);
+       error_e AddChain(const char * chain);
+       error_e RemoveChain(const char * chain);
+       error_e FlushChain(const char * chain);
+       error_e GetAllChain();
+       error_e SetChain(const char *chain, unsigned int target);
+       error_e UnsetChain(const char *chain);
+       error_e SetRule(const char *chain, guint16 direction,
+                       guint16 siptype, guint16 diptype, guint16 sporttype,
+                       guint16 dporttype, guint16 protocol, guint16 family,
+                       const char *sip1, const char *dip1, const char *sip2,
+                       const char *dip2, guint32 dport1, guint32 dport2,
+                       guint32 sport1, guint32 sport2, const char *iface,
+                       guint16 target);
+       error_e AddRule();
+       error_e RemoveRule();
+       error_e UpdateRule();
+       error_e GetAllRule();
+};
+
+#endif /* __STC_MGR_FIREWALL_H__ */
index 91596a942d3b4847dd4116a5eb26e985cd5b59b5..f5456299b43d1918420718de3e02d6a009f031cc 100644 (file)
 #define STC_MGR_STATISTICS_INTERFACE    STC_MGR_SERVICE ".statistics"
 #define STC_MGR_RESTRICTION_INTERFACE   STC_MGR_SERVICE ".restriction"
 #define STC_MGR_MANAGER_INTERFACE       STC_MGR_SERVICE ".manager"
+#define STC_MGR_FIREWALL_INTERFACE      STC_MGR_SERVICE ".firewall"
 
 #define STC_MGR_STATISTICS_PATH         "/net/stc/statistics"
 #define STC_MGR_RESTRICTION_PATH        "/net/stc/restriction"
 #define STC_MGR_MANAGER_PATH            "/net/stc/manager"
+#define STC_MGR_FIREWALL_PATH           "/net/stc/firewall"
 
 #define STC_MGR_METHOD_STATISTICS_INIT              "Init"
 #define STC_MGR_METHOD_STATISTICS_GET_PER_APP_ID    "Get"
 
 #define STC_MGR_METHOD_MANAGER_STOP                 "Stop"
 
+#define STC_MGR_METHOD_FIREWALL_GET_ALL             "GetAllRule"
+#define STC_MGR_METHOD_FIREWALL_UPDATE              "UpdateRule"
+#define STC_MGR_METHOD_FIREWALL_REMOVE              "RemoveRule"
+#define STC_MGR_METHOD_FIREWALL_ADD                 "AddRule"
+#define STC_MGR_METHOD_FIREWALL_SET                 "SetChain"
+#define STC_MGR_METHOD_FIREWALL_UNSET               "UnsetChain"
+#define STC_MGR_METHOD_FIREWALL_FLUSH               "FlushChain"
+#define STC_MGR_METHOD_FIREWALL_GET_CHAIN           "GetAllChain"
+#define STC_MGR_METHOD_FIREWALL_REMOVE_CHAIN        "RemoveChain"
+#define STC_MGR_METHOD_FIREWALL_ADD_CHAIN           "AddChain"
+#define STC_MGR_METHOD_FIREWALL_GET_LOCK            "GetLock"
+#define STC_MGR_METHOD_FIREWALL_LOCK                "Lock"
+#define STC_MGR_METHOD_FIREWALL_UNLOCK              "Unlock"
+
 class GDbus {
 private:
        GDBusConnection *m_pConnection;
index 0c09ddccb6dd90042b0f196fdaba77eb45ca342b..9a3bb4b09b2f476c573fe8fa657c7c6f798b5f0c 100644 (file)
 #include <gtest/gtest.h>
 
 #include "restriction.h"
-
-static GMainLoop *g_pMainLoop = NULL;
-static guint g_nTimeoutId = 0;
-
-static gboolean CallbackTimeut(gpointer data)
-{
-       if (g_pMainLoop)
-               g_main_loop_quit(g_pMainLoop);
-
-       return false;
-}
-
-static void RunMainLoop(void)
-{
-       g_pMainLoop = g_main_loop_new(NULL, false);
-       g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop);
-       g_main_loop_run(g_pMainLoop);
-
-       g_source_remove(g_nTimeoutId);
-       g_pMainLoop = NULL;
-}
-
-static void QuitMainLoop(void)
-{
-       if (g_pMainLoop)
-               g_main_loop_quit(g_pMainLoop);
-}
+#include "common.h"
 
 static void AsyncReadyCallback(GObject *source_object,
        GAsyncResult *res, gpointer user_data)
 {
+       MainLoop *M = (MainLoop *)user_data;
        GLOGD("Succeeded to response async callback");
-       QuitMainLoop();
+       M->quit();
 }
 
 RRule::RRule()
@@ -84,7 +59,7 @@ Restriction::~Restriction()
 error_e Restriction::SetRule(const char *app_id, const char *iface_name,
                const char *subscriber_id, iface_type_e iface_type,
                int64_t data_limit, int64_t data_warn_limit,
-               roaming_type_e roaming_type)
+               roaming_type_e roaming_type, const char *mac)
 {
        if (app_id == NULL || strlen(app_id) == 0)
                this->m_Rule.m_AppID[0] = '\0';
@@ -101,6 +76,11 @@ error_e Restriction::SetRule(const char *app_id, const char *iface_name,
        else
                g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN);
 
+       if (mac == NULL || strlen(mac) == 0)
+               this->m_Rule.m_Mac[0] = '\0';
+       else
+               g_strlcpy(this->m_Rule.m_Mac, mac, MAC_LEN);
+
        switch(iface_type) {
        case IFACE_UNKNOWN:
        case IFACE_DATACALL:
@@ -164,6 +144,11 @@ void Restriction::MakeRuleParams(GVariant **params)
                RESTRICTION_RULE_DATA_WARN_LIMIT,
                g_variant_new_int64(this->m_Rule.m_DataWarnLimit));
 
+       g_variant_builder_add(builder, "{sv}",
+               RESTRICTION_RULE_MAC,
+               g_variant_new_string(this->m_Rule.m_Mac));
+
+
        *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
        g_variant_builder_unref(builder);
 }
@@ -293,6 +278,7 @@ error_e Restriction::GetRstrictionStatus(restriction_status_e *status)
 
 error_e Restriction::GetRstriction(void)
 {
+       MainLoop M;
        GVariant *params = NULL;
        error_e error = ERROR_NONE;
 
@@ -305,7 +291,7 @@ error_e Restriction::GetRstriction(void)
                params,
                DBUS_REPLY_TIMEOUT,
                AsyncReadyCallback,
-               NULL);
+               &M);
 
        if (error != ERROR_NONE) {
                GLOGD("Failed to invoke dbus method nonblock");
@@ -314,12 +300,13 @@ error_e Restriction::GetRstriction(void)
 
        GLOGD("Succeeded to get restriction per app ID");
 
-       RunMainLoop();
+       M.run(GMAINTIMEOUT);
        return ERROR_NONE;
 }
 
 error_e Restriction::GetAllRstriction(void)
 {
+       MainLoop M;
        error_e error = ERROR_NONE;
 
        error = InvokeMethodNonblock(STC_MGR_SERVICE,
@@ -329,7 +316,7 @@ error_e Restriction::GetAllRstriction(void)
                NULL,
                DBUS_REPLY_TIMEOUT,
                AsyncReadyCallback,
-               NULL);
+               &M);
 
        if (error != ERROR_NONE) {
                GLOGD("Failed to invoke dbus method nonblock");
@@ -338,6 +325,6 @@ error_e Restriction::GetAllRstriction(void)
 
        GLOGD("Succeeded to get all restriction");
 
-       RunMainLoop();
+       M.run(GMAINTIMEOUT);
        return ERROR_NONE;
-}
\ No newline at end of file
+}
index c0b0f2dadd2236ffc8f67eb28563ae5e9a45c20a..06cbf2c5c2bb8fcf7648b3325b989c379c4f63c1 100644 (file)
@@ -29,6 +29,7 @@
 #define RESTRICTION_RULE_SUBSCRIBER_ID      "subscriber_id"
 #define RESTRICTION_RULE_DATA_LIMIT         "data_limit"
 #define RESTRICTION_RULE_DATA_WARN_LIMIT    "data_warn_limit"
+#define RESTRICTION_RULE_MAC                "mac"
 
 typedef enum {
        RESTRICTION_UNKNOWN,
@@ -45,6 +46,7 @@ public:
        char m_AppID[APP_ID_LEN];
        char m_IfaceName[IFNAME_LEN];
        char m_SubscriberID[SUBSCRIBER_ID_LEN];
+       char m_Mac[MAC_LEN];
        iface_type_e m_IfaceType;
        int64_t m_DataLimit;
        int64_t m_DataWarnLimit;
@@ -63,7 +65,7 @@ public:
        error_e SetRule(const char *app_id, const char *iface_name,
                const char *subscriber_id, iface_type_e iface_type,
                int64_t data_limit, int64_t data_warn_limit,
-               roaming_type_e roaming_type);
+               roaming_type_e roaming_type, const char *mac);
        void MakeRuleParams(GVariant **params);
        void MakeGetParams(GVariant **params);
        void MakeStatusParams(GVariant **params);
index 49ebd6a29818d156704d22a9476a4c9773b963be..2b4b5e592384cdd7fdf778055c858cbcd136a787 100644 (file)
 #include <gtest/gtest.h>
 
 #include "statistics.h"
-
-static GMainLoop *g_pMainLoop = NULL;
-static guint g_nTimeoutId = 0;
-
-static gboolean CallbackTimeut(gpointer data)
-{
-       if (g_pMainLoop)
-               g_main_loop_quit(g_pMainLoop);
-
-       return false;
-}
-
-static void RunMainLoop(void)
-{
-       g_pMainLoop = g_main_loop_new(NULL, false);
-       g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop);
-       g_main_loop_run(g_pMainLoop);
-
-       g_source_remove(g_nTimeoutId);
-       g_pMainLoop = NULL;
-}
-
-static void QuitMainLoop(void)
-{
-       if (g_pMainLoop)
-               g_main_loop_quit(g_pMainLoop);
-}
+#include "common.h"
 
 static void AsyncReadyCallback(GObject *source_object,
        GAsyncResult *res, gpointer user_data)
 {
+       MainLoop *M = (MainLoop *)user_data;
        GLOGD("Succeeded to response async callback");
-       QuitMainLoop();
+       M->quit();
 }
 
 SRule::SRule()
@@ -209,6 +184,7 @@ error_e Statistics::InitStatistics(void)
 
 error_e Statistics::GetStatistics(void)
 {
+       MainLoop M;
        GVariant *params = NULL;
        error_e error = ERROR_NONE;
 
@@ -221,14 +197,14 @@ error_e Statistics::GetStatistics(void)
                params,
                DBUS_REPLY_TIMEOUT,
                AsyncReadyCallback,
-               NULL);
+               &M);
 
        if (error != ERROR_NONE) {
                GLOGD("Failed to invoke dbus method nonblock");
                return error;
        }
 
-       RunMainLoop();
+       M.run(GMAINTIMEOUT);
        GLOGD("Succeeded to get statistics per app ID");
 
        return ERROR_NONE;
@@ -236,6 +212,7 @@ error_e Statistics::GetStatistics(void)
 
 error_e Statistics::GetTotalStatistics(void)
 {
+       MainLoop M;
        GVariant *params = NULL;
        error_e error = ERROR_NONE;
 
@@ -248,14 +225,14 @@ error_e Statistics::GetTotalStatistics(void)
                params,
                DBUS_REPLY_TIMEOUT,
                AsyncReadyCallback,
-               NULL);
+               &M);
 
        if (error != ERROR_NONE) {
                GLOGD("Failed to invoke dbus method nonblock");
                return error;
        }
 
-       RunMainLoop();
+       M.run(GMAINTIMEOUT);
        GLOGD("Succeeded to get total statistics");
 
        return ERROR_NONE;
@@ -263,6 +240,7 @@ error_e Statistics::GetTotalStatistics(void)
 
 error_e Statistics::GetAllStatistics(void)
 {
+       MainLoop M;
        GVariant *params = NULL;
        error_e error = ERROR_NONE;
 
@@ -275,14 +253,14 @@ error_e Statistics::GetAllStatistics(void)
                params,
                DBUS_REPLY_TIMEOUT,
                AsyncReadyCallback,
-               NULL);
+               &M);
 
        if (error != ERROR_NONE) {
                GLOGD("Failed to invoke dbus method nonblock");
                return error;
        }
 
-       RunMainLoop();
+       M.run(GMAINTIMEOUT);
        GLOGD("Succeeded to get all statistics");
 
        return ERROR_NONE;
index 79f9c2c3bd5d06b0cf8bfa331bffcfbe34ed52fb..888544e95f46613e0886443229d1f2568b3855c1 100644 (file)
@@ -21,6 +21,7 @@
 #define APP_ID_LEN 128
 #define IFNAME_LEN 16
 #define SUBSCRIBER_ID_LEN 128
+#define MAC_LEN 18
 
 #ifdef USE_DLOG
 #include <dlog.h>
index 11410214aa7bb28d4fd28c0da1d51886698e724a..8b467f7afd4e438f3dfdbc791074cce9abf011c7 100644 (file)
 #include "restriction.h"
 #include "statistics.h"
 #include "manager.h"
+#include "stc-manager.h"
+#include "firewall.h"
+
+#define GTEST_MAC "1:c:e:b:00:da"
 
 using ::testing::InitGoogleTest;
 using ::testing::Test;
 using ::testing::TestCase;
 
+typedef enum {
+       FIREWALL_UNKONWN,
+       FIREWALL_UNLOCKED,
+       FIREWALL_LOCKED
+} firewall_lock_e;
+
 TEST(StcManager_Statistics, Init_p)
 {
        error_e ret = ERROR_NONE;
@@ -138,7 +148,8 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
@@ -150,7 +161,8 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_WIFI,
                2,
                1,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
@@ -162,32 +174,14 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_WIRED,
                100000,
                80000,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
-TEST(StcManager_Restriction, Exclude_p)
-
-{
-       error_e ret = ERROR_NONE;
-       Restriction rest;
-
-       ret = rest.SetRule("TOTAL_DATACALL",
-               "seth_w0",
-               NULL,
-               IFACE_DATACALL,
-               0,
-               0,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.ExcludeRstriction();
-       EXPECT_EQ(ERROR_NONE, ret);
-}
-
 TEST(StcManager_Restriction, Get_p)
 {
        error_e ret = ERROR_NONE;
@@ -199,7 +193,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -211,7 +206,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_WIFI,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -223,7 +219,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -239,40 +236,6 @@ TEST(StcManager_Restriction, GetAll_p)
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
-TEST(StcManager_Restriction, GetRst_p)
-{
-       error_e ret = ERROR_NONE;
-       Restriction rest;
-       restriction_status_e status = RESTRICTION_UNKNOWN;
-
-       ret = rest.SetRule("Test_tel",
-               "seth_w0",
-               NULL,
-               IFACE_DATACALL,
-               0,
-               0,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.GetRstrictionStatus(&status);
-       EXPECT_EQ(ERROR_NONE, ret);
-       EXPECT_LE(RESTRICTION_UNKNOWN, status);
-       EXPECT_GE(RESTRICTION_LAST_ELEM, status);
-
-       ret = rest.SetRule("Test_eth",
-               "eth0",
-               NULL,
-               IFACE_WIRED,
-               100000,
-               80000,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.GetRstrictionStatus(&status);
-       EXPECT_EQ(ERROR_NONE, ret);
-       EXPECT_LE(RESTRICTION_UNKNOWN, status);
-       EXPECT_GE(RESTRICTION_LAST_ELEM, status);
-}
 
 TEST(StcManager_Restriction, Unset_p)
 {
@@ -285,7 +248,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -297,7 +261,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_WIFI,
                2,
                1,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -309,7 +274,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_WIRED,
                100000,
                80000,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -321,7 +287,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -361,6 +328,269 @@ TEST(StcManager_Statistics, Reset_p)
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
+TEST(StcManager_Firewall, Lock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       if (state == FIREWALL_LOCKED)
+               f.Unlock();
+
+       ret = f.Lock();
+       EXPECT_EQ(ERROR_NONE, ret);
+       f.Unlock();
+}
+
+TEST(StcManager_Firewall, Unlock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       if (state != FIREWALL_LOCKED)
+               f.Lock();
+
+       ret = f.Unlock();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetLock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.AddChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddRule_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_ACCEPT);
+
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.AddRule();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.AddRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UpdateRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.UpdateRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, RemoveRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.RemoveRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+
+TEST(StcManager_Firewall, SetChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetChain("gtest", 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, SetChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetChain(NULL, 0);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UnsetChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.UnsetChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UnsetChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.UnsetChain(NULL);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+
+TEST(StcManager_Firewall, RemoveChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.RemoveChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, RemoveChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.RemoveChain("not_a_chain");
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, FlushChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.AddChain("gtest_chains");
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.FlushChain("gtest_chains");
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       f.RemoveChain("gtest_chains");
+}
+
+
+TEST(StcManager_Firewall, FlushChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.FlushChain(NULL);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetAllChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.GetAllChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetAllRule_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.GetAllRule();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
 TEST(StcManager_Manager, Stop_p)
 {
        error_e ret = ERROR_NONE;