1 2 #include "http_response.hpp" 3 #include "update_service.hpp" 4 5 #include <optional> 6 7 #include <gtest/gtest.h> 8 9 namespace redfish 10 { 11 namespace 12 { 13 14 TEST(UpdateService, ParseTFTPPostitive) 15 { 16 crow::Response res; 17 { 18 // No protocol, schema on url 19 std::optional<boost::urls::url> ret = 20 parseSimpleUpdateUrl("tftp://1.1.1.1/path", std::nullopt, res); 21 ASSERT_TRUE(ret); 22 if (!ret) 23 { 24 return; 25 } 26 EXPECT_EQ(ret->encoded_host_and_port(), "1.1.1.1"); 27 EXPECT_EQ(ret->encoded_path(), "/path"); 28 EXPECT_EQ(ret->scheme(), "tftp"); 29 } 30 { 31 // Protocol, no schema on url 32 std::optional<boost::urls::url> ret = 33 parseSimpleUpdateUrl("1.1.1.1/path", "TFTP", res); 34 ASSERT_TRUE(ret); 35 if (!ret) 36 { 37 return; 38 } 39 EXPECT_EQ(ret->encoded_host_and_port(), "1.1.1.1"); 40 EXPECT_EQ(ret->encoded_path(), "/path"); 41 EXPECT_EQ(ret->scheme(), "tftp"); 42 } 43 { 44 // Both protocl and schema on url 45 std::optional<boost::urls::url> ret = 46 parseSimpleUpdateUrl("tftp://1.1.1.1/path", "TFTP", res); 47 ASSERT_TRUE(ret); 48 if (!ret) 49 { 50 return; 51 } 52 EXPECT_EQ(ret->encoded_host_and_port(), "1.1.1.1"); 53 EXPECT_EQ(ret->encoded_path(), "/path"); 54 EXPECT_EQ(ret->scheme(), "tftp"); 55 } 56 } 57 58 TEST(UpdateService, ParseTFTPNegative) 59 { 60 crow::Response res; 61 // No protocol, no schema 62 ASSERT_EQ(parseSimpleUpdateUrl("1.1.1.1/path", std::nullopt, res), 63 std::nullopt); 64 // No host 65 ASSERT_EQ(parseSimpleUpdateUrl("/path", "TFTP", res), std::nullopt); 66 67 // No host 68 ASSERT_EQ(parseSimpleUpdateUrl("path", "TFTP", res), std::nullopt); 69 70 // No path 71 ASSERT_EQ(parseSimpleUpdateUrl("tftp://1.1.1.1", "TFTP", res), 72 std::nullopt); 73 ASSERT_EQ(parseSimpleUpdateUrl("tftp://1.1.1.1/", "TFTP", res), 74 std::nullopt); 75 } 76 } // namespace 77 } // namespace redfish 78