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