-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test failure in testReadFromValidCSVContentString.java on Windows * Prevent path traversal exploit * Fixed failed tests after fix for path traversal
- Loading branch information
Showing
5 changed files
with
178 additions
and
73 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
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/io/frictionlessdata/tableschema/DataSourceTest.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 io.frictionlessdata.tableschema; | ||
|
||
import com.sun.javafx.PlatformUtil; | ||
import io.frictionlessdata.tableschema.datasources.DataSource; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class DataSourceTest { | ||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
||
@Test | ||
public void testUnsafePath1() throws Exception { | ||
URL u = DataSourceTest.class.getResource("/fixtures/dates_data.csv"); | ||
Path path = Paths.get(u.toURI()); | ||
Path testPath = path.getParent(); | ||
String maliciousPathName = "/etc/passwd"; | ||
if (PlatformUtil.isWindows()){ | ||
maliciousPathName = "C:/Windows/system.ini"; | ||
} | ||
Path maliciousPath = new File(maliciousPathName).toPath(); | ||
exception.expect(IllegalArgumentException.class); | ||
DataSource.toSecure(maliciousPath, testPath); | ||
} | ||
|
||
@Test | ||
public void testUnsafePath2() throws Exception { | ||
URL u = DataSourceTest.class.getResource("/fixtures/dates_data.csv"); | ||
Path path = Paths.get(u.toURI()); | ||
Path testPath = path.getParent(); | ||
String maliciousPathName = "/etc/"; | ||
if (PlatformUtil.isWindows()){ | ||
maliciousPathName = "C:/Windows/"; | ||
} | ||
Path maliciousPath = new File(maliciousPathName).toPath(); | ||
exception.expect(IllegalArgumentException.class); | ||
DataSource.toSecure(maliciousPath, testPath); | ||
} | ||
|
||
@Test | ||
public void testSafePath() throws Exception { | ||
URL u = DataSourceTest.class.getResource("/fixtures/dates_data.csv"); | ||
Path path = Paths.get(u.toURI()); | ||
Path testPath = path.getParent().getParent(); | ||
String maliciousPathName = "fixtures/dates_data.csv"; | ||
if (PlatformUtil.isWindows()){ | ||
maliciousPathName = "fixtures/dates_data.csv"; | ||
} | ||
Path maliciousPath = new File(maliciousPathName).toPath(); | ||
DataSource.toSecure(maliciousPath, testPath); | ||
} | ||
} | ||
|
Oops, something went wrong.