2016-09-20 23:30:59 +03:00
|
|
|
/**
|
|
|
|
* Nextcloud Android client application
|
|
|
|
*
|
|
|
|
* @author Andy Scherzinger
|
|
|
|
* Copyright (C) 2016 Andy Scherzinger
|
|
|
|
* Copyright (C) 2016 Nextcloud
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-08 20:34:39 +03:00
|
|
|
package com.owncloud.android.authentication;
|
|
|
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.junit.runners.BlockJUnit4ClassRunner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests to check the parser logic of the login data URL parser.
|
|
|
|
*/
|
|
|
|
@RunWith(BlockJUnit4ClassRunner.class)
|
|
|
|
public class AuthenticatorDataUrlTest {
|
2016-11-03 17:50:58 +03:00
|
|
|
public static final String URL_PARSING = " url parsing";
|
|
|
|
public static final String INCORRECT_USER_VALUE_IN = "Incorrect user value in ";
|
2016-09-20 23:30:59 +03:00
|
|
|
private String schemeUrl = "nextcloud://login/";
|
|
|
|
private String plus = "&";
|
2016-09-08 20:34:39 +03:00
|
|
|
|
2016-09-20 23:30:59 +03:00
|
|
|
private String userValue = "testuser123";
|
|
|
|
private String userUrlPart = "user:" + userValue;
|
2016-09-08 20:34:39 +03:00
|
|
|
|
2016-09-20 23:30:59 +03:00
|
|
|
private String passwordValue = "testpassword123";
|
|
|
|
private String passwordUrlPart = "password:" + passwordValue;
|
2016-09-08 20:34:39 +03:00
|
|
|
|
2016-09-20 23:30:59 +03:00
|
|
|
private String addressValue = "testserver123";
|
|
|
|
private String addressUrlPart = "server:" + addressValue;
|
2016-09-08 20:34:39 +03:00
|
|
|
|
2016-09-20 23:30:59 +03:00
|
|
|
private String[] urlStarts = new String[]{schemeUrl};
|
2016-09-08 20:34:39 +03:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void allDataUrlElements() {
|
|
|
|
String dataUrl = userUrlPart + plus + passwordUrlPart + plus + addressUrlPart;
|
|
|
|
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
|
|
|
System.out.println(urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, userValue, info.username);
|
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, passwordValue, info.password);
|
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, addressValue, info.serverAddress);
|
2016-09-08 20:34:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void oneElement() {
|
|
|
|
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + userUrlPart);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, userValue,
|
2016-09-08 20:34:39 +03:00
|
|
|
AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + userUrlPart).username);
|
|
|
|
System.out.println(urlStart + passwordUrlPart);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, passwordValue,
|
2016-09-08 20:34:39 +03:00
|
|
|
AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + passwordUrlPart).password);
|
|
|
|
System.out.println(urlStart + addressUrlPart);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + URL_PARSING, addressValue,
|
2016-09-08 20:34:39 +03:00
|
|
|
AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + addressUrlPart).serverAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void twoDataUrlElements() {
|
|
|
|
|
|
|
|
String dataUrl = userUrlPart + plus + passwordUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, userValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.username);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, passwordValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.password);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataUrl = userUrlPart + plus + addressUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, userValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.username);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, addressValue,
|
2016-09-08 20:34:39 +03:00
|
|
|
info.serverAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataUrl = addressUrlPart + plus + userUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, userValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.username);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, addressValue,
|
2016-09-08 20:34:39 +03:00
|
|
|
info.serverAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataUrl = addressUrlPart + plus + passwordUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, passwordValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.password);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, addressValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.serverAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataUrl = passwordUrlPart + plus + userUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, userValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.username);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, passwordValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.password);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataUrl = passwordUrlPart + plus + addressUrlPart;
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
LoginUrlInfo info = AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, passwordValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.password);
|
2016-11-03 17:50:58 +03:00
|
|
|
Assert.assertEquals(INCORRECT_USER_VALUE_IN + urlStart + dataUrl + URL_PARSING, addressValue, info
|
2016-09-08 20:34:39 +03:00
|
|
|
.serverAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void tooManyDataUrlElements() {
|
|
|
|
String dataUrl = userUrlPart + plus + passwordUrlPart + plus + addressUrlPart + plus + "notexist:boom";
|
|
|
|
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
try {
|
|
|
|
System.out.println(urlStart + dataUrl);
|
|
|
|
AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart + dataUrl);
|
|
|
|
Assert.fail("Illegal Argument Exception expected!");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// all well
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void tooLittleDataUrlElements() {
|
|
|
|
for (String urlStart : urlStarts) {
|
|
|
|
try {
|
|
|
|
System.out.println(urlStart);
|
|
|
|
AuthenticatorActivity.parseLoginDataUrl(urlStart, urlStart);
|
|
|
|
Assert.fail("Illegal Argument Exception expected!");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// all well
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|