diff options
| author | Lorenzo Colitti <lorenzo@google.com> | 2017-04-28 00:03:56 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-04-28 00:03:57 +0000 |
| commit | 680ff87319d206a70efc162eb3c95ad0c429c44d (patch) | |
| tree | 6fa4418d7879af2e771a0094017ebbdbd475ed89 /server/BandwidthControllerTest.cpp | |
| parent | 43b3b4e8cdbb4e644f59a9bf720e587f55dd8a40 (diff) | |
| parent | 4773cb4e74f037b7e82f7394474ead52657560c5 (diff) | |
Merge changes Ic2b692ef,Iaa8daba0,Ie39a6eac,I8e159405,I8224b4cc
* changes:
Properly report failure in runIptablesAlertCmd.
Move enableChildChains to iptables-restore.
Add test coverage for enableChildChains.
Move runIptablesAlert{,Fwd}Cmd to iptables-restore.
Add test coverage for IptablesAlert{,Fwd}Cmd.
Diffstat (limited to 'server/BandwidthControllerTest.cpp')
| -rw-r--r-- | server/BandwidthControllerTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/server/BandwidthControllerTest.cpp b/server/BandwidthControllerTest.cpp index c6b21d8f..487b7d8b 100644 --- a/server/BandwidthControllerTest.cpp +++ b/server/BandwidthControllerTest.cpp @@ -102,6 +102,16 @@ public: expectIptablesRestoreCommands(expected); } + + using IptOp = BandwidthController::IptOp; + + int runIptablesAlertCmd(IptOp a, const char *b, int64_t c) { + return mBw.runIptablesAlertCmd(a, b, c); + } + + int runIptablesAlertFwdCmd(IptOp a, const char *b, int64_t c) { + return mBw.runIptablesAlertFwdCmd(a, b, c); + } }; TEST_F(BandwidthControllerTest, TestSetupIptablesHooks) { @@ -388,3 +398,41 @@ TEST_F(BandwidthControllerTest, TestSetInterfaceQuota) { EXPECT_EQ(0, mBw.removeInterfaceQuota(iface)); expectIptablesCommands(expected); } + +TEST_F(BandwidthControllerTest, IptablesAlertCmd) { + std::vector<std::string> expected = { + "*filter\n" + "-I bw_INPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "-I bw_OUTPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "COMMIT\n" + }; + EXPECT_EQ(0, runIptablesAlertCmd(IptOp::IptOpInsert, "MyWonderfulAlert", 123456)); + expectIptablesRestoreCommands(expected); + + expected = { + "*filter\n" + "-D bw_INPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "-D bw_OUTPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "COMMIT\n" + }; + EXPECT_EQ(0, runIptablesAlertCmd(IptOp::IptOpDelete, "MyWonderfulAlert", 123456)); + expectIptablesRestoreCommands(expected); +} + +TEST_F(BandwidthControllerTest, IptablesAlertFwdCmd) { + std::vector<std::string> expected = { + "*filter\n" + "-I bw_FORWARD -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "COMMIT\n" + }; + EXPECT_EQ(0, runIptablesAlertFwdCmd(IptOp::IptOpInsert, "MyWonderfulAlert", 123456)); + expectIptablesRestoreCommands(expected); + + expected = { + "*filter\n" + "-D bw_FORWARD -m quota2 ! --quota 123456 --name MyWonderfulAlert\n" + "COMMIT\n" + }; + EXPECT_EQ(0, runIptablesAlertFwdCmd(IptOp::IptOpDelete, "MyWonderfulAlert", 123456)); + expectIptablesRestoreCommands(expected); +} |
