Update checkstyle config and CodeClimate exclusions
- Add new checkstyle checks: require Javadoc on large private methods, default in switch, declaration order & others - Update path exclusions in CodeClimate config to match newly renamed classes (e.g. PHPBB -> PhpBB) - Create consistency check testing that excluded paths exist as classes - Fix some trivial violations
This commit is contained in:
parent
e77828b228
commit
32a664ef59
@ -55,7 +55,9 @@
|
|||||||
<module name="MultipleVariableDeclarations"/>
|
<module name="MultipleVariableDeclarations"/>
|
||||||
<module name="ArrayTypeStyle"/>
|
<module name="ArrayTypeStyle"/>
|
||||||
<module name="MissingSwitchDefault"/>
|
<module name="MissingSwitchDefault"/>
|
||||||
|
<module name="DefaultComesLast"/>
|
||||||
<module name="FallThrough"/>
|
<module name="FallThrough"/>
|
||||||
|
<module name="NestedTryDepth"/>
|
||||||
<module name="UpperEll"/>
|
<module name="UpperEll"/>
|
||||||
<module name="ModifierOrder"/>
|
<module name="ModifierOrder"/>
|
||||||
<module name="RedundantModifier"/>
|
<module name="RedundantModifier"/>
|
||||||
@ -111,9 +113,11 @@
|
|||||||
<property name="ignoreFinal" value="false"/>
|
<property name="ignoreFinal" value="false"/>
|
||||||
<property name="allowedAbbreviationLength" value="1"/>
|
<property name="allowedAbbreviationLength" value="1"/>
|
||||||
</module>
|
</module>
|
||||||
|
<module name="DeclarationOrder"/>
|
||||||
<module name="OverloadMethodsDeclarationOrder"/>
|
<module name="OverloadMethodsDeclarationOrder"/>
|
||||||
<module name="VariableDeclarationUsageDistance"/>
|
<module name="VariableDeclarationUsageDistance"/>
|
||||||
<module name="MethodParamPad"/>
|
<module name="MethodParamPad"/>
|
||||||
|
<module name="StringLiteralEquality"/>
|
||||||
<module name="BooleanExpressionComplexity">
|
<module name="BooleanExpressionComplexity">
|
||||||
<property name="max" value="5"/>
|
<property name="max" value="5"/>
|
||||||
</module>
|
</module>
|
||||||
@ -145,9 +149,21 @@
|
|||||||
<property name="scope" value="package"/>
|
<property name="scope" value="package"/>
|
||||||
<property name="allowMissingThrowsTags" value="true"/>
|
<property name="allowMissingThrowsTags" value="true"/>
|
||||||
<property name="minLineCount" value="4"/>
|
<property name="minLineCount" value="4"/>
|
||||||
<property name="allowedAnnotations" value="Override, Test, SectionComments"/>
|
<property name="allowedAnnotations" value="Override, Test, SectionComments, EventHandler"/>
|
||||||
<property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/>
|
<property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/> <!-- exclude CTOR_DEF -->
|
||||||
</module>
|
</module>
|
||||||
|
<module name="JavadocMethod">
|
||||||
|
<property name="scope" value="private"/>
|
||||||
|
<property name="allowMissingThrowsTags" value="true"/>
|
||||||
|
<property name="minLineCount" value="16"/>
|
||||||
|
<property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/> <!-- exclude CTOR_DEF -->
|
||||||
|
</module>
|
||||||
|
<!-- TODO Checkstyle/#4089: need "allowedAnnotations" property to skip @Comment fields
|
||||||
|
<module name="JavadocVariable">
|
||||||
|
<property name="scope" value="package"/>
|
||||||
|
<property name="tokens" value="VARIABLE_DEF"/>
|
||||||
|
</module>
|
||||||
|
-->
|
||||||
<module name="MethodName">
|
<module name="MethodName">
|
||||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||||
<message key="name.invalidPattern"
|
<message key="name.invalidPattern"
|
||||||
|
|||||||
@ -25,6 +25,6 @@ exclude_paths:
|
|||||||
- 'src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java'
|
- 'src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java'
|
||||||
- 'src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java'
|
- 'src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java'
|
||||||
- 'src/main/java/fr/xephi/authme/security/crypts/BCryptService.java'
|
- 'src/main/java/fr/xephi/authme/security/crypts/BCryptService.java'
|
||||||
- 'src/main/java/fr/xephi/authme/security/crypts/PHPBB.java'
|
- 'src/main/java/fr/xephi/authme/security/crypts/PhpBB.java'
|
||||||
- 'src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java'
|
- 'src/main/java/fr/xephi/authme/security/crypts/Whirlpool.java'
|
||||||
- 'src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java'
|
- 'src/main/java/fr/xephi/authme/security/crypts/Wordpress.java'
|
||||||
|
|||||||
@ -127,7 +127,8 @@ public class NewAPI {
|
|||||||
public Location getLastLocation(Player player) {
|
public Location getLastLocation(Player player) {
|
||||||
PlayerAuth auth = playerCache.getAuth(player.getName());
|
PlayerAuth auth = playerCache.getAuth(player.getName());
|
||||||
if (auth != null) {
|
if (auth != null) {
|
||||||
return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
return new Location(Bukkit.getWorld(auth.getWorld()),
|
||||||
|
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,6 +66,10 @@ public class CommandInitializer {
|
|||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the command description objects for all available AuthMe commands.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"checkstyle:LocalVariableName", "checkstyle:AbbreviationAsWordInName"})
|
||||||
private void buildCommands() {
|
private void buildCommands() {
|
||||||
// Register the base AuthMe Reloaded command
|
// Register the base AuthMe Reloaded command
|
||||||
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
||||||
|
|||||||
@ -31,12 +31,12 @@ public class VersionCommand implements ExecutableCommand {
|
|||||||
printDeveloper(sender, "games647", "games647", "Developer", onlinePlayers);
|
printDeveloper(sender, "games647", "games647", "Developer", onlinePlayers);
|
||||||
printDeveloper(sender, "Tim Visee", "timvisee", "Developer", onlinePlayers);
|
printDeveloper(sender, "Tim Visee", "timvisee", "Developer", onlinePlayers);
|
||||||
printDeveloper(sender, "Gabriele C.", "sgdc3", "Project manager, Contributor", onlinePlayers);
|
printDeveloper(sender, "Gabriele C.", "sgdc3", "Project manager, Contributor", onlinePlayers);
|
||||||
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
|
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE
|
||||||
"http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
+ "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||||
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
|
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
|
||||||
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
||||||
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE
|
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE
|
||||||
+ "Copyright (c) AuthMe-Team 2016. All rights reserved.");
|
+ "Copyright (c) AuthMe-Team 2017. All rights reserved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme.debug;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.mail.SendMailSSL;
|
import fr.xephi.authme.mail.SendMailSsl;
|
||||||
import org.apache.commons.mail.EmailException;
|
import org.apache.commons.mail.EmailException;
|
||||||
import org.apache.commons.mail.HtmlEmail;
|
import org.apache.commons.mail.HtmlEmail;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -22,7 +22,7 @@ class TestEmailSender implements DebugSection {
|
|||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SendMailSSL sendMailSSL;
|
private SendMailSsl sendMailSsl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Server server;
|
private Server server;
|
||||||
@ -40,7 +40,7 @@ class TestEmailSender implements DebugSection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, List<String> arguments) {
|
public void execute(CommandSender sender, List<String> arguments) {
|
||||||
if (!sendMailSSL.hasAllInformation()) {
|
if (!sendMailSsl.hasAllInformation()) {
|
||||||
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml "
|
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml "
|
||||||
+ "for sending emails. Please check your config.yml");
|
+ "for sending emails. Please check your config.yml");
|
||||||
return;
|
return;
|
||||||
@ -87,7 +87,7 @@ class TestEmailSender implements DebugSection {
|
|||||||
private boolean sendTestEmail(String email) {
|
private boolean sendTestEmail(String email) {
|
||||||
HtmlEmail htmlEmail;
|
HtmlEmail htmlEmail;
|
||||||
try {
|
try {
|
||||||
htmlEmail = sendMailSSL.initializeMail(email);
|
htmlEmail = sendMailSsl.initializeMail(email);
|
||||||
} catch (EmailException e) {
|
} catch (EmailException e) {
|
||||||
ConsoleLogger.logException("Failed to create email for sample email:", e);
|
ConsoleLogger.logException("Failed to create email for sample email:", e);
|
||||||
return false;
|
return false;
|
||||||
@ -96,6 +96,6 @@ class TestEmailSender implements DebugSection {
|
|||||||
htmlEmail.setSubject("AuthMe test email");
|
htmlEmail.setSubject("AuthMe test email");
|
||||||
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server ("
|
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server ("
|
||||||
+ server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
|
+ server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
|
||||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
return sendMailSsl.sendEmail(message, htmlEmail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,8 +81,8 @@ public class HelpMessagesService implements Reloadable {
|
|||||||
|
|
||||||
public String getMessage(DefaultPermission defaultPermission) {
|
public String getMessage(DefaultPermission defaultPermission) {
|
||||||
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
|
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
|
||||||
String path = DEFAULT_PERMISSIONS_PATH +
|
String path = DEFAULT_PERMISSIONS_PATH
|
||||||
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||||
return messageFileHandler.getMessage(path);
|
return messageFileHandler.getMessage(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class MySQL implements DataSource {
|
public class MySQL implements DataSource {
|
||||||
|
|
||||||
private boolean useSSL;
|
private boolean useSsl;
|
||||||
private String host;
|
private String host;
|
||||||
private String port;
|
private String port;
|
||||||
private String username;
|
private String username;
|
||||||
@ -45,10 +45,10 @@ public class MySQL implements DataSource {
|
|||||||
private HikariDataSource ds;
|
private HikariDataSource ds;
|
||||||
|
|
||||||
private String phpBbPrefix;
|
private String phpBbPrefix;
|
||||||
private String IPBPrefix;
|
private String ipbPrefix;
|
||||||
private int phpBbGroup;
|
private int phpBbGroup;
|
||||||
private int IPBGroup;
|
private int ipbGroup;
|
||||||
private int XFGroup;
|
private int xfGroup;
|
||||||
private String wordpressPrefix;
|
private String wordpressPrefix;
|
||||||
|
|
||||||
public MySQL(Settings settings) throws ClassNotFoundException, SQLException {
|
public MySQL(Settings settings) throws ClassNotFoundException, SQLException {
|
||||||
@ -99,15 +99,15 @@ public class MySQL implements DataSource {
|
|||||||
this.hashAlgorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
|
this.hashAlgorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
|
||||||
this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX);
|
this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX);
|
||||||
this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID);
|
this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID);
|
||||||
this.IPBPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
|
this.ipbPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
|
||||||
this.IPBGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
|
this.ipbGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
|
||||||
this.XFGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
|
this.xfGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
|
||||||
this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX);
|
this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX);
|
||||||
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
||||||
if (poolSize == -1) {
|
if (poolSize == -1) {
|
||||||
poolSize = Utils.getCoreCount()*3;
|
poolSize = Utils.getCoreCount()*3;
|
||||||
}
|
}
|
||||||
this.useSSL = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setConnectionArguments() {
|
private void setConnectionArguments() {
|
||||||
@ -125,7 +125,7 @@ public class MySQL implements DataSource {
|
|||||||
ds.setPassword(this.password);
|
ds.setPassword(this.password);
|
||||||
|
|
||||||
// Request mysql over SSL
|
// Request mysql over SSL
|
||||||
ds.addDataSourceProperty("useSSL", useSSL);
|
ds.addDataSourceProperty("useSSL", useSsl);
|
||||||
|
|
||||||
// Encoding
|
// Encoding
|
||||||
ds.addDataSourceProperty("characterEncoding", "utf8");
|
ds.addDataSourceProperty("characterEncoding", "utf8");
|
||||||
@ -347,23 +347,23 @@ public class MySQL implements DataSource {
|
|||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
if (rs.next()){
|
if (rs.next()){
|
||||||
// Update player group in core_members
|
// Update player group in core_members
|
||||||
sql = "UPDATE " + IPBPrefix + tableName + " SET "+ tableName + ".member_group_id=? WHERE " + col.NAME + "=?;";
|
sql = "UPDATE " + ipbPrefix + tableName + " SET "+ tableName + ".member_group_id=? WHERE " + col.NAME + "=?;";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setInt(1, IPBGroup);
|
pst2.setInt(1, ipbGroup);
|
||||||
pst2.setString(2, auth.getNickname());
|
pst2.setString(2, auth.getNickname());
|
||||||
pst2.executeUpdate();
|
pst2.executeUpdate();
|
||||||
pst2.close();
|
pst2.close();
|
||||||
// Get current time without ms
|
// Get current time without ms
|
||||||
long time = System.currentTimeMillis() / 1000;
|
long time = System.currentTimeMillis() / 1000;
|
||||||
// update joined date
|
// update joined date
|
||||||
sql = "UPDATE " + IPBPrefix + tableName + " SET "+ tableName + ".joined=? WHERE " + col.NAME + "=?;";
|
sql = "UPDATE " + ipbPrefix + tableName + " SET "+ tableName + ".joined=? WHERE " + col.NAME + "=?;";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setLong(1, time);
|
pst2.setLong(1, time);
|
||||||
pst2.setString(2, auth.getNickname());
|
pst2.setString(2, auth.getNickname());
|
||||||
pst2.executeUpdate();
|
pst2.executeUpdate();
|
||||||
pst2.close();
|
pst2.close();
|
||||||
// Update last_visit
|
// Update last_visit
|
||||||
sql = "UPDATE " + IPBPrefix + tableName + " SET " + tableName + ".last_visit=? WHERE " + col.NAME + "=?;";
|
sql = "UPDATE " + ipbPrefix + tableName + " SET " + tableName + ".last_visit=? WHERE " + col.NAME + "=?;";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setLong(1, time);
|
pst2.setLong(1, time);
|
||||||
pst2.setString(2, auth.getNickname());
|
pst2.setString(2, auth.getNickname());
|
||||||
@ -531,14 +531,14 @@ public class MySQL implements DataSource {
|
|||||||
// Update player group in xf_users
|
// Update player group in xf_users
|
||||||
sql = "UPDATE " + tableName + " SET "+ tableName + ".user_group_id=? WHERE " + col.NAME + "=?;";
|
sql = "UPDATE " + tableName + " SET "+ tableName + ".user_group_id=? WHERE " + col.NAME + "=?;";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setInt(1, XFGroup);
|
pst2.setInt(1, xfGroup);
|
||||||
pst2.setString(2, auth.getNickname());
|
pst2.setString(2, auth.getNickname());
|
||||||
pst2.executeUpdate();
|
pst2.executeUpdate();
|
||||||
pst2.close();
|
pst2.close();
|
||||||
// Update player permission combination in xf_users
|
// Update player permission combination in xf_users
|
||||||
sql = "UPDATE " + tableName + " SET "+ tableName + ".permission_combination_id=? WHERE " + col.NAME + "=?;";
|
sql = "UPDATE " + tableName + " SET "+ tableName + ".permission_combination_id=? WHERE " + col.NAME + "=?;";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setInt(1, XFGroup);
|
pst2.setInt(1, xfGroup);
|
||||||
pst2.setString(2, auth.getNickname());
|
pst2.setString(2, auth.getNickname());
|
||||||
pst2.executeUpdate();
|
pst2.executeUpdate();
|
||||||
pst2.close();
|
pst2.close();
|
||||||
@ -557,7 +557,7 @@ public class MySQL implements DataSource {
|
|||||||
sql = "INSERT INTO xf_user_group_relation (user_id, user_group_id, is_primary) VALUES (?,?,?)";
|
sql = "INSERT INTO xf_user_group_relation (user_id, user_group_id, is_primary) VALUES (?,?,?)";
|
||||||
pst2 = con.prepareStatement(sql);
|
pst2 = con.prepareStatement(sql);
|
||||||
pst2.setInt(1, id);
|
pst2.setInt(1, id);
|
||||||
pst2.setInt(2, XFGroup);
|
pst2.setInt(2, xfGroup);
|
||||||
pst2.setString(3, "1");
|
pst2.setString(3, "1");
|
||||||
pst2.executeUpdate();
|
pst2.executeUpdate();
|
||||||
pst2.close();
|
pst2.close();
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class RakamakConverter implements Converter {
|
|||||||
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
|
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
|
||||||
File source = new File(pluginFolder, fileName);
|
File source = new File(pluginFolder, fileName);
|
||||||
File ipFiles = new File(pluginFolder, ipFileName);
|
File ipFiles = new File(pluginFolder, ipFileName);
|
||||||
Map<String, String> playerIP = new HashMap<>();
|
Map<String, String> playerIp = new HashMap<>();
|
||||||
Map<String, HashedPassword> playerPassword = new HashMap<>();
|
Map<String, HashedPassword> playerPassword = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
|
BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
|
||||||
@ -56,7 +56,7 @@ public class RakamakConverter implements Converter {
|
|||||||
while ((tempLine = ipFile.readLine()) != null) {
|
while ((tempLine = ipFile.readLine()) != null) {
|
||||||
if (tempLine.contains("=")) {
|
if (tempLine.contains("=")) {
|
||||||
String[] args = tempLine.split("=");
|
String[] args = tempLine.split("=");
|
||||||
playerIP.put(args[0], args[1]);
|
playerIp.put(args[0], args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ public class RakamakConverter implements Converter {
|
|||||||
for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
|
for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
|
||||||
String playerName = m.getKey();
|
String playerName = m.getKey();
|
||||||
HashedPassword psw = playerPassword.get(playerName);
|
HashedPassword psw = playerPassword.get(playerName);
|
||||||
String ip = useIp ? playerIP.get(playerName) : "127.0.0.1";
|
String ip = useIp ? playerIp.get(playerName) : "127.0.0.1";
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(playerName)
|
.name(playerName)
|
||||||
.realName(playerName)
|
.realName(playerName)
|
||||||
|
|||||||
@ -25,18 +25,18 @@ public class EmailService {
|
|||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
private final String serverName;
|
private final String serverName;
|
||||||
private final Settings settings;
|
private final Settings settings;
|
||||||
private final SendMailSSL sendMailSSL;
|
private final SendMailSsl sendMailSsl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EmailService(@DataFolder File dataFolder, Server server, Settings settings, SendMailSSL sendMailSSL) {
|
EmailService(@DataFolder File dataFolder, Server server, Settings settings, SendMailSsl sendMailSsl) {
|
||||||
this.dataFolder = dataFolder;
|
this.dataFolder = dataFolder;
|
||||||
this.serverName = server.getServerName();
|
this.serverName = server.getServerName();
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.sendMailSSL = sendMailSSL;
|
this.sendMailSsl = sendMailSsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAllInformation() {
|
public boolean hasAllInformation() {
|
||||||
return sendMailSSL.hasAllInformation();
|
return sendMailSsl.hasAllInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class EmailService {
|
|||||||
|
|
||||||
HtmlEmail email;
|
HtmlEmail email;
|
||||||
try {
|
try {
|
||||||
email = sendMailSSL.initializeMail(mailAddress);
|
email = sendMailSsl.initializeMail(mailAddress);
|
||||||
} catch (EmailException e) {
|
} catch (EmailException e) {
|
||||||
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
||||||
return false;
|
return false;
|
||||||
@ -75,7 +75,7 @@ public class EmailService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean couldSendEmail = sendMailSSL.sendEmail(mailText, email);
|
boolean couldSendEmail = sendMailSsl.sendEmail(mailText, email);
|
||||||
FileUtils.delete(file);
|
FileUtils.delete(file);
|
||||||
return couldSendEmail;
|
return couldSendEmail;
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ public class EmailService {
|
|||||||
public boolean sendRecoveryCode(String name, String email, String code) {
|
public boolean sendRecoveryCode(String name, String email, String code) {
|
||||||
HtmlEmail htmlEmail;
|
HtmlEmail htmlEmail;
|
||||||
try {
|
try {
|
||||||
htmlEmail = sendMailSSL.initializeMail(email);
|
htmlEmail = sendMailSsl.initializeMail(email);
|
||||||
} catch (EmailException e) {
|
} catch (EmailException e) {
|
||||||
ConsoleLogger.logException("Failed to create email for recovery code:", e);
|
ConsoleLogger.logException("Failed to create email for recovery code:", e);
|
||||||
return false;
|
return false;
|
||||||
@ -91,7 +91,7 @@ public class EmailService {
|
|||||||
|
|
||||||
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(),
|
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(),
|
||||||
name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID));
|
name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID));
|
||||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
return sendMailSsl.sendEmail(message, htmlEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File generateImage(String name, String newPass) throws IOException {
|
private File generateImage(String name, String newPass) throws IOException {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
|||||||
/**
|
/**
|
||||||
* Sends emails to players on behalf of the server.
|
* Sends emails to players on behalf of the server.
|
||||||
*/
|
*/
|
||||||
public class SendMailSSL {
|
public class SendMailSsl {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
@ -67,7 +67,7 @@ public class SendMailSSL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendEmail(String content, HtmlEmail email) {
|
public boolean sendEmail(String content, HtmlEmail email) {
|
||||||
Thread.currentThread().setContextClassLoader(SendMailSSL.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(SendMailSsl.class.getClassLoader());
|
||||||
// Issue #999: Prevent UnsupportedDataTypeException: no object DCH for MIME type multipart/alternative
|
// Issue #999: Prevent UnsupportedDataTypeException: no object DCH for MIME type multipart/alternative
|
||||||
// cf. http://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
|
// cf. http://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
|
||||||
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
|
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
|
||||||
@ -79,8 +79,8 @@ public class AuthGroupHandler implements Reloadable {
|
|||||||
throw new IllegalStateException("Encountered unhandled auth group type '" + groupType + "'");
|
throw new IllegalStateException("Encountered unhandled auth group type '" + groupType + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleLogger.debug(
|
ConsoleLogger.debug(() -> player.getName() + " changed to "
|
||||||
() -> player.getName() + " changed to " + groupType + ": has groups " + permissionsManager.getGroups(player));
|
+ groupType + ": has groups " + permissionsManager.getGroups(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
// Loop through all the available permissions system types
|
// Loop through all the available permissions system types
|
||||||
for (PermissionsSystemType type : PermissionsSystemType.values()) {
|
for (PermissionsSystemType type : PermissionsSystemType.values()) {
|
||||||
try {
|
try {
|
||||||
PermissionHandler handler = getPermissionHandler(type);
|
PermissionHandler handler = createPermissionHandler(type);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
// Show a success message and return
|
// Show a success message and return
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@ -91,7 +91,14 @@ public class PermissionsManager implements Reloadable {
|
|||||||
ConsoleLogger.info("No supported permissions system found! Permissions are disabled!");
|
ConsoleLogger.info("No supported permissions system found! Permissions are disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private PermissionHandler getPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
|
/**
|
||||||
|
* Creates a permission handler for the provided permission systems if possible.
|
||||||
|
*
|
||||||
|
* @param type the permission systems type for which to create a corresponding permission handler
|
||||||
|
* @return the permission handler, or {@code null} if not possible
|
||||||
|
* @throws PermissionHandlerException during initialization of the permission handler
|
||||||
|
*/
|
||||||
|
private PermissionHandler createPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
|
||||||
// Try to find the plugin for the current permissions system
|
// Try to find the plugin for the current permissions system
|
||||||
Plugin plugin = pluginManager.getPlugin(type.getPluginName());
|
Plugin plugin = pluginManager.getPlugin(type.getPluginName());
|
||||||
|
|
||||||
|
|||||||
@ -96,6 +96,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
* Checks the precondition for authentication (like user known) and returns
|
* Checks the precondition for authentication (like user known) and returns
|
||||||
* the player's {@link PlayerAuth} object.
|
* the player's {@link PlayerAuth} object.
|
||||||
*
|
*
|
||||||
|
* @param player the player to check
|
||||||
* @return the PlayerAuth object, or {@code null} if the player doesn't exist or may not log in
|
* @return the PlayerAuth object, or {@code null} if the player doesn't exist or may not log in
|
||||||
* (e.g. because he is already logged in)
|
* (e.g. because he is already logged in)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -17,6 +17,8 @@ import javax.inject.Inject;
|
|||||||
/**
|
/**
|
||||||
* Registration executor for registration methods where the password
|
* Registration executor for registration methods where the password
|
||||||
* is supplied by the user.
|
* is supplied by the user.
|
||||||
|
*
|
||||||
|
* @param <P> the parameters type
|
||||||
*/
|
*/
|
||||||
abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegisterParams>
|
abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegisterParams>
|
||||||
implements RegistrationExecutor<P> {
|
implements RegistrationExecutor<P> {
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the registration action.
|
* Performs the registration action.
|
||||||
|
*
|
||||||
|
* @param <P> the registration parameters type
|
||||||
*/
|
*/
|
||||||
public interface RegistrationExecutor<P extends RegistrationParameters> {
|
public interface RegistrationExecutor<P extends RegistrationParameters> {
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ package fr.xephi.authme.process.register.executors;
|
|||||||
* classes which perform this registration method. This is essentially a <i>typed enum</i>
|
* classes which perform this registration method. This is essentially a <i>typed enum</i>
|
||||||
* as passing a constant of this class along with a parameters object to a method can
|
* as passing a constant of this class along with a parameters object to a method can
|
||||||
* be restricted to the correct parameters type.
|
* be restricted to the correct parameters type.
|
||||||
|
*
|
||||||
|
* @param <P> the registration parameters type the method uses
|
||||||
*/
|
*/
|
||||||
public final class RegistrationMethod<P extends RegistrationParameters> {
|
public final class RegistrationMethod<P extends RegistrationParameters> {
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public class BukkitService implements SettingsDependent {
|
|||||||
@Inject
|
@Inject
|
||||||
BukkitService(AuthMe authMe, Settings settings) {
|
BukkitService(AuthMe authMe, Settings settings) {
|
||||||
this.authMe = authMe;
|
this.authMe = authMe;
|
||||||
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
|
getOnlinePlayersIsCollection = doesOnlinePlayersMethodReturnCollection();
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,11 +301,12 @@ public class BukkitService implements SettingsDependent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method run upon initialization to verify whether or not the Bukkit implementation
|
* Method run upon initialization to verify whether or not the Bukkit implementation
|
||||||
* returns the online players as a Collection.
|
* returns the online players as a {@link Collection}.
|
||||||
*
|
*
|
||||||
|
* @return true if a collection is returned by the bukkit implementation, false otherwise
|
||||||
* @see #getOnlinePlayers()
|
* @see #getOnlinePlayers()
|
||||||
*/
|
*/
|
||||||
private static boolean initializeOnlinePlayersIsCollectionField() {
|
private static boolean doesOnlinePlayersMethodReturnCollection() {
|
||||||
try {
|
try {
|
||||||
Method method = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
Method method = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
||||||
return method.getReturnType() == Collection.class;
|
return method.getReturnType() == Collection.class;
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import static com.google.common.collect.Sets.newHashSet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Property whose value is a set of entries of a given enum.
|
* Property whose value is a set of entries of a given enum.
|
||||||
|
*
|
||||||
|
* @param <E> the enum type
|
||||||
*/
|
*/
|
||||||
public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* <p>
|
* <p>
|
||||||
* Once the expiration of an entry has been reached, the counter resets
|
* Once the expiration of an entry has been reached, the counter resets
|
||||||
* to 0. The counter returns 0 rather than {@code null} for any given key.
|
* to 0. The counter returns 0 rather than {@code null} for any given key.
|
||||||
|
*
|
||||||
|
* @param <K> the type of the key
|
||||||
*/
|
*/
|
||||||
public class TimedCounter<K> extends ExpiringMap<K, Integer> {
|
public class TimedCounter<K> extends ExpiringMap<K, Integer> {
|
||||||
|
|
||||||
@ -47,8 +49,7 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
|
|||||||
if (e != null) {
|
if (e != null) {
|
||||||
if (e.getValue() <= 0) {
|
if (e.getValue() <= 0) {
|
||||||
remove(key);
|
remove(key);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
entries.put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
|
entries.put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/test/java/fr/xephi/authme/CodeClimateConfigTest.java
Normal file
51
src/test/java/fr/xephi/authme/CodeClimateConfigTest.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consistency test for the CodeClimate configuration file.
|
||||||
|
*/
|
||||||
|
public class CodeClimateConfigTest {
|
||||||
|
|
||||||
|
private static final String CONFIG_FILE = ".codeclimate.yml";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHaveExistingClassesInExclusions() {
|
||||||
|
// given
|
||||||
|
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File(CONFIG_FILE));
|
||||||
|
List<String> excludePaths = configuration.getStringList("exclude_paths");
|
||||||
|
|
||||||
|
// when / then
|
||||||
|
assertThat(excludePaths, not(empty()));
|
||||||
|
for (String path : excludePaths) {
|
||||||
|
String className = convertPathToQualifiedClassName(path);
|
||||||
|
assertThat("No class corresponds to excluded path '" + path + "'",
|
||||||
|
Utils.isClassLoaded(className), equalTo(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String convertPathToQualifiedClassName(String path) {
|
||||||
|
// Note ljacqu 20170323: In the future, we could have legitimate exclusions that don't fulfill these checks,
|
||||||
|
// in which case this test needs to be adapted accordingly.
|
||||||
|
if (!path.startsWith(TestHelper.SOURCES_FOLDER)) {
|
||||||
|
throw new IllegalArgumentException("Unexpected path '" + path + "': expected to start with sources folder");
|
||||||
|
} else if (!path.endsWith(".java")) {
|
||||||
|
throw new IllegalArgumentException("Expected path '" + path + "' to end with '.java'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.substring(0, path.length() - ".java".length()) // strip ending .java
|
||||||
|
.substring(TestHelper.SOURCES_FOLDER.length()) // strip starting src/main/java
|
||||||
|
.replace('/', '.'); // replace '/' to '.'
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,7 +26,7 @@ import static fr.xephi.authme.command.help.HelpProvider.SHOW_COMMAND;
|
|||||||
import static fr.xephi.authme.command.help.HelpProvider.SHOW_DESCRIPTION;
|
import static fr.xephi.authme.command.help.HelpProvider.SHOW_DESCRIPTION;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fr.xephi.authme.command.executable.authme.debug;
|
package fr.xephi.authme.command.executable.authme.debug;
|
||||||
|
|
||||||
import fr.xephi.authme.ClassCollector;
|
import fr.xephi.authme.ClassCollector;
|
||||||
|
import fr.xephi.authme.TestHelper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -22,8 +23,8 @@ public class DebugSectionConsistencyTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void collectClasses() {
|
public static void collectClasses() {
|
||||||
debugClasses = new ClassCollector("src/main/java", "fr/xephi/authme/command/executable/authme/debug")
|
debugClasses = new ClassCollector(
|
||||||
.collectClasses();
|
TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "command/executable/authme/debug").collectClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class EmailServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Server server;
|
private Server server;
|
||||||
@Mock
|
@Mock
|
||||||
private SendMailSSL sendMailSSL;
|
private SendMailSsl sendMailSsl;
|
||||||
@DataFolder
|
@DataFolder
|
||||||
private File dataFolder;
|
private File dataFolder;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class EmailServiceTest {
|
|||||||
given(server.getServerName()).willReturn("serverName");
|
given(server.getServerName()).willReturn("serverName");
|
||||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("mail@example.org");
|
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("mail@example.org");
|
||||||
given(settings.getProperty(EmailSettings.MAIL_PASSWORD)).willReturn("pass1234");
|
given(settings.getProperty(EmailSettings.MAIL_PASSWORD)).willReturn("pass1234");
|
||||||
given(sendMailSSL.hasAllInformation()).willReturn(true);
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -82,17 +82,17 @@ public class EmailServiceTest {
|
|||||||
.willReturn("Hi <playername />, your new password for <servername /> is <generatedpass />");
|
.willReturn("Hi <playername />, your new password for <servername /> is <generatedpass />");
|
||||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||||
HtmlEmail email = mock(HtmlEmail.class);
|
HtmlEmail email = mock(HtmlEmail.class);
|
||||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||||
given(sendMailSSL.sendEmail(anyString(), eq(email))).willReturn(true);
|
given(sendMailSsl.sendEmail(anyString(), eq(email))).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(true));
|
assertThat(result, equalTo(true));
|
||||||
verify(sendMailSSL).initializeMail("user@example.com");
|
verify(sendMailSsl).initializeMail("user@example.com");
|
||||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(sendMailSSL).sendEmail(messageCaptor.capture(), eq(email));
|
verify(sendMailSsl).sendEmail(messageCaptor.capture(), eq(email));
|
||||||
assertThat(messageCaptor.getValue(),
|
assertThat(messageCaptor.getValue(),
|
||||||
equalTo("Hi Player, your new password for serverName is new_password"));
|
equalTo("Hi Player, your new password for serverName is new_password"));
|
||||||
}
|
}
|
||||||
@ -100,15 +100,15 @@ public class EmailServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHandleMailCreationError() throws EmailException {
|
public void shouldHandleMailCreationError() throws EmailException {
|
||||||
// given
|
// given
|
||||||
doThrow(EmailException.class).when(sendMailSSL).initializeMail(anyString());
|
doThrow(EmailException.class).when(sendMailSsl).initializeMail(anyString());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
verify(sendMailSSL).initializeMail("user@example.com");
|
verify(sendMailSsl).initializeMail("user@example.com");
|
||||||
verify(sendMailSSL, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
verify(sendMailSsl, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -117,17 +117,17 @@ public class EmailServiceTest {
|
|||||||
given(settings.getPasswordEmailMessage()).willReturn("Hi <playername />, your new pass is <generatedpass />");
|
given(settings.getPasswordEmailMessage()).willReturn("Hi <playername />, your new pass is <generatedpass />");
|
||||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||||
HtmlEmail email = mock(HtmlEmail.class);
|
HtmlEmail email = mock(HtmlEmail.class);
|
||||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = emailService.sendPasswordMail("bobby", "user@example.com", "myPassw0rd");
|
boolean result = emailService.sendPasswordMail("bobby", "user@example.com", "myPassw0rd");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
verify(sendMailSSL).initializeMail("user@example.com");
|
verify(sendMailSsl).initializeMail("user@example.com");
|
||||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(sendMailSSL).sendEmail(messageCaptor.capture(), eq(email));
|
verify(sendMailSsl).sendEmail(messageCaptor.capture(), eq(email));
|
||||||
assertThat(messageCaptor.getValue(), equalTo("Hi bobby, your new pass is myPassw0rd"));
|
assertThat(messageCaptor.getValue(), equalTo("Hi bobby, your new pass is myPassw0rd"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,32 +138,32 @@ public class EmailServiceTest {
|
|||||||
given(settings.getRecoveryCodeEmailMessage())
|
given(settings.getRecoveryCodeEmailMessage())
|
||||||
.willReturn("Hi <playername />, your code on <servername /> is <recoverycode /> (valid <hoursvalid /> hours)");
|
.willReturn("Hi <playername />, your code on <servername /> is <recoverycode /> (valid <hoursvalid /> hours)");
|
||||||
HtmlEmail email = mock(HtmlEmail.class);
|
HtmlEmail email = mock(HtmlEmail.class);
|
||||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(true);
|
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = emailService.sendRecoveryCode("Timmy", "tim@example.com", "12C56A");
|
boolean result = emailService.sendRecoveryCode("Timmy", "tim@example.com", "12C56A");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(true));
|
assertThat(result, equalTo(true));
|
||||||
verify(sendMailSSL).initializeMail("tim@example.com");
|
verify(sendMailSsl).initializeMail("tim@example.com");
|
||||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(sendMailSSL).sendEmail(messageCaptor.capture(), eq(email));
|
verify(sendMailSsl).sendEmail(messageCaptor.capture(), eq(email));
|
||||||
assertThat(messageCaptor.getValue(), equalTo("Hi Timmy, your code on serverName is 12C56A (valid 7 hours)"));
|
assertThat(messageCaptor.getValue(), equalTo("Hi Timmy, your code on serverName is 12C56A (valid 7 hours)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleMailCreationErrorForRecoveryCode() throws EmailException {
|
public void shouldHandleMailCreationErrorForRecoveryCode() throws EmailException {
|
||||||
// given
|
// given
|
||||||
given(sendMailSSL.initializeMail(anyString())).willThrow(EmailException.class);
|
given(sendMailSsl.initializeMail(anyString())).willThrow(EmailException.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = emailService.sendRecoveryCode("Player", "player@example.org", "ABC1234");
|
boolean result = emailService.sendRecoveryCode("Player", "player@example.org", "ABC1234");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
verify(sendMailSSL).initializeMail("player@example.org");
|
verify(sendMailSsl).initializeMail("player@example.org");
|
||||||
verify(sendMailSSL, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
verify(sendMailSsl, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -173,17 +173,17 @@ public class EmailServiceTest {
|
|||||||
given(settings.getRecoveryCodeEmailMessage()).willReturn("Hi <playername />, your code is <recoverycode />");
|
given(settings.getRecoveryCodeEmailMessage()).willReturn("Hi <playername />, your code is <recoverycode />");
|
||||||
EmailService sendMailSpy = spy(emailService);
|
EmailService sendMailSpy = spy(emailService);
|
||||||
HtmlEmail email = mock(HtmlEmail.class);
|
HtmlEmail email = mock(HtmlEmail.class);
|
||||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = sendMailSpy.sendRecoveryCode("John", "user@example.com", "1DEF77");
|
boolean result = sendMailSpy.sendRecoveryCode("John", "user@example.com", "1DEF77");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
verify(sendMailSSL).initializeMail("user@example.com");
|
verify(sendMailSsl).initializeMail("user@example.com");
|
||||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(sendMailSSL).sendEmail(messageCaptor.capture(), eq(email));
|
verify(sendMailSsl).sendEmail(messageCaptor.capture(), eq(email));
|
||||||
assertThat(messageCaptor.getValue(), equalTo("Hi John, your code is 1DEF77"));
|
assertThat(messageCaptor.getValue(), equalTo("Hi John, your code is 1DEF77"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,13 @@ import static org.junit.Assert.assertThat;
|
|||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link SendMailSSL}.
|
* Test for {@link SendMailSsl}.
|
||||||
*/
|
*/
|
||||||
@RunWith(DelayedInjectionRunner.class)
|
@RunWith(DelayedInjectionRunner.class)
|
||||||
public class SendMailSSLTest {
|
public class SendMailSslTest {
|
||||||
|
|
||||||
@InjectDelayed
|
@InjectDelayed
|
||||||
private SendMailSSL sendMailSSL;
|
private SendMailSsl sendMailSsl;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
@ -57,7 +57,7 @@ public class SendMailSSLTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveAllInformation() {
|
public void shouldHaveAllInformation() {
|
||||||
// given / when / then
|
// given / when / then
|
||||||
assertThat(sendMailSSL.hasAllInformation(), equalTo(true));
|
assertThat(sendMailSsl.hasAllInformation(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -73,7 +73,7 @@ public class SendMailSSLTest {
|
|||||||
given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(LogLevel.DEBUG);
|
given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(LogLevel.DEBUG);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(email, not(nullValue()));
|
assertThat(email, not(nullValue()));
|
||||||
@ -99,7 +99,7 @@ public class SendMailSSLTest {
|
|||||||
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
|
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(email, not(nullValue()));
|
assertThat(email, not(nullValue()));
|
||||||
@ -122,7 +122,7 @@ public class SendMailSSLTest {
|
|||||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
|
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(email, not(nullValue()));
|
assertThat(email, not(nullValue()));
|
||||||
@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableSetMultimap;
|
|||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import fr.xephi.authme.ClassCollector;
|
import fr.xephi.authme.ClassCollector;
|
||||||
import fr.xephi.authme.ReflectionTestUtils;
|
import fr.xephi.authme.ReflectionTestUtils;
|
||||||
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.datasource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
@ -126,7 +127,7 @@ public class SettingsConsistencyTest {
|
|||||||
private List<Method> getSectionCommentMethods() {
|
private List<Method> getSectionCommentMethods() {
|
||||||
// Find all SettingsHolder classes
|
// Find all SettingsHolder classes
|
||||||
List<Class<? extends SettingsHolder>> settingsClasses =
|
List<Class<? extends SettingsHolder>> settingsClasses =
|
||||||
new ClassCollector("src/main/java", "fr/xephi/authme/settings/properties/")
|
new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "settings/properties/")
|
||||||
.collectClasses(SettingsHolder.class);
|
.collectClasses(SettingsHolder.class);
|
||||||
checkArgument(!settingsClasses.isEmpty(), "Could not find any SettingsHolder classes");
|
checkArgument(!settingsClasses.isEmpty(), "Could not find any SettingsHolder classes");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user