Fix junit tests under windows when the platform is explicitly changed
SystemReader used a chached ObjectChecker which was instantiated only once. But in case of unit tests where we can change the platform dynamically (e.g. MockSystemReader.setWindows()) this is wrong and caused DirCacheCheckoutMaliciousPathTest. testMaliciousAbsoluteCurDrivePathWindowsOnUnix() to fail. This change allows user of SystemReader to force the creation of a new ObjectChecker. MockSystemReader.setWindows() and .setUnix() make use of this feature. Change-Id: I87458d1dc63c1f5c18979f972b1c1f0d670a9ed8
This commit is contained in:
parent
d49c9ee848
commit
3226e35db8
|
@ -184,6 +184,7 @@ public void setWindows() {
|
||||||
setProperty("file.separator", "\\");
|
setProperty("file.separator", "\\");
|
||||||
setProperty("path.separator", ";");
|
setProperty("path.separator", ";");
|
||||||
setProperty("line.separator", "\r\n");
|
setProperty("line.separator", "\r\n");
|
||||||
|
setPlatformChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,5 +195,6 @@ public void setUnix() {
|
||||||
setProperty("file.separator", "/");
|
setProperty("file.separator", "/");
|
||||||
setProperty("path.separator", ":");
|
setProperty("path.separator", ":");
|
||||||
setProperty("line.separator", "\n");
|
setProperty("line.separator", "\n");
|
||||||
|
setPlatformChecker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,11 +163,19 @@ public static void setInstance(SystemReader newReader) {
|
||||||
private void init() {
|
private void init() {
|
||||||
// Creating ObjectChecker must be deferred. Unit tests change
|
// Creating ObjectChecker must be deferred. Unit tests change
|
||||||
// behavior of is{Windows,MacOS} in constructor of subclass.
|
// behavior of is{Windows,MacOS} in constructor of subclass.
|
||||||
if (platformChecker == null) {
|
if (platformChecker == null)
|
||||||
platformChecker = new ObjectChecker()
|
setPlatformChecker();
|
||||||
.setSafeForWindows(isWindows())
|
}
|
||||||
.setSafeForMacOS(isMacOS());
|
|
||||||
}
|
/**
|
||||||
|
* Should be used in tests when the platform is explicitly changed.
|
||||||
|
*
|
||||||
|
* @since 3.6
|
||||||
|
*/
|
||||||
|
protected final void setPlatformChecker() {
|
||||||
|
platformChecker = new ObjectChecker()
|
||||||
|
.setSafeForWindows(isWindows())
|
||||||
|
.setSafeForMacOS(isMacOS());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue