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
124
125
126
127
128
|
// --------------------------------------------------------------------------
//
// File
// Name: tests3store.cpp
// Purpose: Test Amazon S3 storage VFS API and utilities
// Created: 2015/06/28
//
// --------------------------------------------------------------------------
#include "Box.h"
#ifndef WIN32
# include <csignal>
#endif
#include "BackupAccountControl.h"
#include "BackupClientCryptoKeys.h"
#include "BackupDaemonConfigVerify.h"
#include "BackupStoreDirectory.h"
#include "BackupStoreInfo.h"
#include "Configuration.h"
#include "RaidFileController.h"
#include "ServerControl.h"
#include "SSLLib.h"
#include "Test.h"
#include "Utils.h"
#include "MemLeakFindOn.h"
#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf"
int s3simulator_pid = 0;
bool StartSimulator()
{
s3simulator_pid = StartDaemon(s3simulator_pid,
"../../bin/s3simulator/s3simulator " + bbstored_args +
" testfiles/s3simulator.conf", "testfiles/s3simulator.pid");
return s3simulator_pid != 0;
}
bool StopSimulator()
{
bool result = StopDaemon(s3simulator_pid, "testfiles/s3simulator.pid",
"s3simulator.memleaks", true);
s3simulator_pid = 0;
return result;
}
bool kill_running_daemons()
{
if(FileExists("testfiles/s3simulator.pid"))
{
return KillServer("testfiles/s3simulator.pid", true);
}
else
{
return true;
}
}
//! Simplifies calling setUp() with the current function name in each test.
#define SETUP_TEST_S3SIMULATOR() \
SETUP(); \
TEST_THAT(kill_running_daemons()); \
TEST_THAT(StartSimulator()); \
#define TEARDOWN_TEST_S3SIMULATOR() \
TEST_THAT(s3simulator_pid == 0 || StopSimulator()); \
TEST_THAT(kill_running_daemons()); \
TEARDOWN();
bool test_create_account_with_account_control()
{
SETUP_TEST_S3SIMULATOR();
std::auto_ptr<Configuration> config = load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE,
BackupDaemonConfigVerify);
S3BackupAccountControl control(*config);
control.CreateAccount("test", 1000, 2000);
FileStream fs("testfiles/store/subdir/" S3_INFO_FILE_NAME);
std::auto_ptr<BackupStoreInfo> info = BackupStoreInfo::Load(fs, fs.GetFileName(),
true); // ReadOnly
TEST_EQUAL(0, info->GetAccountID());
TEST_EQUAL(1, info->GetLastObjectIDUsed());
TEST_EQUAL(1, info->GetBlocksUsed());
TEST_EQUAL(0, info->GetBlocksInCurrentFiles());
TEST_EQUAL(0, info->GetBlocksInOldFiles());
TEST_EQUAL(0, info->GetBlocksInDeletedFiles());
TEST_EQUAL(1, info->GetBlocksInDirectories());
TEST_EQUAL(0, info->GetDeletedDirectories().size());
TEST_EQUAL(1000, info->GetBlocksSoftLimit());
TEST_EQUAL(2000, info->GetBlocksHardLimit());
TEST_EQUAL(0, info->GetNumCurrentFiles());
TEST_EQUAL(0, info->GetNumOldFiles());
TEST_EQUAL(0, info->GetNumDeletedFiles());
TEST_EQUAL(1, info->GetNumDirectories());
TEST_EQUAL(true, info->IsAccountEnabled());
TEST_EQUAL(true, info->IsReadOnly());
TEST_EQUAL(0, info->GetClientStoreMarker());
TEST_EQUAL("test", info->GetAccountName());
FileStream root_stream("testfiles/store/subdir/dirs/0x1.dir");
BackupStoreDirectory root_dir(root_stream);
TEST_EQUAL(0, root_dir.GetNumberOfEntries());
TEARDOWN_TEST_S3SIMULATOR();
}
int test(int argc, const char *argv[])
{
// SSL library
SSLLib::Initialise();
// Use the setup crypto command to set up all these keys, so that the bbackupquery command can be used
// for seeing what's going on.
BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys");
#ifndef WIN32
signal(SIGPIPE, SIG_IGN);
#endif
TEST_THAT(test_create_account_with_account_control());
return finish_test_suite();
}
|