summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2019-10-30 19:20:30 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2019-10-30 19:20:30 -0400
commitb29e9bd1cb252577c1b8118861830cffcf15fd27 (patch)
tree092decdc663d1915d170f96f2020c4b0ef5c378e /org.eclipse.jgit.test
parent7c75a68b9635848a8231df8a1461c3f9405a55f4 (diff)
parentb7d1eb4185aa35f037790580b60c1f2d76968fa8 (diff)
downloadjgit-b29e9bd1cb252577c1b8118861830cffcf15fd27.tar.gz
jgit-b29e9bd1cb252577c1b8118861830cffcf15fd27.zip
Merge "HttpSupport.proxyFor(): use only scheme, host, and port"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HttpSupportTest.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HttpSupportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HttpSupportTest.java
new file mode 100644
index 0000000000..cbe4eb2eb0
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HttpSupportTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019, Thomas Wolf <thomas.wolf@paranor.ch> and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+public class HttpSupportTest {
+
+ private static class TestProxySelector extends ProxySelector {
+
+ private static final Proxy DUMMY = new Proxy(Proxy.Type.HTTP,
+ InetSocketAddress.createUnresolved("localhost", 0));
+
+ @Override
+ public List<Proxy> select(URI uri) {
+ if ("http".equals(uri.getScheme())
+ && "somehost".equals(uri.getHost())) {
+ return Collections.singletonList(DUMMY);
+ }
+ return Collections.singletonList(Proxy.NO_PROXY);
+ }
+
+ @Override
+ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+ // Empty
+ }
+ }
+
+ @Test
+ public void testMalformedUri() throws Exception {
+ // Valid URL, but backslash is not allowed in a URI in the userinfo part
+ // per RFC 3986: https://tools.ietf.org/html/rfc3986#section-3.2.1 .
+ // Test that conversion to URI to call the ProxySelector does not throw
+ // an exception.
+ Proxy proxy = HttpSupport.proxyFor(new TestProxySelector(), new URL(
+ "http://infor\\c.jones@somehost/somewhere/someproject.git"));
+ assertNotNull(proxy);
+ assertEquals(Proxy.Type.HTTP, proxy.type());
+ }
+
+ @Test
+ public void testCorrectUri() throws Exception {
+ // Backslash escaped as %5C is correct.
+ Proxy proxy = HttpSupport.proxyFor(new TestProxySelector(), new URL(
+ "http://infor%5Cc.jones@somehost/somewhere/someproject.git"));
+ assertNotNull(proxy);
+ assertEquals(Proxy.Type.HTTP, proxy.type());
+ }
+}