Skip to content
Snippets Groups Projects
Commit 15f5e75c authored by cyberta's avatar cyberta Committed by cyberta
Browse files

fix crash when entering invalid invite token

parent 447cfa0c
No related branches found
No related tags found
1 merge request!327fix crash when entering invalid invite token
Pipeline #263422 passed with warnings
......@@ -230,8 +230,19 @@ public class ConfigHelper {
public static boolean isDomainName(String url) {
return url != null && Patterns.DOMAIN_NAME.matcher(url).matches();
}
public static String getDomainFromMainURL(@NonNull String mainUrl) throws NullPointerException {
return PublicSuffixDatabase.Companion.get().getEffectiveTldPlusOne(mainUrl).replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
/**
* Extracts a domain from a given URL
* @param mainUrl URL as String
* @return Domain as String, null if mainUrl is an invalid URL
*/
public static String getDomainFromMainURL(String mainUrl) {
try {
String topLevelDomain = PublicSuffixDatabase.Companion.get().getEffectiveTldPlusOne(mainUrl);
return topLevelDomain.replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
} catch (NullPointerException | IllegalArgumentException e) {
return null;
}
}
public static boolean isCalyxOSWithTetheringSupport(Context context) {
......
......@@ -136,6 +136,9 @@ public abstract class ProviderApiManagerBase {
protected void getPersistedProviderUpdates(Provider provider) {
String providerDomain = getDomainFromMainURL(provider.getMainUrl());
if (providerDomain == null) {
return;
}
if (hasUpdatedProviderDetails(providerDomain)) {
provider.setCaCert(getPersistedProviderCA(providerDomain));
provider.define(getPersistedProviderDefinition(providerDomain));
......@@ -155,8 +158,6 @@ public abstract class ProviderApiManagerBase {
}
}
protected String getPersistedPrivateKey(String providerDomain) {
return getFromPersistedProvider(PROVIDER_PRIVATE_KEY, providerDomain);
}
......
package se.leap.bitmaskclient.base.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.tngtech.java.junit.dataprovider.DataProvider;
......@@ -65,6 +66,14 @@ public class ConfigHelperTest {
assertEquals("domain.co.uk", ConfigHelper.getDomainFromMainURL("https://domain.co.uk"));
}
@Test
public void testGetDomainFromMainURL_returnNullIfInvalid() {
assertNull(ConfigHelper.getDomainFromMainURL("https://localhost"));
assertNull(ConfigHelper.getDomainFromMainURL("http://localhost"));
assertNull(ConfigHelper.getDomainFromMainURL("invalidrandomstring"));
assertNull(ConfigHelper.getDomainFromMainURL(null));
}
@Test
public void testParseX509CertificatesFromString() throws IOException {
ArrayList<X509Certificate> certs = ConfigHelper.parseX509CertificatesFromString(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("updated_cert.pem")));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment