Improve proxy link parsing.

This commit is contained in:
Greyson Parrelli
2021-02-03 15:22:38 -05:00
parent 3e2349c4ff
commit 0569d0555f
4 changed files with 123 additions and 35 deletions

View File

@@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static junit.framework.TestCase.assertEquals;
@RunWith(Parameterized.class)
public class SignalProxyUtilText_convertUserEnteredAddressToHost {
private final String input;
private final String output;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{ "https://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "https://signal.tube/#proxy.parker.org:443", "proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org:443", "proxy.parker.org" },
{ "proxy.parker.org", "proxy.parker.org" },
{ "proxy.parker.org:443", "proxy.parker.org" },
{ "x", "x" },
{ "", "" }
});
}
public SignalProxyUtilText_convertUserEnteredAddressToHost(String input, String output) {
this.input = input;
this.output = output;
}
@Test
public void parse() {
assertEquals(output, SignalProxyUtil.convertUserEnteredAddressToHost(input));
}
}

View File

@@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static junit.framework.TestCase.assertEquals;
@RunWith(Parameterized.class)
public class SignalProxyUtilText_generateProxyUrl {
private final String input;
private final String output;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{ "https://signal.tube/#proxy.parker.org", "https://signal.tube/#proxy.parker.org" },
{ "https://signal.tube/#proxy.parker.org:443", "https://signal.tube/#proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org", "https://signal.tube/#proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org:443", "https://signal.tube/#proxy.parker.org" },
{ "proxy.parker.org", "https://signal.tube/#proxy.parker.org" },
{ "proxy.parker.org:443", "https://signal.tube/#proxy.parker.org" },
{ "x", "https://signal.tube/#x" },
{ "", "https://signal.tube/#" }
});
}
public SignalProxyUtilText_generateProxyUrl(String input, String output) {
this.input = input;
this.output = output;
}
@Test
public void parse() {
assertEquals(output, SignalProxyUtil.generateProxyUrl(input));
}
}

View File

@@ -18,16 +18,18 @@ public class SignalProxyUtilText_parseHostFromProxyDeepLink {
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{ "https://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "https://signal.tube/", null },
{ "https://signal.tube/#", null },
{ "sgnl://signal.tube/", null },
{ "sgnl://signal.tube/#", null },
{ "http://signal.tube/#proxy.parker.org", null },
{ "signal.tube/#proxy.parker.org", null },
{ "", null },
{ null, null }
{ "https://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "https://signal.tube/#proxy.parker.org:443", "proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org", "proxy.parker.org" },
{ "sgnl://signal.tube/#proxy.parker.org:443", "proxy.parker.org" },
{ "https://signal.tube/", null },
{ "https://signal.tube/#", null },
{ "sgnl://signal.tube/", null },
{ "sgnl://signal.tube/#", null },
{ "http://signal.tube/#proxy.parker.org", null },
{ "signal.tube/#proxy.parker.org", null },
{ "", null },
{ null, null }
});
}