mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 10:18:59 +03:00
Normalize input URL scheme during auth process
Fixes #8519 Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
parent
9b7163e733
commit
c893834576
3 changed files with 92 additions and 0 deletions
|
@ -771,6 +771,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
accountSetupBinding.hostUrlInput.setText(uri);
|
||||
}
|
||||
|
||||
uri = AuthenticatorUrlUtils.normalizeScheme(uri);
|
||||
|
||||
// Handle internationalized domain names
|
||||
try {
|
||||
uri = DisplayUtils.convertIdn(uri, true);
|
||||
|
|
|
@ -23,6 +23,7 @@ package com.owncloud.android.authentication;
|
|||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -97,4 +98,14 @@ public final class AuthenticatorUrlUtils {
|
|||
|
||||
return strippedUrl;
|
||||
}
|
||||
|
||||
public static String normalizeScheme(String url) {
|
||||
URI uri = URI.create(url);
|
||||
if (uri.getScheme() != null) {
|
||||
String lcScheme = uri.getScheme().toLowerCase(Locale.ROOT);
|
||||
return String.format("%s:%s", lcScheme, uri.getRawSchemeSpecificPart());
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package com.owncloud.android.authentication;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses(AuthenticatorUrlUtilsTest.NormalizeScheme.class)
|
||||
public class AuthenticatorUrlUtilsTest {
|
||||
|
||||
public static class NormalizeScheme {
|
||||
@Test
|
||||
public void noScheme() {
|
||||
// GIVEN
|
||||
// input URL has no scheme
|
||||
String url = "host.net/index.php/apps/ABC/def/?";
|
||||
|
||||
// WHEN
|
||||
// scheme is normalized
|
||||
String normalized = AuthenticatorUrlUtils.normalizeScheme(url);
|
||||
|
||||
// THEN
|
||||
// input is returned unchanged
|
||||
Assert.assertSame(url, normalized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowercaseScheme() {
|
||||
// GIVEN
|
||||
// input URL has scheme
|
||||
// scheme is lowercase
|
||||
String url = "https://host.net/index.php/ABC/def/?";
|
||||
|
||||
// WHEN
|
||||
// scheme is normalized
|
||||
String normalized = AuthenticatorUrlUtils.normalizeScheme(url);
|
||||
|
||||
// THEN
|
||||
// output is equal
|
||||
Assert.assertEquals(url, normalized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercaseScheme() {
|
||||
// GIVEN
|
||||
// input URL has scheme
|
||||
// scheme has uppercase characters
|
||||
String mixedCaseUrl = "HTtps://host.net/index.php/ABC/def/?";
|
||||
|
||||
// WHEN
|
||||
// scheme is normalized
|
||||
String normalized = AuthenticatorUrlUtils.normalizeScheme(mixedCaseUrl);
|
||||
|
||||
// THEN
|
||||
// scheme has been lower-cased
|
||||
// remaining URL part is left unchanged
|
||||
String expectedUrl = "https://host.net/index.php/ABC/def/?";
|
||||
Assert.assertEquals(expectedUrl, normalized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyInput() {
|
||||
// GIVEN
|
||||
// input URL is empty
|
||||
String emptyUrl = "";
|
||||
|
||||
// WHEN
|
||||
// scheme is normalized
|
||||
String normalized = AuthenticatorUrlUtils.normalizeScheme(emptyUrl);
|
||||
|
||||
// THEN
|
||||
// output is empty
|
||||
Assert.assertEquals("", normalized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue