summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shared/condition-util.c3
-rw-r--r--src/test/test-condition-util.c57
2 files changed, 59 insertions, 1 deletions
diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index 7569b40d6d..749b57712a 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -45,7 +45,9 @@ Condition* condition_new(ConditionType type, const char *parameter, bool trigger
Condition *c;
int r;
+ assert(type >= 0);
assert(type < _CONDITION_TYPE_MAX);
+ assert(!parameter == (type == CONDITION_NULL));
c = new0(Condition, 1);
if (!c)
@@ -397,7 +399,6 @@ static int condition_test_file_is_executable(Condition *c) {
static int condition_test_null(Condition *c) {
assert(c);
- assert(c->parameter);
assert(c->type == CONDITION_NULL);
/* Note that during parsing we already evaluate the string and
diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
index 4f9ae8ab90..b69e62bfd3 100644
--- a/src/test/test-condition-util.c
+++ b/src/test/test-condition-util.c
@@ -31,6 +31,18 @@ static void test_condition_test_path_exists(void) {
assert_se(condition_test(condition));
condition_free(condition);
+ condition = condition_new(CONDITION_PATH_EXISTS, "/bin/s?", false, false);
+ assert_se(!condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, true);
+ assert_se(!condition_test(condition));
+ condition_free(condition);
+
condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, false);
assert_se(!condition_test(condition));
condition_free(condition);
@@ -38,6 +50,38 @@ static void test_condition_test_path_exists(void) {
condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, true);
assert_se(condition_test(condition));
condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_IS_DIRECTORY, "/bin", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_DIRECTORY_NOT_EMPTY, "/bin", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_FILE_NOT_EMPTY, "/bin/sh", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/bin/sh", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/etc/passwd", false, false);
+ assert_se(!condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/proc", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/", false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false);
+ assert_se(!condition_test(condition));
+ condition_free(condition);
}
static void test_condition_test_ac_power(void) {
@@ -123,6 +167,18 @@ static void test_condition_test_kernel_command_line(void) {
condition_free(condition);
}
+static void test_condition_test_null(void) {
+ Condition *condition;
+
+ condition = condition_new(CONDITION_NULL, NULL, false, false);
+ assert_se(condition_test(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_NULL, NULL, false, true);
+ assert_se(!condition_test(condition));
+ condition_free(condition);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -132,6 +188,7 @@ int main(int argc, char *argv[]) {
test_condition_test_host();
test_condition_test_architecture();
test_condition_test_kernel_command_line();
+ test_condition_test_null();
return 0;
}