Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 437-add-email
Conflicts: src/main/java/fr/xephi/authme/datasource/MySQL.java src/main/java/fr/xephi/authme/datasource/SQLite.java src/main/java/fr/xephi/authme/process/Management.java src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java
This commit is contained in:
@@ -2,6 +2,7 @@ package fr.xephi.authme.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -135,4 +136,13 @@ public class StringUtilsTest {
|
||||
assertThat(StringUtils.getDifference("test", "bear"), equalTo(0.75));
|
||||
assertThat(StringUtils.getDifference("test", "something"), greaterThan(0.88));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConstructPath() {
|
||||
// given/when
|
||||
String result = StringUtils.makePath("path", "to", "test-file.txt");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLoggerTestInitializer;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
@@ -35,6 +41,7 @@ public class UtilsTest {
|
||||
public static void setUpMocks() {
|
||||
WrapperMock wrapperMock = WrapperMock.createInstance();
|
||||
authMeMock = wrapperMock.getAuthMe();
|
||||
ConsoleLoggerTestInitializer.setupLogger();
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -64,6 +71,10 @@ public class UtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160206: Running this test with all others results in an error
|
||||
// because Utils is used elsewhere. The AuthMe field is set in a static block
|
||||
// so creating the WrapperMock here will have no effect
|
||||
public void shouldNotAddToNormalGroupIfPermManagerIsNull() {
|
||||
// given
|
||||
Settings.isPermissionCheckEnabled = true;
|
||||
@@ -92,8 +103,96 @@ public class UtilsTest {
|
||||
assertThat(players, hasSize(2));
|
||||
}
|
||||
|
||||
// ----------------
|
||||
// Tests for Utils#isEmailCorrect()
|
||||
// ----------------
|
||||
@Test
|
||||
public void shouldAcceptEmailWithEmptyLists() {
|
||||
// given
|
||||
NewSetting settings = mock(NewSetting.class);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.EMPTY_LIST);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.EMPTY_LIST);
|
||||
|
||||
// when
|
||||
boolean result = Utils.isEmailCorrect("test@example.org", settings);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAcceptEmailWithWhitelist() {
|
||||
// given
|
||||
NewSetting settings = mock(NewSetting.class);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST))
|
||||
.willReturn(Arrays.asList("domain.tld", "example.com"));
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.EMPTY_LIST);
|
||||
|
||||
// when
|
||||
boolean result = Utils.isEmailCorrect("TesT@Example.com", settings);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectEmailNotInWhitelist() {
|
||||
// given
|
||||
NewSetting settings = mock(NewSetting.class);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST))
|
||||
.willReturn(Arrays.asList("domain.tld", "example.com"));
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST)).willReturn(Collections.EMPTY_LIST);
|
||||
|
||||
// when
|
||||
boolean result = Utils.isEmailCorrect("email@other-domain.abc", settings);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAcceptEmailNotInBlacklist() {
|
||||
// given
|
||||
NewSetting settings = mock(NewSetting.class);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.EMPTY_LIST);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST))
|
||||
.willReturn(Arrays.asList("Example.org", "a-test-name.tld"));
|
||||
|
||||
// when
|
||||
boolean result = Utils.isEmailCorrect("sample@valid-name.tld", settings);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectEmailInBlacklist() {
|
||||
// given
|
||||
NewSetting settings = mock(NewSetting.class);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_WHITELIST)).willReturn(Collections.EMPTY_LIST);
|
||||
given(settings.getProperty(EmailSettings.DOMAIN_BLACKLIST))
|
||||
.willReturn(Arrays.asList("Example.org", "a-test-name.tld"));
|
||||
|
||||
// when
|
||||
boolean result = Utils.isEmailCorrect("sample@a-Test-name.tld", settings);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidEmail() {
|
||||
// given/when/then
|
||||
assertThat(Utils.isEmailCorrect("invalidinput", mock(NewSetting.class)), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectDefaultEmail() {
|
||||
// given/when/then
|
||||
assertThat(Utils.isEmailCorrect("your@email.com", mock(NewSetting.class)), equalTo(false));
|
||||
}
|
||||
|
||||
// Note: This method is used through reflections
|
||||
@SuppressWarnings("unused")
|
||||
public static Player[] onlinePlayersImpl() {
|
||||
return new Player[]{
|
||||
mock(Player.class), mock(Player.class)
|
||||
|
||||
Reference in New Issue
Block a user