Add a test for setUidCleartextPolicy.
Bug: 28362720
Test: netd_{unit,integration}_test pass
Change-Id: Ie4577b29230282e0e6c9ae0ae6727af78e8b0849
diff --git a/server/StrictControllerTest.cpp b/server/StrictControllerTest.cpp
index c0c8839..3783c30 100644
--- a/server/StrictControllerTest.cpp
+++ b/server/StrictControllerTest.cpp
@@ -122,3 +122,31 @@
"COMMIT\n";
expectIptablesRestoreCommands({ expected });
}
+
+TEST_F(StrictControllerTest, TestSetUidCleartextPenalty) {
+ std::vector<std::string> acceptCommands = {
+ "-D st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect",
+ "-D st_clear_caught -m owner --uid-owner 12345 -j st_penalty_log",
+ "-D st_clear_caught -m owner --uid-owner 12345 -j st_penalty_reject",
+ };
+ std::vector<std::string> logCommands = {
+ "-I st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect",
+ "-I st_clear_caught -m owner --uid-owner 12345 -j st_penalty_log",
+ };
+ std::vector<std::string> rejectCommands = {
+ "-I st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect",
+ "-I st_clear_caught -m owner --uid-owner 12345 -j st_penalty_reject",
+ };
+
+ mStrictCtrl.setUidCleartextPenalty(12345, LOG);
+ expectIptablesCommands(logCommands);
+
+ mStrictCtrl.setUidCleartextPenalty(12345, ACCEPT);
+ expectIptablesCommands(acceptCommands);
+
+ mStrictCtrl.setUidCleartextPenalty(12345, REJECT);
+ expectIptablesCommands(rejectCommands);
+
+ mStrictCtrl.setUidCleartextPenalty(12345, ACCEPT);
+ expectIptablesCommands(acceptCommands);
+}