1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#define BOOST_TEST_MODULE TestNetFSLib
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <defaultMapper.h>
#include <entCache.impl.h>
#include <lockHelpers.h>
class TestEntCache : public EntCache<User> {
void
fillCache() const noexcept override
{
Lock(lock);
idcache->insert(std::make_shared<User>(1, "user1", 1));
idcache->insert(std::make_shared<User>(2, "user2", 1));
idcache->insert(std::make_shared<User>(3, "user3", 1));
}
};
const auto GoodIds = boost::unit_test::data::make({1, 2, 3});
const auto BadIds = boost::unit_test::data::make({0, -1, 10});
const auto GoodNames = boost::unit_test::data::make({"user1", "user2", "user3"});
const auto BadNames = boost::unit_test::data::make({"", "bad", "user4"});
BOOST_FIXTURE_TEST_SUITE(tec, TestEntCache);
BOOST_DATA_TEST_CASE(notfoundid, BadIds, id)
{
BOOST_CHECK(!getEntry(id));
}
BOOST_DATA_TEST_CASE(notfoundname, BadNames, name)
{
BOOST_CHECK(!getEntry(name));
}
BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id)
{
BOOST_CHECK_EQUAL(getEntry(id)->name, name);
}
BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
{
BOOST_CHECK_EQUAL(getEntry(name)->id, id);
}
BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE(group_membership)
{
Group g(0, "root");
g.members.insert(0);
g.members.insert(1);
g.members.insert(5);
BOOST_REQUIRE_EQUAL(3, g.members.size());
BOOST_CHECK(g.hasMember(0));
BOOST_CHECK(g.hasMember(1));
BOOST_CHECK(g.hasMember(5));
BOOST_CHECK(!g.hasMember(3));
BOOST_CHECK(!g.hasMember(6));
}
// These tests make some assumptions about local system users
BOOST_FIXTURE_TEST_CASE(usercache, UserEntCache)
{
auto root = getEntry(0);
BOOST_REQUIRE(root);
BOOST_CHECK_EQUAL(root->id, 0);
BOOST_CHECK_EQUAL(root->name, "root");
BOOST_CHECK_EQUAL(root->group, 0);
auto rootByName = getEntry(root->name);
BOOST_REQUIRE_EQUAL(root, rootByName);
}
struct TestGroupEntCache : public GroupEntCache {
TestGroupEntCache() : GroupEntCache(std::make_shared<UserEntCache>()) { }
};
BOOST_FIXTURE_TEST_CASE(groupcache, TestGroupEntCache)
{
auto root = getEntry(0);
BOOST_REQUIRE(root);
BOOST_CHECK_EQUAL(root->id, 0);
BOOST_CHECK_EQUAL(root->name, "root");
BOOST_CHECK(root->hasMember(0));
auto rootByName = getEntry(root->name);
BOOST_REQUIRE_EQUAL(root, rootByName);
}
BOOST_FIXTURE_TEST_SUITE(dm, NetFS::Mapping::DefaultMapper);
BOOST_AUTO_TEST_CASE(good_maptransport)
{
auto fs = mapTransport("root", "root");
BOOST_CHECK_EQUAL(0, fs.uid);
BOOST_CHECK_EQUAL(0, fs.gid);
BOOST_CHECK_EQUAL(0, fs.mask);
}
BOOST_AUTO_TEST_CASE(good_mapfs)
{
auto tn = mapFileSystem(0, 0);
BOOST_CHECK_EQUAL("root", tn.username);
BOOST_CHECK_EQUAL("root", tn.groupname);
}
BOOST_AUTO_TEST_CASE(bad_maptransport)
{
BOOST_REQUIRE_THROW(mapTransport("root", ""), NetFS::SystemError);
BOOST_REQUIRE_THROW(mapTransport("", "root"), NetFS::SystemError);
BOOST_REQUIRE_THROW(mapTransport("", ""), NetFS::SystemError);
}
BOOST_AUTO_TEST_CASE(bad_mapfilesystem)
{
BOOST_REQUIRE_THROW(mapFileSystem(0, -1), NetFS::SystemError);
BOOST_REQUIRE_THROW(mapFileSystem(-1, 0), NetFS::SystemError);
BOOST_REQUIRE_THROW(mapFileSystem(-1, -1), NetFS::SystemError);
}
BOOST_AUTO_TEST_SUITE_END();
|