sapling/eden/fs/inodes/test/EdenDispatcherTest.cpp
Chad Austin 0797ee3a35 to satisfy secfs validation suite, limit path components to 255 bytes
Summary:
Most filesystems limit path components to 255. To remain consistent,
let's have Eden do the same, at least for write operations.

Reviewed By: simpkins

Differential Revision: D8151020

fbshipit-source-id: 251da94a076f5765111c8e3d9d8a25c37682e2e3
2018-05-30 23:11:28 -07:00

102 lines
3.1 KiB
C++

/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "eden/fs/inodes/EdenDispatcher.h"
#include <folly/experimental/TestUtil.h>
#include <folly/test/TestUtils.h>
#include <gtest/gtest.h>
#include "eden/fs/testharness/FakeTreeBuilder.h"
#include "eden/fs/testharness/TestMount.h"
using namespace facebook::eden;
using namespace std::chrono_literals;
using namespace folly::string_piece_literals;
namespace {
struct EdenDispatcherTest : ::testing::Test {
EdenDispatcherTest() : mount{builder} {}
FakeTreeBuilder builder;
TestMount mount;
};
constexpr auto kTooLongPiece = folly::StringPiece{
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"};
static_assert(256 == kTooLongPiece.size(), "256 is one larger than the max!");
static const auto kTooLong = PathComponentPiece{kTooLongPiece};
} // namespace
TEST_F(EdenDispatcherTest, mknodReturnsNameTooLong) {
try {
mount.getDispatcher()
->mknod(kRootNodeId, kTooLong, S_IFREG | 0644, 0)
.get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}
TEST_F(EdenDispatcherTest, mkdirReturnsNameTooLong) {
try {
mount.getDispatcher()
->mkdir(kRootNodeId, kTooLong, S_IFDIR | 0755)
.get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}
TEST_F(EdenDispatcherTest, symlinkReturnsNameTooLong) {
try {
mount.getDispatcher()->symlink(kRootNodeId, kTooLong, "aoeu"_sp).get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}
TEST_F(EdenDispatcherTest, renameReturnsNameTooLong) {
try {
mount.getDispatcher()
->rename(kRootNodeId, "oldname"_pc, kRootNodeId, kTooLong)
.get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}
TEST_F(EdenDispatcherTest, linkReturnsNameTooLong) {
try {
// Eden doesn't support hard links yet and this link call could never work
// in the first place, but at least validate the target name length.
mount.getDispatcher()->link(kRootNodeId, kRootNodeId, kTooLong).get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}
TEST_F(EdenDispatcherTest, createReturnsNameTooLong) {
try {
mount.getDispatcher()
->create(kRootNodeId, kTooLong, S_IFREG | 0644, 0)
.get(0ms);
FAIL() << "should throw";
} catch (std::system_error& e) {
EXPECT_EQ(ENAMETOOLONG, e.code().value());
}
}