Skip to content

Commit

Permalink
Support importing https pages, fixes unclebob#1086
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoeben committed Dec 17, 2019
1 parent 2233026 commit d5d7fd3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
1 change: 1 addition & 0 deletions FitNesseRoot/FitNesse/ReleaseNotes/content.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!2 ${FITNESSE_VERSION}
* Support importing remote wiki pages over https (not just http) ([[1086][https://github.com/unclebob/fitnesse/issues/1086]])

!2 20191110
* Improved failure navigator at top-right after running tests: some tests were missed, others were counted twice. #1246
Expand Down
36 changes: 26 additions & 10 deletions src/fitnesse/responders/WikiImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class WikiImporter implements XmlizerPageHandler, TraversalListener<WikiP
private String remoteUsername;
private String remotePassword;

private String remoteProtocol;
private String remoteHostname;
private int remotePort;
private WikiPagePath localPath;
Expand Down Expand Up @@ -179,7 +180,7 @@ protected void importRemotePageContent(WikiPage localPage) throws IOException {

public String remoteUrl() {
String remotePathName = PathParser.render(remotePath);
return "http://" + remoteHostname + ":" + remotePort + "/" + remotePathName;
return remoteProtocol + "://" + remoteHostname + ":" + remotePort + "/" + remotePathName;
}

@Override
Expand Down Expand Up @@ -233,6 +234,10 @@ public WikiPagePath getLocalPath() {
return localPath;
}

public String getRemoteProtocol() {
return remoteProtocol;
}

public String getRemoteHostname() {
return remoteHostname;
}
Expand All @@ -259,27 +264,38 @@ public void parseUrl(String urlString) throws MalformedURLException {
URL url;
try {
url = new URL(urlString);
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new MalformedURLException(urlString + " is not a valid URL.");
}

remoteProtocol = url.getProtocol();
remoteHostname = url.getHost();
remotePort = url.getPort();
if (remotePort == -1)
remotePort = 80;

String path = url.getPath();
while (path.startsWith("/"))
path = path.substring(1);
remotePort = extractPort(url);

String path = extractPath(url);
remotePath = PathParser.parse(path);

if (remotePath == null) {
throw new MalformedURLException("The URL's resource path, " + path + ", is not a valid WikiWord.");
}
}

private int extractPort(URL url) {
int port = url.getPort();
if (port == -1) {
port = url.getDefaultPort();
}
return port;
}

private String extractPath(URL url) {
String path = url.getPath();
while (path.startsWith("/")) {
path = path.substring(1);
}
return path;
}

public void setWikiImporterClient(WikiImporterClient client) {
importerClient = client;
}
Expand Down
31 changes: 22 additions & 9 deletions test/fitnesse/responders/WikiImporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,31 @@ public void testGetPageTree() throws Exception {
}

@Test
public void testUrlParsing() throws Exception {
testUrlParsing("http://mysite.com", "mysite.com", 80, "");
testUrlParsing("http://mysite.com/", "mysite.com", 80, "");
testUrlParsing("http://mysite.com:8080/", "mysite.com", 8080, "");
testUrlParsing("http://mysite.com:8080", "mysite.com", 8080, "");
testUrlParsing("http://mysite.com:80/", "mysite.com", 80, "");
testUrlParsing("http://mysite.com/PageOne", "mysite.com", 80, "PageOne");
testUrlParsing("http://mysite.com/PageOne.ChildOne", "mysite.com", 80, "PageOne.ChildOne");
public void testUrlParsingHttp() throws Exception {
testUrlParsing("http://mysite.com", "http", "mysite.com", 80, "");
testUrlParsing("http://mysite.com/", "http", "mysite.com", 80, "");
testUrlParsing("http://mysite.com:8080/", "http", "mysite.com", 8080, "");
testUrlParsing("http://mysite.com:8080", "http", "mysite.com", 8080, "");
testUrlParsing("http://mysite.com:80/", "http", "mysite.com", 80, "");
testUrlParsing("http://mysite.com/PageOne", "http", "mysite.com", 80, "PageOne");
testUrlParsing("http://mysite.com/PageOne.ChildOne", "http", "mysite.com", 80, "PageOne.ChildOne");
}

private void testUrlParsing(String url, String host, int port, String path) throws Exception {
@Test
public void testUrlParsingHttps() throws Exception {
testUrlParsing("https://mysite.com", "https", "mysite.com", 443, "");
testUrlParsing("https://mysite.com/", "https", "mysite.com", 443, "");
testUrlParsing("https://mysite.com:8080/", "https", "mysite.com", 8080, "");
testUrlParsing("https://mysite.com:8080", "https", "mysite.com", 8080, "");
testUrlParsing("https://mysite.com:80/", "https", "mysite.com", 80, "");
testUrlParsing("https://mysite.com/PageOne", "https", "mysite.com", 443, "PageOne");
testUrlParsing("https://mysite.com/PageOne.ChildOne", "https", "mysite.com", 443, "PageOne.ChildOne");
testUrlParsing("https://mysite.com:377/PageOne.ChildOne", "https", "mysite.com", 377, "PageOne.ChildOne");
}

private void testUrlParsing(String url, String protocol, String host, int port, String path) throws Exception {
importer.parseUrl(url);
assertEquals(protocol, importer.getRemoteProtocol());
assertEquals(host, importer.getRemoteHostname());
assertEquals(port, importer.getRemotePort());
assertEquals(path, PathParser.render(importer.getRemotePath()));
Expand Down

0 comments on commit d5d7fd3

Please sign in to comment.