summaryrefslogtreecommitdiff
path: root/unittests/config.cpp
blob: 20a025aa5c323e35d061284fb72b72b48ee417b5 (plain)
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
#define BOOST_TEST_MODULE GitFS_Config
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

#include "mockDefs.h"
#include <compileTimeFormatter.h>
#include <definedDirs.h>

using namespace GitFS;
using namespace GitFS::Test;
using namespace AdHoc::literals;

namespace btdata = boost::unit_test::data;

class IdsIce : public IceTray::DryIce {
public:
	IdsIce(const char * uid, const char * gid) :
		IceTray::DryIce({
				"--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()),
				"--GitFS.testrepo.authkey=%?"_fmt("testauth"),
				"--GitFS.testrepo.gid=%?"_fmt(gid),
				"--GitFS.testrepo.uid=%?"_fmt(uid),
				"--GitFS.testrepo.commitish=7a0ccb40084c3ab31d9856e7f689c0514c28c930",
		})
	{
	}
};

const auto USERS = btdata::make({"root", "gituser", "www"});
const auto GROUPS = btdata::make({"root", "gitgroup", "www"});
const auto DIRS = btdata::make({"/", "/src", "/unittests/fixtures"});
const auto FILES = btdata::make({"/Jamroot.jam", "/src/repo.cpp", "/unittests/fixtures/executable"});
const auto LINKS = btdata::make({"/unittests/fixtures/symlink"});
const auto COMMITISHS
		= btdata::make({"", "master", "origin/master", "testcommit", "7a0ccb40084c3ab31d9856e7f689c0514c28c930"});

BOOST_DATA_TEST_CASE(uid_gid_override_getattr, USERS * GROUPS *(DIRS + FILES + LINKS), uid, gid, path)
{
	IdsIce s(uid, gid);
	VolumeClient c;
	BOOST_CHECK_NO_THROW(c.s->ice_ping());

	auto attr = c.v->getattr(c.env, path);
	BOOST_CHECK_EQUAL(attr.uid, uid);
	BOOST_CHECK_EQUAL(attr.gid, gid);
}

BOOST_DATA_TEST_CASE(uid_gid_override_fgetattr, USERS * GROUPS * FILES, uid, gid, path)
{
	IdsIce s(uid, gid);
	VolumeClient c;
	BOOST_CHECK_NO_THROW(c.s->ice_ping());

	auto file = c.v->open(c.env, path, {});
	auto attr = file->fgetattr(c.env);
	BOOST_CHECK_EQUAL(attr.uid, uid);
	BOOST_CHECK_EQUAL(attr.gid, gid);
	file->close();
}

BOOST_DATA_TEST_CASE(uid_gid_override_list, USERS * GROUPS * DIRS, uid, gid, path)
{
	IdsIce s(uid, gid);
	VolumeClient c;
	BOOST_CHECK_NO_THROW(c.s->ice_ping());

	auto dir = c.v->opendir(c.env, path);
	for (const auto & dirent : dir->listdir()) {
		BOOST_TEST_CONTEXT(dirent.first) {
			BOOST_CHECK_EQUAL(dirent.second.uid, uid);
			BOOST_CHECK_EQUAL(dirent.second.gid, gid);
		}
	}
	dir->close();
}

BOOST_DATA_TEST_CASE(commitishs, COMMITISHS *(FILES + DIRS), commitish, path)
{
	IceTray::DryIce di({
			"--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()),
			"--GitFS.testrepo.authkey=%?"_fmt("testauth"),
			"--GitFS.testrepo.commitish=%?"_fmt(commitish),
	});
	VolumeClient c;
	BOOST_CHECK_NO_THROW(c.v->ice_ping());
	BOOST_CHECK_NO_THROW(c.v->getattr(c.env, path));
}

BOOST_DATA_TEST_CASE(bad_commitishs, FILES, commitish) // File paths aren't commitishs
{
	IceTray::DryIce di({
			"--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()),
			"--GitFS.testrepo.authkey=%?"_fmt("testauth"),
			"--GitFS.testrepo.commitish=%?"_fmt(commitish),
	});
	Client c;
	BOOST_CHECK_THROW(c.s->connect("testrepo", "testauth"), NetFS::ConfigError);
}