-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move trailing slash removal from SFTPEngine.mkdirs() to PathHelper.…
…getComponents() - Try to make the PathHelper.getComponents() code clearer - Added some tests for PathHelper.getComponents()
- Loading branch information
Showing
3 changed files
with
104 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package net.schmizz.sshj.sftp; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
public class PathHelperTest { | ||
|
||
private final PathHelper helper = new PathHelper(new PathHelper.Canonicalizer() { | ||
/** | ||
* Very basic, it does not try to canonicalize relative bits in the middle of a path. | ||
*/ | ||
@Override | ||
public String canonicalize(String path) | ||
throws IOException { | ||
if (path.equals("") || path.equals(".") || path.equals("./")) | ||
return "/home/me"; | ||
if (path.equals("..") || path.equals("../")) | ||
return "/home"; | ||
return path; | ||
} | ||
}, "/"); | ||
|
||
@Test | ||
public void empty() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents(""); | ||
assertEquals("me", comp.getName()); | ||
assertEquals("/home", comp.getParent()); | ||
} | ||
|
||
@Test | ||
public void root() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents("/"); | ||
assertEquals("", comp.getName()); | ||
assertEquals("", comp.getParent()); | ||
} | ||
|
||
@Test | ||
public void dot() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents("."); | ||
assertEquals("me", comp.getName()); | ||
assertEquals("/home", comp.getParent()); | ||
} | ||
|
||
@Test | ||
public void dotDot() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents(".."); | ||
assertEquals("home", comp.getName()); | ||
assertEquals("", comp.getParent()); | ||
} | ||
|
||
@Test | ||
public void fileInHomeDir() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents("somefile"); | ||
assertEquals("somefile", comp.getName()); | ||
assertEquals("", comp.getParent()); | ||
} | ||
|
||
@Test | ||
public void fileSomeLevelsDeep() | ||
throws IOException { | ||
final PathComponents comp = helper.getComponents("/home/me/../somedir/somefile"); | ||
assertEquals("somefile", comp.getName()); | ||
assertEquals("/home/me/../somedir", comp.getParent()); | ||
} | ||
|
||
} |