Skip to content

Commit a25d07c

Browse files
Add unit test for ReadExternalEntitites
1 parent c76a6d6 commit a25d07c

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Compile Include="..\DotNetUnitTest\ConfigMappings\ConfigTest.cs" Link="ConfigMappings\ConfigTest.cs" />
1515
<Compile Include="..\DotNetUnitTest\Domain\GxHttpClientTest.cs" Link="Domain\GxHttpClientTest.cs" />
1616
<Compile Include="..\DotNetUnitTest\Domain\ShellTest.cs" Link="Domain\ShellTest.cs" />
17+
<Compile Include="..\DotNetUnitTest\Domain\XmlReaderTest.cs" Link="Domain\XmlReaderTest.cs" />
1718
<Compile Include="..\DotNetUnitTest\FileIO\DfrgFunctions.cs" Link="FileIO\DfrgFunctions.cs" />
1819
<Compile Include="..\DotNetUnitTest\FileIO\FileSystemTest.cs" Link="FileIO\FileSystemTest.cs" />
1920
<Compile Include="..\DotNetUnitTest\FileIO\Xslt.cs" Link="FileIO\Xslt.cs" />
@@ -38,6 +39,9 @@
3839
<EmbeddedResource Include="..\DotNetUnitTest\type_SdtItem.cs" Link="type_SdtItem.cs">
3940
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4041
</EmbeddedResource>
42+
<Content Include="..\DotNetUnitTest\resources\QueryViewerObjects.xml" Link="resources\QueryViewerObjects.xml">
43+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
44+
</Content>
4145
<Content Include="..\DotNetUnitTest\resources\xml\error.xml" Link="resources\xml\error.xml">
4246
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4347
</Content>
@@ -159,6 +163,9 @@
159163

160164

161165
<ItemGroup>
166+
<None Include="..\DotNetUnitTest\resources\QueryViewerObjects.xsd" Link="resources\QueryViewerObjects.xsd">
167+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
168+
</None>
162169
<None Include="..\DotNetUnitTest\resources\xml\xmlTohtml1.xsl" Link="resources\xml\xmlTohtml1.xsl">
163170
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
164171
</None>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.IO;
3+
using System.Xml;
4+
using GeneXus.XML;
5+
using Xunit;
6+
7+
namespace xUnitTesting
8+
{
9+
public class XmlReaderTest
10+
{
11+
[Fact]
12+
public void TestExternalEntitiesEnabled()
13+
{
14+
TestExternalEntities(1);
15+
}
16+
[Fact]
17+
public void TestExternalEntitiesDisabled()
18+
{
19+
TestExternalEntities(0);
20+
}
21+
void TestExternalEntities(int externalEntities)
22+
{
23+
string xml;
24+
string value;
25+
GXXMLReader xmlReader;
26+
27+
using (xmlReader = new GXXMLReader(Directory.GetCurrentDirectory()))
28+
{
29+
xmlReader.ReadExternalEntities = externalEntities;
30+
xml = "";
31+
xml += "<!DOCTYPE Envelope [";
32+
xml += "<!ELEMENT Envelope ANY >";
33+
xml += "<!ENTITY xxe \"Hello\">";
34+
xml += "<!ENTITY xxe2 \"&xxe;&xxe;&xxe;&xxe;\">";
35+
xml += "] >";
36+
xml += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xxe=\"issue63212\">";
37+
xml += "<soapenv:Header/>";
38+
xml += "<soapenv:Body>";
39+
xml += "<xxe:helloworld.Execute>";
40+
xml += "<xxe:Name>&xxe2;</xxe:Name>";
41+
xml += "</xxe:helloworld.Execute>";
42+
xml += "</soapenv:Body>";
43+
xml += "</soapenv:Envelope>";
44+
xmlReader.OpenFromString(xml);
45+
Assert.Equal(0, xmlReader.ErrCode);
46+
Assert.Equal(string.Empty, xmlReader.ErrDescription);
47+
if (!xmlReader.EOF)
48+
{
49+
xmlReader.Read();
50+
Assert.Equal(0, xmlReader.ErrCode);
51+
Assert.Equal(string.Empty, xmlReader.ErrDescription);
52+
value = xmlReader.Value;
53+
if (externalEntities==0)
54+
Assert.Equal(string.Empty, value);
55+
else
56+
Assert.Equal("Envelope", value);
57+
}
58+
xmlReader.Close();
59+
}
60+
61+
}
62+
[Fact]
63+
public void TestValidationType()
64+
{
65+
string value;
66+
GXXMLReader xmlReader;
67+
68+
using (xmlReader = new GXXMLReader(Directory.GetCurrentDirectory()))
69+
{
70+
xmlReader.ValidationType = GXXMLReader.ValidationSchema;
71+
xmlReader.AddSchema("./resources/QueryViewerObjects.xsd", "qv");
72+
xmlReader.Open("./resources/QueryViewerObjects.xml");
73+
Assert.Equal(string.Empty, xmlReader.ErrDescription);
74+
Assert.Equal(0, xmlReader.ErrCode);
75+
if (!xmlReader.EOF)
76+
{
77+
xmlReader.Read();
78+
Assert.Equal(0, xmlReader.ErrCode);
79+
Assert.Equal(string.Empty, xmlReader.ErrDescription);
80+
value = xmlReader.Name;
81+
Assert.Equal("Objects", value);
82+
}
83+
xmlReader.Close();
84+
}
85+
86+
}
87+
}
88+
}

