summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/http/file_test_utilities.hpp37
-rw-r--r--test/include/ossl_random.cpp9
-rw-r--r--test/include/ssl_key_handler_test.cpp26
-rw-r--r--test/redfish-core/lib/metadata_test.cpp52
-rw-r--r--test/redfish-core/lib/update_service_test.cpp13
5 files changed, 100 insertions, 37 deletions
diff --git a/test/http/file_test_utilities.hpp b/test/http/file_test_utilities.hpp
deleted file mode 100644
index bd11a90d8d..0000000000
--- a/test/http/file_test_utilities.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-#include <filesystem>
-#include <string>
-#include <string_view>
-
-#include <gtest/gtest.h>
-
-struct TemporaryFileHandle
-{
- std::filesystem::path path;
- std::string stringPath;
-
- // Creates a temporary file with the contents provided, removes it on
- // destruction.
- explicit TemporaryFileHandle(std::string_view sampleData) :
- path(std::filesystem::temp_directory_path() /
- "bmcweb_http_response_test_XXXXXXXXXXX")
- {
- stringPath = path.string();
-
- int fd = mkstemp(stringPath.data());
- EXPECT_GT(fd, 0);
- EXPECT_EQ(write(fd, sampleData.data(), sampleData.size()),
- sampleData.size());
- close(fd);
- }
-
- TemporaryFileHandle(const TemporaryFileHandle&) = delete;
- TemporaryFileHandle(TemporaryFileHandle&&) = delete;
- TemporaryFileHandle& operator=(const TemporaryFileHandle&) = delete;
- TemporaryFileHandle& operator=(TemporaryFileHandle&&) = delete;
-
- ~TemporaryFileHandle()
- {
- std::filesystem::remove(path);
- }
-};
diff --git a/test/include/ossl_random.cpp b/test/include/ossl_random.cpp
index 512b5c8f83..1b9a2b88da 100644
--- a/test/include/ossl_random.cpp
+++ b/test/include/ossl_random.cpp
@@ -6,6 +6,7 @@
namespace
{
+using testing::IsEmpty;
using testing::MatchesRegex;
TEST(Bmcweb, GetRandomUUID)
@@ -18,4 +19,12 @@ TEST(Bmcweb, GetRandomUUID)
"^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"));
}
+TEST(Bmcweb, GetRandomIdOfLength)
+{
+ using bmcweb::getRandomIdOfLength;
+ EXPECT_THAT(getRandomIdOfLength(1), MatchesRegex("^[a-zA-Z0-9]$"));
+ EXPECT_THAT(getRandomIdOfLength(10), MatchesRegex("^[a-zA-Z0-9]{10}$"));
+ EXPECT_THAT(getRandomIdOfLength(0), IsEmpty());
+}
+
} // namespace
diff --git a/test/include/ssl_key_handler_test.cpp b/test/include/ssl_key_handler_test.cpp
new file mode 100644
index 0000000000..f60252ff6e
--- /dev/null
+++ b/test/include/ssl_key_handler_test.cpp
@@ -0,0 +1,26 @@
+#include "file_test_utilities.hpp"
+#include "ssl_key_handler.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace ensuressl
+{
+
+TEST(SSLKeyHandler, GenerateVerifyRoundTrip)
+{
+ /* Verifies that we can generate a certificate, then read back in the
+ * certificate that was read */
+ TemporaryFileHandle myFile("");
+ std::string cert = generateSslCertificate("TestCommonName");
+
+ EXPECT_FALSE(cert.empty());
+
+ writeCertificateToFile(myFile.stringPath, cert);
+
+ std::string cert2 = verifyOpensslKeyCert(myFile.stringPath);
+ EXPECT_FALSE(cert2.empty());
+ EXPECT_EQ(cert, cert2);
+}
+
+} // namespace ensuressl
diff --git a/test/redfish-core/lib/metadata_test.cpp b/test/redfish-core/lib/metadata_test.cpp
new file mode 100644
index 0000000000..84365ac53b
--- /dev/null
+++ b/test/redfish-core/lib/metadata_test.cpp
@@ -0,0 +1,52 @@
+#include "file_test_utilities.hpp"
+#include "metadata.hpp"
+
+#include <string>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace redfish
+{
+namespace
+{
+
+/*
+Example from Redfish and OData whitepaper.
+
+https://www.dmtf.org/sites/default/files/standards/documents/DSP2052_1.0.0.pdf
+*/
+constexpr std::string_view content =
+ "<edmx:Edmx xmlns:edms=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\">\n"
+ " <edmx:Reference Uri=\"http://contoso.org/schemas/ExternalSchema.xml\">\n"
+ " <edmx:Include Namespace=\"ExternalNamespace\"/>\n"
+ " <edmx:Include Namespace=\"Other.Namespace\"/>\n"
+ " </edmx:Reference>\n"
+ " <edmx:DataServices>\n"
+ " <Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNewNamespace\">\n"
+ " <ComplexType Name=\"MyDataType\">\n"
+ " <Property Name=\"MyProperty\" Type=\"ExternalNamespace.ReferencedDataType\"/>\n"
+ " <Property Name=\"MyProperty2\" Type=\"Other.Namespace.OtherDataType\"/>\n"
+ " <Property Name=\"MyProperty3\" Type=\"Edm.Int64\"/>\n"
+ " </ComplexType>\n"
+ " </Schema>\n"
+ " </edmx:DataServices>\n"
+ "</edmx:Edmx>\n";
+
+TEST(MetadataGet, GetOneFile)
+{
+ TemporaryFileHandle file(content);
+
+ std::filesystem::path path{file.stringPath};
+ EXPECT_EQ(
+ getMetadataPieceForFile(path),
+ std::format(" <edmx:Reference Uri=\"/redfish/v1/schema/{}\">\n"
+ " <edmx:Include Namespace=\"MyNewNamespace\"/>\n"
+ " </edmx:Reference>\n",
+ path.filename().string()));
+
+ EXPECT_EQ(getMetadataPieceForFile("DoesNotExist_v1.xml"), "");
+}
+
+} // namespace
+} // namespace redfish
diff --git a/test/redfish-core/lib/update_service_test.cpp b/test/redfish-core/lib/update_service_test.cpp
index 11b4479a3d..3e013e3cbd 100644
--- a/test/redfish-core/lib/update_service_test.cpp
+++ b/test/redfish-core/lib/update_service_test.cpp
@@ -112,6 +112,19 @@ TEST(UpdateService, ParseHTTPSPostitive)
EXPECT_EQ(ret->encoded_path(), "/");
EXPECT_EQ(ret->scheme(), "https");
}
+ {
+ // Both protocol and schema on url without path
+ std::optional<boost::urls::url> ret =
+ parseSimpleUpdateUrl("https://[2001:db8::1]", "HTTPS", res);
+ ASSERT_TRUE(ret);
+ if (!ret)
+ {
+ return;
+ }
+ EXPECT_EQ(ret->encoded_host_and_port(), "[2001:db8::1]");
+ EXPECT_EQ(ret->encoded_path(), "/");
+ EXPECT_EQ(ret->scheme(), "https");
+ }
}
TEST(UpdateService, ParseTFTPNegative)