1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/fpdfdoc/cpdf_metadata.h"
6
7 #include "core/fpdfapi/parser/cpdf_stream.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
TEST(CPDF_MetadataTest,CheckSharedFormEmailAtTopLevel)10 TEST(CPDF_MetadataTest, CheckSharedFormEmailAtTopLevel) {
11 static const char data[] =
12 "<?xml charset=\"utf-8\"?>\n"
13 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
14 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
15 "<adhocwf:version>1.1</adhocwf:version>\n"
16 "</node>";
17
18 auto stream = pdfium::MakeRetain<CPDF_Stream>();
19 stream->SetData(ByteStringView(data).raw_span());
20 CPDF_Metadata metadata(stream.Get());
21
22 auto results = metadata.CheckForSharedForm();
23 ASSERT_EQ(1U, results.size());
24 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
25 }
26
TEST(CPDF_MetadataTest,CheckSharedFormAcrobatAtTopLevel)27 TEST(CPDF_MetadataTest, CheckSharedFormAcrobatAtTopLevel) {
28 static const char data[] =
29 "<?xml charset=\"utf-8\"?>\n"
30 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
31 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
32 "<adhocwf:version>1.1</adhocwf:version>\n"
33 "</node>";
34
35 auto stream = pdfium::MakeRetain<CPDF_Stream>();
36 stream->SetData(ByteStringView(data).raw_span());
37 CPDF_Metadata metadata(stream.Get());
38
39 auto results = metadata.CheckForSharedForm();
40 ASSERT_EQ(1U, results.size());
41 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormAcrobat, results[0]);
42 }
43
TEST(CPDF_MetadataTest,CheckSharedFormFilesystemAtTopLevel)44 TEST(CPDF_MetadataTest, CheckSharedFormFilesystemAtTopLevel) {
45 static const char data[] =
46 "<?xml charset=\"utf-8\"?>\n"
47 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
48 "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
49 "<adhocwf:version>1.1</adhocwf:version>\n"
50 "</node>";
51
52 auto stream = pdfium::MakeRetain<CPDF_Stream>();
53 stream->SetData(ByteStringView(data).raw_span());
54 CPDF_Metadata metadata(stream.Get());
55
56 auto results = metadata.CheckForSharedForm();
57 ASSERT_EQ(1U, results.size());
58 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormFilesystem, results[0]);
59 }
60
TEST(CPDF_MetadataTest,CheckSharedFormWithoutWorkflow)61 TEST(CPDF_MetadataTest, CheckSharedFormWithoutWorkflow) {
62 static const char data[] =
63 "<?xml charset=\"utf-8\"?>\n"
64 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
65 "<adhocwf:state>2</adhocwf:state>\n"
66 "<adhocwf:version>1.1</adhocwf:version>\n"
67 "</node>";
68
69 auto stream = pdfium::MakeRetain<CPDF_Stream>();
70 stream->SetData(ByteStringView(data).raw_span());
71 CPDF_Metadata metadata(stream.Get());
72
73 auto results = metadata.CheckForSharedForm();
74 EXPECT_EQ(0U, results.size());
75 }
76
TEST(CPDF_MetadataTest,CheckSharedFormAsChild)77 TEST(CPDF_MetadataTest, CheckSharedFormAsChild) {
78 static const char data[] =
79 "<?xml charset=\"utf-8\"?>\n"
80 "<grandparent><parent>\n"
81 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
82 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
83 "<adhocwf:version>1.1</adhocwf:version>\n"
84 "</node>"
85 "</parent></grandparent>";
86
87 auto stream = pdfium::MakeRetain<CPDF_Stream>();
88 stream->SetData(ByteStringView(data).raw_span());
89 CPDF_Metadata metadata(stream.Get());
90
91 auto results = metadata.CheckForSharedForm();
92 ASSERT_EQ(1U, results.size());
93 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
94 }
95
TEST(CPDF_MetadataTest,CheckSharedFormAsNoAdhoc)96 TEST(CPDF_MetadataTest, CheckSharedFormAsNoAdhoc) {
97 static const char data[] =
98 "<?xml charset=\"utf-8\"?>\n"
99 "<node></node>";
100
101 auto stream = pdfium::MakeRetain<CPDF_Stream>();
102 stream->SetData(ByteStringView(data).raw_span());
103 CPDF_Metadata metadata(stream.Get());
104
105 auto results = metadata.CheckForSharedForm();
106 EXPECT_EQ(0U, results.size());
107 }
108
TEST(CPDF_MetadataTest,CheckSharedFormWrongNamespace)109 TEST(CPDF_MetadataTest, CheckSharedFormWrongNamespace) {
110 static const char data[] =
111 "<?xml charset=\"utf-8\"?>\n"
112 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/2.0/\">\n"
113 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
114 "<adhocwf:version>1.1</adhocwf:version>\n"
115 "</node>";
116
117 auto stream = pdfium::MakeRetain<CPDF_Stream>();
118 stream->SetData(ByteStringView(data).raw_span());
119 CPDF_Metadata metadata(stream.Get());
120
121 auto results = metadata.CheckForSharedForm();
122 EXPECT_EQ(0U, results.size());
123 }
124
TEST(CPDF_MetadataTest,CheckSharedFormMultipleErrors)125 TEST(CPDF_MetadataTest, CheckSharedFormMultipleErrors) {
126 static const char data[] =
127 "<?xml charset=\"utf-8\"?>\n"
128 "<grandparent>"
129 "<parent>\n"
130 "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
131 "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
132 "<adhocwf:version>1.1</adhocwf:version>\n"
133 "</node>"
134 "</parent>"
135 "<node2 "
136 "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
137 "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
138 "<adhocwf:version>1.1</adhocwf:version>\n"
139 "</node2>"
140 "<node3 "
141 "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
142 "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
143 "<adhocwf:version>1.1</adhocwf:version>\n"
144 "</node3>"
145 "</grandparent>";
146
147 auto stream = pdfium::MakeRetain<CPDF_Stream>();
148 stream->SetData(ByteStringView(data).raw_span());
149 CPDF_Metadata metadata(stream.Get());
150
151 auto results = metadata.CheckForSharedForm();
152 ASSERT_EQ(3U, results.size());
153 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
154 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormFilesystem, results[1]);
155 EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormAcrobat, results[2]);
156 }
157