]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/fs/fuse/access.cc
fuse(4): add tests for FUSE_MKDIR and FUSE_ACCESS
[FreeBSD/FreeBSD.git] / tests / sys / fs / fuse / access.cc
1 /*-
2  * Copyright (c) 2019 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by BFF Storage Systems, LLC under sponsorship
6  * from the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 extern "C" {
31 //#include <sys/param.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 }
35
36 #include "mockfs.hh"
37 #include "utils.hh"
38
39 using namespace testing;
40
41 class Access: public FuseTest {};
42
43 /* TODO: test methods for the default_permissions mount option */
44
45 /* The error case of FUSE_ACCESS.  */
46 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
47 TEST_F(Access, DISABLED_eaccess)
48 {
49         const char FULLPATH[] = "mountpoint/some_file.txt";
50         const char RELPATH[] = "some_file.txt";
51         uint64_t ino = 42;
52         mode_t  access_mode = X_OK;
53
54         EXPECT_LOOKUP(RELPATH).WillOnce(Invoke([=](auto in, auto out) {
55                 out->header.unique = in->header.unique;
56                 SET_OUT_HEADER_LEN(out, entry);
57                 out->body.entry.attr.mode = S_IFREG | 0644;
58                 out->body.entry.nodeid = ino;
59         }));
60         EXPECT_CALL(*m_mock, process(
61                 ResultOf([=](auto in) {
62                         return (in->header.opcode == FUSE_ACCESS &&
63                                 in->header.nodeid == ino &&
64                                 in->body.access.mask == access_mode);
65                 }, Eq(true)),
66                 _)
67         ).WillOnce(Invoke(ReturnErrno(EACCES)));
68
69
70         ASSERT_NE(0, access(FULLPATH, access_mode));
71         ASSERT_EQ(EACCES, errno);
72 }
73
74 /* The successful case of FUSE_ACCESS.  */
75 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
76 TEST_F(Access, DISABLED_ok)
77 {
78         const char FULLPATH[] = "mountpoint/some_file.txt";
79         const char RELPATH[] = "some_file.txt";
80         uint64_t ino = 42;
81         mode_t  access_mode = R_OK;
82
83         EXPECT_LOOKUP(RELPATH).WillOnce(Invoke([=](auto in, auto out) {
84                 out->header.unique = in->header.unique;
85                 SET_OUT_HEADER_LEN(out, entry);
86                 out->body.entry.attr.mode = S_IFREG | 0644;
87                 out->body.entry.nodeid = ino;
88         }));
89         EXPECT_CALL(*m_mock, process(
90                 ResultOf([=](auto in) {
91                         return (in->header.opcode == FUSE_ACCESS &&
92                                 in->header.nodeid == ino &&
93                                 in->body.access.mask == access_mode);
94                 }, Eq(true)),
95                 _)
96         ).WillOnce(Invoke(ReturnErrno(0)));
97
98         ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);
99 }