Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2017-09-02 16:30:46 +0000
committerThomas Wolf2017-09-14 07:59:42 +0000
commitc3e3f95632940d65c46a2212a12938b0eedbd0ef (patch)
tree26faea5636d3bb6966c08c310ad40c45b651b543 /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui
parent65c68b362052a0be3f5daba1515daeb341ab4134 (diff)
downloadegit-c3e3f95632940d65c46a2212a12938b0eedbd0ef.tar.gz
egit-c3e3f95632940d65c46a2212a12938b0eedbd0ef.tar.xz
egit-c3e3f95632940d65c46a2212a12938b0eedbd0ef.zip
Add a test for cloning via HTTPS
Tests that cloning from an HTTPS server that has a certificate that doesn't validate pops up the correct dialog, and that after trusting the server all the same, the clone proceeds successfully. Fixes some bugs in apparently never used parts of the CustomPromptDialog that the EGitCredentialsProvider uses to get user input. Bug: 374703 JGit-Dependency: Ie1abada9a3d389ad4d8d52c2d5265d2764e3fb0e Change-Id: I6e3dbf6bf7d0db1459d7baedf5b20be5c894aada Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/GitCloneWizardHttpsTest.java88
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/SampleTestRepository.java39
2 files changed, 122 insertions, 5 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/GitCloneWizardHttpsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/GitCloneWizardHttpsTest.java
new file mode 100644
index 0000000000..5c866447d1
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/GitCloneWizardHttpsTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.wizards.clone;
+
+import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
+
+import java.io.File;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.ui.common.RepoPropertiesPage;
+import org.eclipse.egit.ui.common.RepoRemoteBranchesPage;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class GitCloneWizardHttpsTest extends GitCloneWizardTestBase {
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ TestUtil.disableProxy();
+ r = new SampleTestRepository(NUMBER_RANDOM_COMMITS, true, true);
+ }
+
+ @Test
+ public void canCloneARemoteRepo() throws Exception {
+ destRepo = new File(ResourcesPlugin.getWorkspace().getRoot()
+ .getLocation().toFile(), "test" + System.nanoTime());
+
+ importWizard.openWizard();
+ RepoPropertiesPage propertiesPage = importWizard.openRepoPropertiesPage();
+ propertiesPage.setURI(r.getSecureUri());
+ propertiesPage.setUser("agitter");
+ propertiesPage.setPassword("letmein");
+ propertiesPage.setStoreInSecureStore(false);
+ SWTBotShell wizardShell = bot.activeShell();
+
+ RepoRemoteBranchesPage remoteBranches = propertiesPage
+ .nextToRemoteBranches();
+ bot.waitUntil(
+ shellIsActive(UIText.EGitCredentialsProvider_information));
+ // SSL trust dialog
+ bot.checkBox(1).select();
+ bot.button("OK").click();
+ bot.waitUntil(new ActiveShell(wizardShell, "import wizard shell"));
+ cloneRepo(destRepo, remoteBranches);
+ }
+
+ private static class ActiveShell extends DefaultCondition {
+
+ private SWTBotShell shell;
+
+ private String msg;
+
+ private final SWTBot localBot = new SWTBot();
+
+ public ActiveShell(SWTBotShell shell, String msg) {
+ this.shell = shell;
+ this.msg = msg;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "The expected shell did not activate: " + msg;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ try {
+ return localBot.activeShell().widget == shell.widget;
+ } catch (WidgetNotFoundException e) {
+ // Ignore and return false below.
+ }
+ return false;
+ }
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/SampleTestRepository.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/SampleTestRepository.java
index eb7f4c101d..208485527f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/SampleTestRepository.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/clone/SampleTestRepository.java
@@ -71,6 +71,8 @@ public class SampleTestRepository {
private String uri;
+ private String secureUri;
+
private RevBlob A_txt;
private RevCommit A, B, C;
@@ -83,6 +85,10 @@ public class SampleTestRepository {
return uri;
}
+ public String getSecureUri() {
+ return secureUri;
+ }
+
/**
* Create a bare repository, generate some sample data and start git daemon
* on a free port
@@ -90,15 +96,35 @@ public class SampleTestRepository {
* @param n
* hint how many random commits should be generated
* @param serveHttp
+ * whether to serve the repository over HTTP
*
* @throws Exception
*/
public SampleTestRepository(int n, boolean serveHttp) throws Exception {
+ this(n, serveHttp, false);
+ }
+
+ /**
+ * Create a bare repository, generate some sample data and start git daemon
+ * on a free port
+ *
+ * @param n
+ * hint how many random commits should be generated
+ * @param serveHttp
+ * whether to serve the repository over HTTP
+ * @param withSsl
+ * whether to server the repository also over HTTPS if
+ * {@code serveHttp} is {@code true}
+ *
+ * @throws Exception
+ */
+ public SampleTestRepository(int n, boolean serveHttp, boolean withSsl)
+ throws Exception {
this.serveHttp = serveHttp;
src = createRepository();
generateSampleData(n);
if (serveHttp)
- serveHttp();
+ serveHttp(withSsl);
else
serve();
}
@@ -110,7 +136,7 @@ public class SampleTestRepository {
Repository db = new RepositoryBuilder().setGitDir(gitdir).build();
assertFalse(gitdir.exists());
db.create(true);
- return new TestRepository<Repository>(db);
+ return new TestRepository<>(db);
}
private void generateSampleData(int n) throws Exception {
@@ -154,7 +180,7 @@ public class SampleTestRepository {
private void serve() throws IOException {
d = new Daemon();
- FileResolver<DaemonClient> resolver = new FileResolver<DaemonClient>();
+ FileResolver<DaemonClient> resolver = new FileResolver<>();
resolver.exportRepository(REPO_NAME, src.getRepository());
d.setRepositoryResolver(resolver);
d.start();
@@ -162,10 +188,13 @@ public class SampleTestRepository {
+ Constants.DOT_GIT_EXT;
}
- private void serveHttp() throws Exception{
- httpServer = new SimpleHttpServer(src.getRepository());
+ private void serveHttp(boolean withSsl) throws Exception {
+ httpServer = new SimpleHttpServer(src.getRepository(), withSsl);
httpServer.start();
uri = httpServer.getUri().toString();
+ if (withSsl) {
+ secureUri = httpServer.getSecureUri().toString();
+ }
}
/**

Back to the top