2 * Copyright (c) 2019 The FreeBSD Foundation
5 * This software was developed by BFF Storage Systems, LLC under sponsorship
6 * from the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
31 //#include <sys/param.h>
39 using namespace testing;
41 class Access: public FuseTest {};
43 /* TODO: test methods for the default_permissions mount option */
45 /* The error case of FUSE_ACCESS. */
46 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
47 TEST_F(Access, DISABLED_eaccess)
49 const char FULLPATH[] = "mountpoint/some_file.txt";
50 const char RELPATH[] = "some_file.txt";
52 mode_t access_mode = X_OK;
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;
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);
67 ).WillOnce(Invoke(ReturnErrno(EACCES)));
70 ASSERT_NE(0, access(FULLPATH, access_mode));
71 ASSERT_EQ(EACCES, errno);
74 /* The successful case of FUSE_ACCESS. */
75 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
76 TEST_F(Access, DISABLED_ok)
78 const char FULLPATH[] = "mountpoint/some_file.txt";
79 const char RELPATH[] = "some_file.txt";
81 mode_t access_mode = R_OK;
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;
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);
96 ).WillOnce(Invoke(ReturnErrno(0)));
98 ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);