Blame SOURCES/extend_unit_test_for_is_local_fs.patch

fa2dd6
From 673f338641ca90b31f00e0787cdcbb5fb19a49a1 Mon Sep 17 00:00:00 2001
fa2dd6
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
fa2dd6
Date: Thu, 23 May 2019 09:07:17 +0200
fa2dd6
Subject: [PATCH 1/2] Extend unit test for is_local_fs from fsdev.h
fa2dd6
fa2dd6
The test uses a fake `mtab` file which contains 1 entry for a local
fa2dd6
filesystem, 1 entry for a direct autofs map and 1 entry for a NFS
fa2dd6
system mounted using autofs. By parsing the `mtab` file only 1 local
fa2dd6
filesystem should be found. It will help us to test
fa2dd6
https://github.com/OpenSCAP/openscap/pull/1329
fa2dd6
---
fa2dd6
 tests/API/probes/Makefile.am              |  2 ++
fa2dd6
 tests/API/probes/fake_mtab                |  3 ++
fa2dd6
 tests/API/probes/test_fsdev_is_local_fs.c | 36 +++++++++++++++++++++--
fa2dd6
 3 files changed, 38 insertions(+), 3 deletions(-)
fa2dd6
 create mode 100644 tests/API/probes/fake_mtab
fa2dd6
fa2dd6
diff --git a/tests/API/probes/Makefile.am b/tests/API/probes/Makefile.am
fa2dd6
index 70442bcc3..459e5f3af 100644
fa2dd6
--- a/tests/API/probes/Makefile.am
fa2dd6
+++ b/tests/API/probes/Makefile.am
fa2dd6
@@ -1,4 +1,5 @@
fa2dd6
 AM_CPPFLAGS = \
fa2dd6
+	-DDATADIR=\"$(srcdir)/\" \
fa2dd6
 	-I$(top_srcdir)/src \
fa2dd6
 	-I$(top_srcdir)/src/CCE/public \
fa2dd6
 	-I$(top_srcdir)/src/CPE/public \
fa2dd6
@@ -35,6 +36,7 @@ test_fsdev_is_local_fs_SOURCES = test_fsdev_is_local_fs.c
fa2dd6
 
fa2dd6
 EXTRA_DIST += \
fa2dd6
 	all.sh \
fa2dd6
+	fake_mtab \
fa2dd6
 	fts.sh \
fa2dd6
 	gentree.sh \
fa2dd6
 	test_api_probes_smoke.c \
fa2dd6
diff --git a/tests/API/probes/fake_mtab b/tests/API/probes/fake_mtab
fa2dd6
new file mode 100644
fa2dd6
index 000000000..26d6918bb
fa2dd6
--- /dev/null
fa2dd6
+++ b/tests/API/probes/fake_mtab
fa2dd6
@@ -0,0 +1,3 @@
fa2dd6
+/dev/mapper/fedora-root / ext4 rw,seclabel,relatime 0 0
fa2dd6
+/etc/mount.map /nfs/test autofs rw,relatime,fd=17,pgrp=11111,timeout=5,minproto=5,maxproto=5,direct,pipe_ino=1246883 0 0
fa2dd6
+192.168.122.231:/test /nfs/test nfs4 rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.231 0 0
fa2dd6
diff --git a/tests/API/probes/test_fsdev_is_local_fs.c b/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
index bcc596442..143030070 100644
fa2dd6
--- a/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
+++ b/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
@@ -29,13 +29,43 @@
fa2dd6
 #include <mntent.h>
fa2dd6
 #include "fsdev.h"
fa2dd6
 
fa2dd6
-int main(int argc, char *argv[])
fa2dd6
+static int test_single_call()
fa2dd6
 {
fa2dd6
 	struct mntent ment;
fa2dd6
 	ment.mnt_type = "autofs";
fa2dd6
 	int ret = is_local_fs(&ment);
fa2dd6
-	if (ret != 0) {
fa2dd6
+	/* autofs entry is never considered local */
fa2dd6
+	return (ret == 0);
fa2dd6
+}
fa2dd6
+
fa2dd6
+static int test_multiple_calls()
fa2dd6
+{
fa2dd6
+	/* fake mtab contains only 1 local filesystem */
fa2dd6
+	FILE *f = setmntent(DATADIR "fake_mtab", "r");
fa2dd6
+	if (f == NULL) {
fa2dd6
+		fprintf(stderr, "fake_mtab could not be open\n");
fa2dd6
+		return 0;
fa2dd6
+	}
fa2dd6
+	struct mntent *ment;
fa2dd6
+	unsigned int locals = 0;
fa2dd6
+	while ((ment = getmntent(f)) != NULL) {
fa2dd6
+		if (is_local_fs(ment)) {
fa2dd6
+			locals++;
fa2dd6
+		}
fa2dd6
+	}
fa2dd6
+	endmntent(f);
fa2dd6
+	return (locals == 1);
fa2dd6
+}
fa2dd6
+
fa2dd6
+int main(int argc, char *argv[])
fa2dd6
+{
fa2dd6
+	if (!test_single_call()) {
fa2dd6
+		fprintf(stderr, "test_single_call has failed\n");
fa2dd6
+		return 1;
fa2dd6
+	}
fa2dd6
+	if (!test_multiple_calls()) {
fa2dd6
+		fprintf(stderr, "test_multiple_calls has failed\n");
fa2dd6
 		return 1;
fa2dd6
 	}
fa2dd6
 	return 0;
fa2dd6
-}
fa2dd6
\ No newline at end of file
fa2dd6
+}
fa2dd6
fa2dd6
From 4f8fcd1a85c6840895672b7912592cc9f3c92b01 Mon Sep 17 00:00:00 2001
fa2dd6
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
fa2dd6
Date: Fri, 24 May 2019 13:48:59 +0200
fa2dd6
Subject: [PATCH 2/2] Add more entries into fake mtab
fa2dd6
fa2dd6
---
fa2dd6
 tests/API/probes/fake_mtab                | 4 ++++
fa2dd6
 tests/API/probes/test_fsdev_is_local_fs.c | 7 +++++--
fa2dd6
 2 files changed, 9 insertions(+), 2 deletions(-)
fa2dd6
fa2dd6
diff --git a/tests/API/probes/fake_mtab b/tests/API/probes/fake_mtab
fa2dd6
index 26d6918bb..94b1fe295 100644
fa2dd6
--- a/tests/API/probes/fake_mtab
fa2dd6
+++ b/tests/API/probes/fake_mtab
fa2dd6
@@ -1,3 +1,7 @@
fa2dd6
 /dev/mapper/fedora-root / ext4 rw,seclabel,relatime 0 0
fa2dd6
+tmpfs /tmp tmpfs rw,seclabel,nosuid,nodev 0 0
fa2dd6
 /etc/mount.map /nfs/test autofs rw,relatime,fd=17,pgrp=11111,timeout=5,minproto=5,maxproto=5,direct,pipe_ino=1246883 0 0
fa2dd6
 192.168.122.231:/test /nfs/test nfs4 rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.231 0 0
fa2dd6
+/dev/mapper/fedora-home /home ext4 rw,seclabel,relatime 0 0
fa2dd6
+proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
fa2dd6
+//192.168.0.5/storage /media/movies cifs guest,uid=myuser,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm 0 0
fa2dd6
diff --git a/tests/API/probes/test_fsdev_is_local_fs.c b/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
index 143030070..e3b4691db 100644
fa2dd6
--- a/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
+++ b/tests/API/probes/test_fsdev_is_local_fs.c
fa2dd6
@@ -40,7 +40,10 @@ static int test_single_call()
fa2dd6
 
fa2dd6
 static int test_multiple_calls()
fa2dd6
 {
fa2dd6
-	/* fake mtab contains only 1 local filesystem */
fa2dd6
+	/*
fa2dd6
+	 * fake mtab contains only 4 local filesystems:
fa2dd6
+	 * /, /tmp, /home and /proc
fa2dd6
+	 */
fa2dd6
 	FILE *f = setmntent(DATADIR "fake_mtab", "r");
fa2dd6
 	if (f == NULL) {
fa2dd6
 		fprintf(stderr, "fake_mtab could not be open\n");
fa2dd6
@@ -54,7 +57,7 @@ static int test_multiple_calls()
fa2dd6
 		}
fa2dd6
 	}
fa2dd6
 	endmntent(f);
fa2dd6
-	return (locals == 1);
fa2dd6
+	return (locals == 4);
fa2dd6
 }
fa2dd6
 
fa2dd6
 int main(int argc, char *argv[])