From f86bcc875a496b3c321a4ed102579a4031617800 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Fri, 25 Aug 2023 09:34:07 -0700 Subject: Clean up tftp update to use URL Similar to transforms we've done elsewhere, we shouldn't be parsing urls using std::string::find, regex, or anything else, as they don't handle URL % encoding properly. Change-Id: I48bb30c0c737c4df2ae73f40fc49c63bac5b658f Signed-off-by: Ed Tanous --- test/redfish-core/lib/update_service_test.cpp | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/redfish-core/lib/update_service_test.cpp (limited to 'test') diff --git a/test/redfish-core/lib/update_service_test.cpp b/test/redfish-core/lib/update_service_test.cpp new file mode 100644 index 0000000000..01f2a0e7c9 --- /dev/null +++ b/test/redfish-core/lib/update_service_test.cpp @@ -0,0 +1,55 @@ + +#include "update_service.hpp" + +#include + +namespace redfish +{ +namespace +{ + +TEST(UpdateService, ParseTFTPPostitive) +{ + crow::Response res; + { + // No protocol, schema on url + std::optional ret = parseTftpUrl("tftp://1.1.1.1/path", + std::nullopt, res); + ASSERT_NE(ret, std::nullopt); + EXPECT_EQ(ret->tftpServer, "1.1.1.1"); + EXPECT_EQ(ret->fwFile, "path"); + } + { + // Protocol, no schema on url + std::optional ret = parseTftpUrl("1.1.1.1/path", "TFTP", res); + ASSERT_NE(ret, std::nullopt); + EXPECT_EQ(ret->tftpServer, "1.1.1.1"); + EXPECT_EQ(ret->fwFile, "path"); + } + { + // Both protocl and schema on url + std::optional ret = parseTftpUrl("tftp://1.1.1.1/path", "TFTP", + res); + ASSERT_NE(ret, std::nullopt); + EXPECT_EQ(ret->tftpServer, "1.1.1.1"); + EXPECT_EQ(ret->fwFile, "path"); + } +} + +TEST(UpdateService, ParseTFTPNegative) +{ + crow::Response res; + // No protocol, no schema + ASSERT_EQ(parseTftpUrl("1.1.1.1/path", std::nullopt, res), std::nullopt); + // No host + ASSERT_EQ(parseTftpUrl("/path", "TFTP", res), std::nullopt); + + // No host + ASSERT_EQ(parseTftpUrl("path", "TFTP", res), std::nullopt); + + // No path + ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1", "TFTP", res), std::nullopt); + ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1/", "TFTP", res), std::nullopt); +} +} // namespace +} // namespace redfish -- cgit v1.2.3