diff options
author | Ed Tanous <edtanous@google.com> | 2023-08-25 19:34:07 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-01-19 22:43:50 +0300 |
commit | f86bcc875a496b3c321a4ed102579a4031617800 (patch) | |
tree | ea0ee25603c64a63a77edac9e4fe036e22916b96 /test | |
parent | 367b3dce0567c223f53ce1a4cc10d34241111774 (diff) | |
download | bmcweb-f86bcc875a496b3c321a4ed102579a4031617800.tar.xz |
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 <edtanous@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/redfish-core/lib/update_service_test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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 <gtest/gtest.h> + +namespace redfish +{ +namespace +{ + +TEST(UpdateService, ParseTFTPPostitive) +{ + crow::Response res; + { + // No protocol, schema on url + std::optional<TftpUrl> 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<TftpUrl> 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<TftpUrl> 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 |