summaryrefslogtreecommitdiffstats
path: root/src/test/rgw/test_rgw_lc.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/rgw/test_rgw_lc.cc
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/rgw/test_rgw_lc.cc')
-rw-r--r--src/test/rgw/test_rgw_lc.cc109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/test/rgw/test_rgw_lc.cc b/src/test/rgw/test_rgw_lc.cc
new file mode 100644
index 000000000..83a4cac67
--- /dev/null
+++ b/src/test/rgw/test_rgw_lc.cc
@@ -0,0 +1,109 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "rgw_xml.h"
+#include "rgw_lc.h"
+#include "rgw_lc_s3.h"
+#include <gtest/gtest.h>
+//#include <spawn/spawn.hpp>
+#include <string>
+#include <vector>
+#include <stdexcept>
+
+static const char* xmldoc_1 =
+R"(<Filter>
+ <And>
+ <Prefix>tax/</Prefix>
+ <Tag>
+ <Key>key1</Key>
+ <Value>value1</Value>
+ </Tag>
+ <Tag>
+ <Key>key2</Key>
+ <Value>value2</Value>
+ </Tag>
+ </And>
+</Filter>
+)";
+
+TEST(TestLCFilterDecoder, XMLDoc1)
+{
+ RGWXMLDecoder::XMLParser parser;
+ ASSERT_TRUE(parser.init());
+ ASSERT_TRUE(parser.parse(xmldoc_1, strlen(xmldoc_1), 1));
+ LCFilter_S3 filter;
+ auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
+ ASSERT_TRUE(result);
+ /* check repeated Tag element */
+ auto tag_map = filter.get_tags().get_tags();
+ auto val1 = tag_map.find("key1");
+ ASSERT_EQ(val1->second, "value1");
+ auto val2 = tag_map.find("key2");
+ ASSERT_EQ(val2->second, "value2");
+ /* check our flags */
+ ASSERT_EQ(filter.get_flags(), 0);
+}
+
+static const char* xmldoc_2 =
+R"(<Filter>
+ <And>
+ <ArchiveZone />
+ <Tag>
+ <Key>spongebob</Key>
+ <Value>squarepants</Value>
+ </Tag>
+ </And>
+</Filter>
+)";
+
+TEST(TestLCFilterDecoder, XMLDoc2)
+{
+ RGWXMLDecoder::XMLParser parser;
+ ASSERT_TRUE(parser.init());
+ ASSERT_TRUE(parser.parse(xmldoc_2, strlen(xmldoc_2), 1));
+ LCFilter_S3 filter;
+ auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
+ ASSERT_TRUE(result);
+ /* check tags */
+ auto tag_map = filter.get_tags().get_tags();
+ auto val1 = tag_map.find("spongebob");
+ ASSERT_EQ(val1->second, "squarepants");
+ /* check our flags */
+ ASSERT_EQ(filter.get_flags(), LCFilter::make_flag(LCFlagType::ArchiveZone));
+}
+
+// invalid And element placement
+static const char* xmldoc_3 =
+R"(<Filter>
+ <And>
+ <Tag>
+ <Key>miles</Key>
+ <Value>davis</Value>
+ </Tag>
+ </And>
+ <Tag>
+ <Key>spongebob</Key>
+ <Value>squarepants</Value>
+ </Tag>
+</Filter>
+)";
+
+TEST(TestLCFilterInvalidAnd, XMLDoc3)
+{
+ RGWXMLDecoder::XMLParser parser;
+ ASSERT_TRUE(parser.init());
+ ASSERT_TRUE(parser.parse(xmldoc_3, strlen(xmldoc_3), 1));
+ LCFilter_S3 filter;
+ auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
+ ASSERT_TRUE(result);
+ /* check repeated Tag element */
+ auto tag_map = filter.get_tags().get_tags();
+ auto val1 = tag_map.find("spongebob");
+ ASSERT_TRUE(val1 == tag_map.end());
+ /* because the invalid 2nd tag element was not recognized,
+ * we cannot access it:
+ ASSERT_EQ(val1->second, "squarepants");
+ */
+ /* check our flags */
+ ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::none));
+}