]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/rgw/test_rgw_lc.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / rgw / test_rgw_lc.cc
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_xml.h"
5 #include "rgw_lc.h"
6 #include "rgw_lc_s3.h"
7 #include <gtest/gtest.h>
8 //#include <spawn/spawn.hpp>
9 #include <string>
10 #include <vector>
11 #include <stdexcept>
12
13 static const char* xmldoc_1 =
14 R"(<Filter>
15 <And>
16 <Prefix>tax/</Prefix>
17 <Tag>
18 <Key>key1</Key>
19 <Value>value1</Value>
20 </Tag>
21 <Tag>
22 <Key>key2</Key>
23 <Value>value2</Value>
24 </Tag>
25 </And>
26 </Filter>
27 )";
28
29 TEST(TestLCFilterDecoder, XMLDoc1)
30 {
31 RGWXMLDecoder::XMLParser parser;
32 ASSERT_TRUE(parser.init());
33 ASSERT_TRUE(parser.parse(xmldoc_1, strlen(xmldoc_1), 1));
34 LCFilter_S3 filter;
35 auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
36 ASSERT_TRUE(result);
37 /* check repeated Tag element */
38 auto tag_map = filter.get_tags().get_tags();
39 auto val1 = tag_map.find("key1");
40 ASSERT_EQ(val1->second, "value1");
41 auto val2 = tag_map.find("key2");
42 ASSERT_EQ(val2->second, "value2");
43 /* check our flags */
44 ASSERT_EQ(filter.get_flags(), 0);
45 }
46
47 static const char* xmldoc_2 =
48 R"(<Filter>
49 <And>
50 <ArchiveZone />
51 <Tag>
52 <Key>spongebob</Key>
53 <Value>squarepants</Value>
54 </Tag>
55 </And>
56 </Filter>
57 )";
58
59 TEST(TestLCFilterDecoder, XMLDoc2)
60 {
61 RGWXMLDecoder::XMLParser parser;
62 ASSERT_TRUE(parser.init());
63 ASSERT_TRUE(parser.parse(xmldoc_2, strlen(xmldoc_2), 1));
64 LCFilter_S3 filter;
65 auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
66 ASSERT_TRUE(result);
67 /* check tags */
68 auto tag_map = filter.get_tags().get_tags();
69 auto val1 = tag_map.find("spongebob");
70 ASSERT_EQ(val1->second, "squarepants");
71 /* check our flags */
72 ASSERT_EQ(filter.get_flags(), LCFilter::make_flag(LCFlagType::ArchiveZone));
73 }
74
75 // invalid And element placement
76 static const char* xmldoc_3 =
77 R"(<Filter>
78 <And>
79 <Tag>
80 <Key>miles</Key>
81 <Value>davis</Value>
82 </Tag>
83 </And>
84 <Tag>
85 <Key>spongebob</Key>
86 <Value>squarepants</Value>
87 </Tag>
88 </Filter>
89 )";
90
91 TEST(TestLCFilterInvalidAnd, XMLDoc3)
92 {
93 RGWXMLDecoder::XMLParser parser;
94 ASSERT_TRUE(parser.init());
95 ASSERT_TRUE(parser.parse(xmldoc_3, strlen(xmldoc_3), 1));
96 LCFilter_S3 filter;
97 auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
98 ASSERT_TRUE(result);
99 /* check repeated Tag element */
100 auto tag_map = filter.get_tags().get_tags();
101 auto val1 = tag_map.find("spongebob");
102 ASSERT_TRUE(val1 == tag_map.end());
103 /* because the invalid 2nd tag element was not recognized,
104 * we cannot access it:
105 ASSERT_EQ(val1->second, "squarepants");
106 */
107 /* check our flags */
108 ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::none));
109 }