forked from baritonehands/jenkinsnuget
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
039f189
commit c8ed4cb
Showing
4 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/org/jenkinsci/plugins/nuget/utils/NugetPackageCheckerVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jenkinsci.plugins.nuget.utils; | ||
|
||
import org.jenkinsci.plugins.nuget.NugetGlobalConfiguration; | ||
import org.jenkinsci.plugins.nuget.triggers.logs.TriggerLog; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.xml.sax.SAXParseException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Path; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class NugetPackageCheckerVisitorTest { | ||
|
||
NugetPackageCheckerVisitor visitor; | ||
TriggerLog log; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
log = mock(TriggerLog.class); | ||
NugetGlobalConfiguration configuration = mock(NugetGlobalConfiguration.class); | ||
visitor = new NugetPackageCheckerVisitor( | ||
log, | ||
configuration, | ||
true, | ||
null | ||
); | ||
visitor.getLatestPackageVersions().put("Test", "1.0.0"); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeVulnerableToXxe() throws URISyntaxException, IOException { | ||
Path file = getFile("xxe"); | ||
FileVisitResult fileVisitResult = visitor.visitFile(file, null); | ||
|
||
ArgumentCaptor<SAXParseException> exceptionArgumentCaptor = ArgumentCaptor.forClass(SAXParseException.class); | ||
verify(log).errorWhileParsingPackageConfigFile(exceptionArgumentCaptor.capture()); | ||
SAXParseException exception = exceptionArgumentCaptor.getValue(); | ||
assertEquals(DOCTYPE_FORBIDDEN_ERROR, exception.getMessage()); | ||
} | ||
|
||
private Path getFile(String path) throws URISyntaxException { | ||
URL url = getClass() | ||
.getClassLoader() | ||
.getResource("NugetPackageCheckerVisitorTest/" + path + "/packages.config"); | ||
File file = new File(url.toURI()); | ||
return file.toPath(); | ||
} | ||
|
||
final String DOCTYPE_FORBIDDEN_ERROR = | ||
"DOCTYPE is disallowed when the feature \"http://apache.org/xml/features/disallow-doctype-decl\" set to true."; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/resources/NugetPackageCheckerVisitorTest/xxe/packages.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE packages [ | ||
<!ELEMENT packages (package)> | ||
<!ELEMENT package (#PCDATA)> | ||
<!ATTLIST package | ||
id CDATA #REQUIRED | ||
version CDATA #REQUIRED | ||
targetFramework CDATA #REQUIRED | ||
> | ||
<!ENTITY xxe SYSTEM "file:///evil"> | ||
]> | ||
<packages> | ||
<package id="Test" version="1.0.0" targetFramework="net46" >&xxe;</package> | ||
</packages> |