]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/rgw/test_rgw_url.cc
import 15.2.4
[ceph.git] / ceph / src / test / rgw / test_rgw_url.cc
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "rgw/rgw_url.h"
5#include <string>
6#include <gtest/gtest.h>
7
8using namespace rgw;
9
10TEST(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
22TEST(TestURL, IPAuthority)
23{
24 std::string host;
25 std::string user;
26 std::string password;
27 const std::string url = "http://1.2.3.4";
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(), "1.2.3.4");
32}
33
34TEST(TestURL, IPv6Authority)
35{
36 std::string host;
37 std::string user;
38 std::string password;
39 const std::string url = "http://FE80:CD00:0000:0CDE:1257:0000:211E:729C";
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(), "FE80:CD00:0000:0CDE:1257:0000:211E:729C");
44}
45
46TEST(TestURL, AuthorityWithUserinfo)
47{
48 std::string host;
49 std::string user;
50 std::string password;
e306af50 51 const std::string url = "https://user:password@example.com";
9f95a23c
TL
52 ASSERT_TRUE(parse_url_authority(url, host, user, password));
53 EXPECT_STREQ(host.c_str(), "example.com");
54 EXPECT_STREQ(user.c_str(), "user");
55 EXPECT_STREQ(password.c_str(), "password");
56}
57
58TEST(TestURL, AuthorityWithPort)
59{
60 std::string host;
61 std::string user;
62 std::string password;
63 const std::string url = "http://user:password@example.com:1234";
64 ASSERT_TRUE(parse_url_authority(url, host, user, password));
65 EXPECT_STREQ(host.c_str(), "example.com:1234");
66 EXPECT_STREQ(user.c_str(), "user");
67 EXPECT_STREQ(password.c_str(), "password");
68}
69
70TEST(TestURL, DifferentSchema)
71{
72 std::string host;
73 std::string user;
74 std::string password;
75 const std::string url = "kafka://example.com";
76 ASSERT_TRUE(parse_url_authority(url, host, user, password));
77 ASSERT_TRUE(user.empty());
78 ASSERT_TRUE(password.empty());
79 EXPECT_STREQ(host.c_str(), "example.com");
80}
81
82TEST(TestURL, InvalidHost)
83{
84 std::string host;
85 std::string user;
86 std::string password;
87 const std::string url = "http://exa_mple.com";
88 ASSERT_FALSE(parse_url_authority(url, host, user, password));
89}
90
e306af50
TL
91TEST(TestURL, WithPath)
92{
93 std::string host;
94 std::string user;
95 std::string password;
96 const std::string url = "amqps://www.example.com:1234/vhost_name";
97 ASSERT_TRUE(parse_url_authority(url, host, user, password));
98}
99