]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
1e59de90 | 4 | #include "rgw_url.h" |
9f95a23c TL |
5 | #include <string> |
6 | #include <gtest/gtest.h> | |
7 | ||
8 | using namespace rgw; | |
9 | ||
10 | TEST(TestURL, SimpleAuthority) | |
11 | { | |
12 | std::string host; | |
13 | std::string user; | |
14 | std::string password; | |
15 | const std::string url = "http://example.com"; | |
16 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
17 | ASSERT_TRUE(user.empty()); | |
18 | ASSERT_TRUE(password.empty()); | |
19 | EXPECT_STREQ(host.c_str(), "example.com"); | |
20 | } | |
21 | ||
20effc67 TL |
22 | TEST(TestURL, SimpleAuthority_1) |
23 | { | |
24 | std::string host; | |
25 | std::string user; | |
26 | std::string password; | |
27 | const std::string url = "http://example.com/"; | |
28 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
29 | ASSERT_TRUE(user.empty()); | |
30 | ASSERT_TRUE(password.empty()); | |
31 | EXPECT_STREQ(host.c_str(), "example.com"); | |
32 | } | |
33 | ||
9f95a23c TL |
34 | TEST(TestURL, IPAuthority) |
35 | { | |
36 | std::string host; | |
37 | std::string user; | |
38 | std::string password; | |
39 | const std::string url = "http://1.2.3.4"; | |
40 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
41 | ASSERT_TRUE(user.empty()); | |
42 | ASSERT_TRUE(password.empty()); | |
43 | EXPECT_STREQ(host.c_str(), "1.2.3.4"); | |
44 | } | |
45 | ||
46 | TEST(TestURL, IPv6Authority) | |
47 | { | |
48 | std::string host; | |
49 | std::string user; | |
50 | std::string password; | |
51 | const std::string url = "http://FE80:CD00:0000:0CDE:1257:0000:211E:729C"; | |
52 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
53 | ASSERT_TRUE(user.empty()); | |
54 | ASSERT_TRUE(password.empty()); | |
55 | EXPECT_STREQ(host.c_str(), "FE80:CD00:0000:0CDE:1257:0000:211E:729C"); | |
56 | } | |
57 | ||
58 | TEST(TestURL, AuthorityWithUserinfo) | |
59 | { | |
60 | std::string host; | |
61 | std::string user; | |
62 | std::string password; | |
e306af50 | 63 | const std::string url = "https://user:password@example.com"; |
9f95a23c TL |
64 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); |
65 | EXPECT_STREQ(host.c_str(), "example.com"); | |
66 | EXPECT_STREQ(user.c_str(), "user"); | |
67 | EXPECT_STREQ(password.c_str(), "password"); | |
68 | } | |
69 | ||
70 | TEST(TestURL, AuthorityWithPort) | |
71 | { | |
72 | std::string host; | |
73 | std::string user; | |
74 | std::string password; | |
75 | const std::string url = "http://user:password@example.com:1234"; | |
76 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
77 | EXPECT_STREQ(host.c_str(), "example.com:1234"); | |
78 | EXPECT_STREQ(user.c_str(), "user"); | |
79 | EXPECT_STREQ(password.c_str(), "password"); | |
80 | } | |
81 | ||
82 | TEST(TestURL, DifferentSchema) | |
83 | { | |
84 | std::string host; | |
85 | std::string user; | |
86 | std::string password; | |
87 | const std::string url = "kafka://example.com"; | |
88 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
89 | ASSERT_TRUE(user.empty()); | |
90 | ASSERT_TRUE(password.empty()); | |
91 | EXPECT_STREQ(host.c_str(), "example.com"); | |
92 | } | |
93 | ||
94 | TEST(TestURL, InvalidHost) | |
95 | { | |
96 | std::string host; | |
97 | std::string user; | |
98 | std::string password; | |
99 | const std::string url = "http://exa_mple.com"; | |
100 | ASSERT_FALSE(parse_url_authority(url, host, user, password)); | |
101 | } | |
102 | ||
e306af50 TL |
103 | TEST(TestURL, WithPath) |
104 | { | |
105 | std::string host; | |
106 | std::string user; | |
107 | std::string password; | |
108 | const std::string url = "amqps://www.example.com:1234/vhost_name"; | |
109 | ASSERT_TRUE(parse_url_authority(url, host, user, password)); | |
110 | } | |
111 |