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<TftpUrl> ret = parseTftpUrl("tftp://1.1.1.1/path",
20                                                   std::nullopt, res);
21         ASSERT_TRUE(ret);
22         if (!ret)
23         {
24             return;
25         }
26         EXPECT_EQ(ret->tftpServer, "1.1.1.1");
27         EXPECT_EQ(ret->fwFile, "path");
28     }
29     {
30         // Protocol, no schema on url
31         std::optional<TftpUrl> ret = parseTftpUrl("1.1.1.1/path", "TFTP", res);
32         ASSERT_TRUE(ret);
33         if (!ret)
34         {
35             return;
36         }
37         EXPECT_EQ(ret->tftpServer, "1.1.1.1");
38         EXPECT_EQ(ret->fwFile, "path");
39     }
40     {
41         // Both protocl and schema on url
42         std::optional<TftpUrl> ret = parseTftpUrl("tftp://1.1.1.1/path", "TFTP",
43                                                   res);
44         ASSERT_TRUE(ret);
45         if (!ret)
46         {
47             return;
48         }
49         EXPECT_EQ(ret->tftpServer, "1.1.1.1");
50         EXPECT_EQ(ret->fwFile, "path");
51     }
52 }
53 
54 TEST(UpdateService, ParseTFTPNegative)
55 {
56     crow::Response res;
57     // No protocol, no schema
58     ASSERT_EQ(parseTftpUrl("1.1.1.1/path", std::nullopt, res), std::nullopt);
59     // No host
60     ASSERT_EQ(parseTftpUrl("/path", "TFTP", res), std::nullopt);
61 
62     // No host
63     ASSERT_EQ(parseTftpUrl("path", "TFTP", res), std::nullopt);
64 
65     // No path
66     ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1", "TFTP", res), std::nullopt);
67     ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1/", "TFTP", res), std::nullopt);
68 }
69 } // namespace
70 } // namespace redfish
71