dotnet/test/DotNetUnitTest/DotNetUnitTest.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
<None Update="resources\bird-thumbnail.jpg">
6969
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7070
</None>
71+
<None Update="resources\QueryViewerObjects.xml">
72+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+
</None>
74+
<None Update="resources\QueryViewerObjects.xsd">
75+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76+
</None>
7177
<None Update="resources\text.txt">
7278
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7379
</None>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Objects xmlns="qv">
3+
<Object name="General.UI.SidebarItemsDP" id="1" type="DataProvider" IntegratedSecurityLevel="SecurityLow" xmlns="qv">
4+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
5+
</Object>
6+
<Object name="Cliente_DataProvider" id="2" type="DataProvider" IntegratedSecurityLevel="SecurityLow" xmlns="qv">
7+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
8+
</Object>
9+
<Object name="DataProviderNone" id="7" type="DataProvider" IntegratedSecurityLevel="SecurityNone" xmlns="qv">
10+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
11+
</Object>
12+
<Object name="DataProviderAuthorization" id="8" type="DataProvider" IntegratedSecurityLevel="SecurityHigh" PermissionPrefix="DataProviderAuthorization" xmlns="qv">
13+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
14+
</Object>
15+
<Object name="DataProviderAuthentication" id="9" type="DataProvider" IntegratedSecurityLevel="SecurityLow" xmlns="qv">
16+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
17+
</Object>
18+
<Object name="QueryNone" id="1" type="Query" IntegratedSecurityLevel="SecurityNone" xmlns="qv">
19+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
20+
</Object>
21+
<Object name="QueryAuthentication" id="2" type="Query" IntegratedSecurityLevel="SecurityLow" xmlns="qv">
22+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
23+
</Object>
24+
<Object name="QueryAuthorization" id="3" type="Query" IntegratedSecurityLevel="SecurityHigh" PermissionPrefix="QueryAuthorization" xmlns="qv">
25+
<DefaultOutput type="OutputTypePivotTable" xmlns="qv" />
26+
</Object>
27+
</Objects>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
targetNamespace="qv"
4+
xmlns="qv"
5+
elementFormDefault="qualified">
6+
<xs:element name="Objects">
7+
<xs:complexType>
8+
<xs:sequence>
9+
<xs:element name="Object" minOccurs="0" maxOccurs="unbounded">
10+
<xs:complexType>
11+
<xs:sequence>
12+
<xs:element name="DefaultOutput">
13+
<xs:complexType>
14+
<xs:attribute name="type" type="outputType" use="required"/>
15+
</xs:complexType>
16+
</xs:element>
17+
</xs:sequence>
18+
<xs:attribute name="name" type="xs:string" use="required"/>
19+
<xs:attribute name="id" type="xs:nonNegativeInteger" use="required"/>
20+
<xs:attribute name="type" type="objectType" use="required"/>
21+
<xs:attribute name="IntegratedSecurityLevel" type="securityLevel"/>
22+
<xs:attribute name="PermissionPrefix" type="xs:string"/>
23+
</xs:complexType>
24+
</xs:element>
25+
</xs:sequence>
26+
</xs:complexType>
27+
</xs:element>
28+
<xs:simpleType name="objectType">
29+
<xs:restriction base="xs:string">
30+
<xs:enumeration value="Query"/>
31+
<xs:enumeration value="DataProvider"/>
32+
</xs:restriction>
33+
</xs:simpleType>
34+
<xs:simpleType name="securityLevel">
35+
<xs:restriction base="xs:string">
36+
<xs:enumeration value="SecurityNone"/>
37+
<xs:enumeration value="SecurityLow"/>
38+
<xs:enumeration value="SecurityHigh"/>
39+
</xs:restriction>
40+
</xs:simpleType>
41+
<xs:simpleType name="outputType">
42+
<xs:restriction base="xs:string">
43+
<xs:enumeration value="OutputTypeCard"/>
44+
<xs:enumeration value="OutputTypeMap"/>
45+
<xs:enumeration value="OutputTypePivotTable"/>
46+
<xs:enumeration value="OutputTypeTable"/>
47+
<xs:enumeration value="OutputTypeChartColumn"/>
48+
<xs:enumeration value="OutputTypeChartColumn3D"/>
49+
<xs:enumeration value="OutputTypeChartStackedColumn"/>
50+
<xs:enumeration value="OutputTypeChartStackedColumn3D"/>
51+
<xs:enumeration value="OutputTypeChartStackedColumn100"/>
52+
<xs:enumeration value="OutputTypeChartBar"/>
53+
<xs:enumeration value="OutputTypeChartStackedBar"/>
54+
<xs:enumeration value="OutputTypeChartStackedBar100"/>
55+
<xs:enumeration value="OutputTypeChartArea"/>
56+
<xs:enumeration value="OutputTypeChartStackedArea"/>
57+
<xs:enumeration value="OutputTypeChartStackedArea100"/>
58+
<xs:enumeration value="OutputTypeChartSmoothArea"/>
59+
<xs:enumeration value="OutputTypeChartStepArea"/>
60+
<xs:enumeration value="OutputTypeChartLine"/>
61+
<xs:enumeration value="OutputTypeChartStackedLine"/>
62+
<xs:enumeration value="OutputTypeChartStackedLine100"/>
63+
<xs:enumeration value="OutputTypeChartSmoothLine"/>
64+
<xs:enumeration value="OutputTypeChartStepLine"/>
65+
<xs:enumeration value="OutputTypeChartPie"/>
66+
<xs:enumeration value="OutputTypeChartPie3D"/>
67+
<xs:enumeration value="OutputTypeChartDoughnut"/>
68+
<xs:enumeration value="OutputTypeChartDoughnut3D"/>
69+
<xs:enumeration value="OutputTypeChartLinearGauge"/>
70+
<xs:enumeration value="OutputTypeChartCircularGauge"/>
71+
<xs:enumeration value="OutputTypeChartRadar"/>
72+
<xs:enumeration value="OutputTypeChartFilledRadar"/>
73+
<xs:enumeration value="OutputTypeChartPolarArea"/>
74+
<xs:enumeration value="OutputTypeChartFunnel"/>
75+
<xs:enumeration value="OutputTypeChartPyramid"/>
76+
<xs:enumeration value="OutputTypeChartColumnLine"/>
77+
<xs:enumeration value="OutputTypeChartColumn3DLine"/>
78+
<xs:enumeration value="OutputTypeChartTimeline"/>
79+
<xs:enumeration value="OutputTypeChartSmoothTimeline"/>
80+
<xs:enumeration value="OutputTypeChartStepTimeline"/>
81+
<xs:enumeration value="OutputTypeChartSparkline"/>
82+
</xs:restriction>
83+
</xs:simpleType>
84+
</xs:schema>

0 commit comments

Comments
 (0)