|
|
|
|
@@ -18,7 +18,10 @@ const std::string kTestFileName2 = "test2.txt";
|
|
|
|
|
const std::string kTestFileName3 = "test3.other";
|
|
|
|
|
const std::string kTestFileNameExt = ".txt";
|
|
|
|
|
const std::string kTestFileNameExt3 = ".other";
|
|
|
|
|
const std::string kTestIdentifier1 = "some_identifier";
|
|
|
|
|
const std::string kTestIdentifier2 = "some_other_identifier";
|
|
|
|
|
const std::string kWildcard = "*";
|
|
|
|
|
const std::string kUnderscore = "_";
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
class FileTest : public testing::Test {
|
|
|
|
|
@@ -175,4 +178,182 @@ TEST_F(FileTest, ListFiles) {
|
|
|
|
|
EXPECT_EQ(0u, names.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FileTest, CreateGlobalCertificates) {
|
|
|
|
|
// Clear directory
|
|
|
|
|
std::vector<std::string> names;
|
|
|
|
|
std::string path_dir = test_vectors::kTestDir;
|
|
|
|
|
std::string wild_card_path = path_dir + kWildcard;
|
|
|
|
|
file_system_.Remove(wild_card_path);
|
|
|
|
|
if (file_system_.List(path_dir, &names)) {
|
|
|
|
|
EXPECT_EQ(0u, names.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create certificates and verify that they exist
|
|
|
|
|
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
|
|
|
|
std::string legacy_certificate_path =
|
|
|
|
|
test_vectors::kTestDir + kLegacyCertificateFileName;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<File> file =
|
|
|
|
|
file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(certificate_path));
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(legacy_certificate_path));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.List(path_dir, &names));
|
|
|
|
|
|
|
|
|
|
// Should find two files. Order not important.
|
|
|
|
|
EXPECT_EQ(2u, names.size());
|
|
|
|
|
EXPECT_THAT(names, ::testing::UnorderedElementsAre(
|
|
|
|
|
kCertificateFileName, kLegacyCertificateFileName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FileTest, CreateCertificates) {
|
|
|
|
|
// Clear directory
|
|
|
|
|
std::vector<std::string> names;
|
|
|
|
|
std::string path_dir = test_vectors::kTestDir;
|
|
|
|
|
std::string wild_card_path = path_dir + kWildcard;
|
|
|
|
|
file_system_.Remove(wild_card_path);
|
|
|
|
|
if (file_system_.List(path_dir, &names)) {
|
|
|
|
|
EXPECT_EQ(0u, names.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
|
|
|
|
std::string legacy_certificate_path =
|
|
|
|
|
test_vectors::kTestDir + kLegacyCertificateFileName;
|
|
|
|
|
|
|
|
|
|
// Create Global certificates
|
|
|
|
|
std::unique_ptr<File> file =
|
|
|
|
|
file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
// Create certificates with first identifier
|
|
|
|
|
file_system_.set_identifier(kTestIdentifier1);
|
|
|
|
|
file = file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(!file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
// Create certificates with second identifier
|
|
|
|
|
file_system_.set_identifier(kTestIdentifier2);
|
|
|
|
|
file = file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(!file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(certificate_path));
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(legacy_certificate_path));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.List(path_dir, &names));
|
|
|
|
|
|
|
|
|
|
// Should find six files. Order not important.
|
|
|
|
|
bool is_global_certificate_present = false;
|
|
|
|
|
bool is_global_legacy_certificate_present = false;
|
|
|
|
|
size_t certificate_count = 0;
|
|
|
|
|
size_t legacy_certificate_count = 0;
|
|
|
|
|
EXPECT_EQ(6u, names.size());
|
|
|
|
|
for (size_t i = 0; i < names.size(); ++i) {
|
|
|
|
|
if (names[i].size() > kCertificateFileName.size()) {
|
|
|
|
|
if (names[i].compare(0, kCertificateFileNamePrefix.size(),
|
|
|
|
|
kCertificateFileNamePrefix) == 0)
|
|
|
|
|
++certificate_count;
|
|
|
|
|
else if (names[i].compare(0, kLegacyCertificateFileNamePrefix.size(),
|
|
|
|
|
kLegacyCertificateFileNamePrefix) == 0)
|
|
|
|
|
++legacy_certificate_count;
|
|
|
|
|
} else if (names[i].compare(kCertificateFileName) == 0) {
|
|
|
|
|
is_global_certificate_present = true;
|
|
|
|
|
} else if (names[i].compare(kLegacyCertificateFileName) == 0) {
|
|
|
|
|
is_global_legacy_certificate_present = true;
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(2, certificate_count);
|
|
|
|
|
EXPECT_EQ(2, legacy_certificate_count);
|
|
|
|
|
EXPECT_TRUE(is_global_certificate_present);
|
|
|
|
|
EXPECT_TRUE(is_global_legacy_certificate_present);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FileTest, RemoveCertificates) {
|
|
|
|
|
// Clear directory
|
|
|
|
|
std::vector<std::string> names;
|
|
|
|
|
std::string path_dir = test_vectors::kTestDir;
|
|
|
|
|
std::string wild_card_path = path_dir + kWildcard;
|
|
|
|
|
file_system_.Remove(wild_card_path);
|
|
|
|
|
if (file_system_.List(path_dir, &names)) {
|
|
|
|
|
EXPECT_EQ(0u, names.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
|
|
|
|
std::string legacy_certificate_path =
|
|
|
|
|
test_vectors::kTestDir + kLegacyCertificateFileName;
|
|
|
|
|
|
|
|
|
|
// Create Global certificates
|
|
|
|
|
std::unique_ptr<File> file =
|
|
|
|
|
file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
// Create certificates with first identifier
|
|
|
|
|
file_system_.set_identifier(kTestIdentifier1);
|
|
|
|
|
file = file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(!file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
// Create certificates with second identifier
|
|
|
|
|
file_system_.set_identifier(kTestIdentifier2);
|
|
|
|
|
file = file_system_.Open(certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
file = file_system_.Open(legacy_certificate_path, FileSystem::kCreate);
|
|
|
|
|
ASSERT_TRUE(file);
|
|
|
|
|
EXPECT_TRUE(!file_system_.IsGlobal());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(certificate_path));
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(legacy_certificate_path));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(file_system_.List(path_dir, &names));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(6u, names.size());
|
|
|
|
|
|
|
|
|
|
// Remove all even number listed files
|
|
|
|
|
for (size_t i = 0; i < names.size(); ++i) {
|
|
|
|
|
if (i % 2 == 0) {
|
|
|
|
|
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir + names[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that they have been removed
|
|
|
|
|
for (size_t i = 0; i < names.size(); ++i) {
|
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
|
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove all odd number listed files
|
|
|
|
|
for (size_t i = 0; i < names.size(); ++i) {
|
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
|
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir + names[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that all have been removed
|
|
|
|
|
for (size_t i = 0; i < names.size(); ++i) {
|
|
|
|
|
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace wvcdm
|
|
|
|
|
|