1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2019 The FreeBSD Foundation 5 * 6 * This software was developed by BFF Storage Systems, LLC under sponsorship 7 * from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 extern "C" { 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 public: 43 void expect_access(uint64_t ino, mode_t access_mode, int error) 44 { 45 EXPECT_CALL(*m_mock, process( 46 ResultOf([=](auto in) { 47 return (in->header.opcode == FUSE_ACCESS && 48 in->header.nodeid == ino && 49 in->body.access.mask == access_mode); 50 }, Eq(true)), 51 _) 52 ).WillOnce(Invoke(ReturnErrno(error))); 53 } 54 55 void expect_lookup(const char *relpath, uint64_t ino) 56 { 57 FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 0, 1); 58 } 59 }; 60 61 /* The error case of FUSE_ACCESS. */ 62 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */ 63 TEST_F(Access, DISABLED_eaccess) 64 { 65 const char FULLPATH[] = "mountpoint/some_file.txt"; 66 const char RELPATH[] = "some_file.txt"; 67 uint64_t ino = 42; 68 mode_t access_mode = X_OK; 69 70 expect_lookup(RELPATH, ino); 71 expect_access(ino, access_mode, EACCES); 72 73 ASSERT_NE(0, access(FULLPATH, access_mode)); 74 ASSERT_EQ(EACCES, errno); 75 } 76 77 /* 78 * If the filesystem returns ENOSYS, then it is treated as a permanent success, 79 * and subsequent VOP_ACCESS calls will succeed automatically without querying 80 * the daemon. 81 */ 82 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236557 */ 83 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */ 84 TEST_F(Access, DISABLED_enosys) 85 { 86 const char FULLPATH[] = "mountpoint/some_file.txt"; 87 const char RELPATH[] = "some_file.txt"; 88 uint64_t ino = 42; 89 mode_t access_mode = R_OK; 90 91 expect_lookup(RELPATH, ino); 92 expect_access(ino, access_mode, ENOSYS); 93 94 ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno); 95 ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno); 96 } 97 98 /* The successful case of FUSE_ACCESS. */ 99 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */ 100 TEST_F(Access, DISABLED_ok) 101 { 102 const char FULLPATH[] = "mountpoint/some_file.txt"; 103 const char RELPATH[] = "some_file.txt"; 104 uint64_t ino = 42; 105 mode_t access_mode = R_OK; 106 107 expect_lookup(RELPATH, ino); 108 expect_access(ino, access_mode, 0); 109 110 ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno); 111 } 112