test-condition.c revision 015df1f78f443f91b354e0c4b4cb76de86c838eb
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Ronny Chevalier
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void test_condition_test_path(void) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering condition = condition_new(CONDITION_PATH_EXISTS, "/bin/s?", false, false);
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek assert_se(!condition_test(condition));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, false);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, true);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, false);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, true);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_PATH_IS_DIRECTORY, "/bin", false, false);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_DIRECTORY_NOT_EMPTY, "/bin", false, false);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_FILE_NOT_EMPTY, "/bin/sh", false, false);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/bin/sh", false, false);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/etc/passwd", false, false);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/proc", false, false);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/", false, false);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering condition = condition_new(CONDITION_PATH_IS_READ_WRITE, "/tmp", false, false);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void test_condition_test_ac_power(void) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_AC_POWER, "true", false, false);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering assert_se(condition_test(condition) == on_ac_power());
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering condition = condition_new(CONDITION_AC_POWER, "false", false, false);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering assert_se(condition_test(condition) != on_ac_power());
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_AC_POWER, "false", false, true);
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering assert_se(condition_test(condition) == on_ac_power());
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poetteringstatic void test_condition_test_host(void) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_HOST, sid, false, false);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_HOST, "garbage value jjjjjjjjjjjjjj", false, false);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition = condition_new(CONDITION_HOST, sid, false, true);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering condition = condition_new(CONDITION_HOST, hostname, false, false);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poetteringstatic void test_condition_test_architecture(void) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert_se(condition_test(condition));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert_se(condition_test(condition) < 0);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersenstatic void test_condition_test_kernel_command_line(void) {
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmekstatic void test_condition_test_null(void) {
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering condition = condition_new(CONDITION_NULL, NULL, false, false);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_NULL, NULL, false, true);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek assert_se(!condition_test(condition));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekstatic void test_condition_test_security(void) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek assert_se(!condition_test(condition));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek condition = condition_new(CONDITION_SECURITY, "selinux", false, true);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek assert_se(condition_test(condition) != mac_selinux_use());
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen condition = condition_new(CONDITION_SECURITY, "ima", false, false);
9ead3519c54b6d1b79b35541873b5cf7c8b3a7d3Lennart Poettering assert_se(condition_test(condition) == use_ima());
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen condition = condition_new(CONDITION_SECURITY, "apparmor", false, false);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen assert_se(condition_test(condition) == mac_apparmor_use());
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen condition = condition_new(CONDITION_SECURITY, "smack", false, false);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen assert_se(condition_test(condition) == mac_smack_use());
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen condition = condition_new(CONDITION_SECURITY, "audit", false, false);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen assert_se(condition_test(condition) == use_audit());