21ab4e
From 2419f7df9fbe9c63c6c41acec2b38684c6bc09d8 Mon Sep 17 00:00:00 2001
21ab4e
From: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Date: Tue, 9 May 2017 16:11:52 +0530
21ab4e
Subject: [PATCH 449/473] tests/gfapi:Adding testcase to check handling of "."
21ab4e
 and ".."
21ab4e
21ab4e
Adding a testcase to check the proper handling of "." and ".."
21ab4e
in gfapi path.
21ab4e
The patch which fix the issue is https://review.gluster.org/#/c/17177
21ab4e
21ab4e
Backport of>
21ab4e
>Change-Id: I5c9cceade30f7d8a3b451b5f34f1cf9815729c4a
21ab4e
>BUG: 1447266
21ab4e
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
>Reviewed-on: https://review.gluster.org/17216
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Niels de Vos <ndevos@redhat.com>
21ab4e
>Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
21ab4e
Change-Id: I5c9cceade30f7d8a3b451b5f34f1cf9815729c4a
21ab4e
BUG: 1441280
21ab4e
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/106339
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 tests/bugs/gfapi/bug-1447266/bug-1447266.c | 105 +++++++++++++++++++++++++++++
21ab4e
 tests/bugs/gfapi/bug-1447266/bug-1447266.t |  60 +++++++++++++++++
21ab4e
 2 files changed, 165 insertions(+)
21ab4e
 create mode 100644 tests/bugs/gfapi/bug-1447266/bug-1447266.c
21ab4e
 create mode 100644 tests/bugs/gfapi/bug-1447266/bug-1447266.t
21ab4e
21ab4e
diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.c b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
21ab4e
new file mode 100644
21ab4e
index 0000000..e4b3c88
21ab4e
--- /dev/null
21ab4e
+++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
21ab4e
@@ -0,0 +1,105 @@
21ab4e
+#include <glusterfs/api/glfs.h>
21ab4e
+#include <stdio.h>
21ab4e
+#include <errno.h>
21ab4e
+#include <string.h>
21ab4e
+#include <stdlib.h>
21ab4e
+#define TOTAL_ARGS 4
21ab4e
+int main(int argc, char *argv[])
21ab4e
+{
21ab4e
+        char *cwd = (char *)malloc(PATH_MAX*sizeof(char *));
21ab4e
+        char *resolved = NULL;
21ab4e
+        char *result = NULL;
21ab4e
+        char *buf = NULL;
21ab4e
+        struct stat st;
21ab4e
+        char *path = NULL;
21ab4e
+        int ret;
21ab4e
+
21ab4e
+        if (argc != TOTAL_ARGS) {
21ab4e
+                printf ("Please give all required command line args.\n"
21ab4e
+                         "Format : <volname> <server_ip> <path_name>\n");
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        glfs_t *fs = glfs_new (argv[1]);
21ab4e
+
21ab4e
+        if (fs == NULL) {
21ab4e
+                printf ("glfs_new: %s\n", strerror(errno));
21ab4e
+                /* No need to fail the test for this error */
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_set_volfile_server: %s\n", strerror(errno));
21ab4e
+                /* No need to fail the test for this error */
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        path = argv[3];
21ab4e
+
21ab4e
+        ret = glfs_set_logging(fs, "/tmp/gfapi.log", 7);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_set_logging: %s\n", strerror(errno));
21ab4e
+                /* No need to fail the test for this error */
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = glfs_init(fs);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_init: %s\n", strerror(errno));
21ab4e
+                /* No need to fail the test for this error */
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        sleep(1);
21ab4e
+
21ab4e
+        ret = glfs_chdir(fs, path);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_chdir: %s\n", strerror(errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        buf = glfs_getcwd(fs, cwd, PATH_MAX);
21ab4e
+        if (cwd == NULL) {
21ab4e
+                printf ("glfs_getcwd: %s\n", strerror(errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        printf ("\ncwd = %s\n\n", cwd);
21ab4e
+
21ab4e
+        result = glfs_realpath(fs, path, resolved);
21ab4e
+        if (result == NULL) {
21ab4e
+                printf ("glfs_realpath: %s\n", strerror(errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = glfs_stat(fs, path, &st);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_stat: %s\n", strerror(errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+        if (cwd)
21ab4e
+                free(cwd);
21ab4e
+
21ab4e
+        result = glfs_realpath(fs, path, resolved);
21ab4e
+        if (result == NULL) {
21ab4e
+                printf ("glfs_realpath: %s\n", strerror(errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = glfs_fini(fs);
21ab4e
+        if (ret) {
21ab4e
+                printf ("glfs_fini: %s\n", strerror(errno));
21ab4e
+                /* No need to fail the test for this error */
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        printf ("\n");
21ab4e
+out:
21ab4e
+        return ret;
21ab4e
+}
21ab4e
diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.t b/tests/bugs/gfapi/bug-1447266/bug-1447266.t
21ab4e
new file mode 100644
21ab4e
index 0000000..2bf72f8
21ab4e
--- /dev/null
21ab4e
+++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.t
21ab4e
@@ -0,0 +1,60 @@
21ab4e
+#!/bin/bash
21ab4e
+
21ab4e
+. $(dirname $0)/../../../include.rc
21ab4e
+. $(dirname $0)/../../../volume.rc
21ab4e
+. $(dirname $0)/../../../snapshot.rc
21ab4e
+
21ab4e
+cleanup;
21ab4e
+
21ab4e
+TEST init_n_bricks 3;
21ab4e
+TEST setup_lvm 3;
21ab4e
+
21ab4e
+TEST glusterd;
21ab4e
+
21ab4e
+TEST pidof glusterd;
21ab4e
+
21ab4e
+TEST $CLI volume create $V0 $H0:$L1 $H0:$L2 $H0:$L3;
21ab4e
+TEST $CLI volume set $V0 nfs.disable false
21ab4e
+
21ab4e
+
21ab4e
+TEST $CLI volume start $V0;
21ab4e
+
21ab4e
+TEST $GFS --volfile-server=$H0 --volfile-id=$V0 $M0;
21ab4e
+
21ab4e
+for i in {1..10} ; do echo "file" > $M0/file$i ; done
21ab4e
+
21ab4e
+# Create file and hard-links
21ab4e
+TEST touch $M0/f1
21ab4e
+TEST mkdir $M0/dir
21ab4e
+TEST ln $M0/f1 $M0/f2
21ab4e
+TEST ln $M0/f1 $M0/dir/f3
21ab4e
+
21ab4e
+TEST $CLI snapshot config activate-on-create enable
21ab4e
+TEST $CLI volume set $V0 features.uss enable;
21ab4e
+
21ab4e
+TEST $CLI snapshot create snap1 $V0 no-timestamp;
21ab4e
+
21ab4e
+for i in {11..20} ; do echo "file" > $M0/file$i ; done
21ab4e
+
21ab4e
+TEST $CLI snapshot create snap2 $V0 no-timestamp;
21ab4e
+TEST build_tester $(dirname $0)/bug-1447266.c -lgfapi
21ab4e
+
21ab4e
+#Testing strts from here-->
21ab4e
+
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../.."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../."
21ab4e
+#Since dir1 is not present, this test should fail
21ab4e
+TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../dir1"
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/.."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps"
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/."
21ab4e
+#Since snap3 is not present, this test should fail
21ab4e
+TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/.././snap3"
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/../."
21ab4e
+TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/./snap1/./../snap1/dir/."
21ab4e
+
21ab4e
+cleanup_tester $(dirname $0)/bug-1319374
21ab4e
+cleanup;
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e