mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-04-15 08:26:03 +02:00
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="ArrayTypeStyle"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="DefaultComesLast"/>
|
||||
<module name="FallThrough"/>
|
||||
<module name="NestedTryDepth"/>
|
||||
<module name="UpperEll"/>
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="RedundantModifier"/>
|
||||
@ -111,9 +113,11 @@
|
||||
<property name="ignoreFinal" value="false"/>
|
||||
<property name="allowedAbbreviationLength" value="1"/>
|
||||
</module>
|
||||
<module name="DeclarationOrder"/>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
<module name="VariableDeclarationUsageDistance"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="StringLiteralEquality"/>
|
||||
<module name="BooleanExpressionComplexity">
|
||||
<property name="max" value="5"/>
|
||||
</module>
|
||||
@ -145,9 +149,21 @@
|
||||
<property name="scope" value="package"/>
|
||||
<property name="allowMissingThrowsTags" value="true"/>
|
||||
<property name="minLineCount" value="4"/>
|
||||
<property name="allowedAnnotations" value="Override, Test, SectionComments"/>
|
||||
<property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/>
|
||||
<property name="allowedAnnotations" value="Override, Test, SectionComments, EventHandler"/>
|
||||
<property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/> <!-- exclude CTOR_DEF -->
|
||||
</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">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||
<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/OAuth2SaslClientFactory.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/WHIRLPOOL.java'
|
||||
- 'src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.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/Wordpress.java'
|
||||
|
@ -127,7 +127,8 @@ public class NewAPI {
|
||||
public Location getLastLocation(Player player) {
|
||||
PlayerAuth auth = playerCache.getAuth(player.getName());
|
||||
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;
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ public class CommandInitializer {
|
||||
return commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the command description objects for all available AuthMe commands.
|
||||
*/
|
||||
@SuppressWarnings({"checkstyle:LocalVariableName", "checkstyle:AbbreviationAsWordInName"})
|
||||
private void buildCommands() {
|
||||
// Register the base AuthMe Reloaded command
|
||||
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
||||
|
@ -31,12 +31,12 @@ public class VersionCommand implements ExecutableCommand {
|
||||
printDeveloper(sender, "games647", "games647", "Developer", onlinePlayers);
|
||||
printDeveloper(sender, "Tim Visee", "timvisee", "Developer", onlinePlayers);
|
||||
printDeveloper(sender, "Gabriele C.", "sgdc3", "Project manager, Contributor", onlinePlayers);
|
||||
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
|
||||
"http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE
|
||||
+ "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
|
||||
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
||||
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.data.auth.PlayerAuth;
|
||||
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.HtmlEmail;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -22,7 +22,7 @@ class TestEmailSender implements DebugSection {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private SendMailSSL sendMailSSL;
|
||||
private SendMailSsl sendMailSsl;
|
||||
|
||||
@Inject
|
||||
private Server server;
|
||||
@ -40,7 +40,7 @@ class TestEmailSender implements DebugSection {
|
||||
|
||||
@Override
|
||||
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 "
|
||||
+ "for sending emails. Please check your config.yml");
|
||||
return;
|
||||
@ -87,7 +87,7 @@ class TestEmailSender implements DebugSection {
|
||||
private boolean sendTestEmail(String email) {
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = sendMailSSL.initializeMail(email);
|
||||
htmlEmail = sendMailSsl.initializeMail(email);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email for sample email:", e);
|
||||
return false;
|
||||
@ -96,6 +96,6 @@ class TestEmailSender implements DebugSection {
|
||||
htmlEmail.setSubject("AuthMe test email");
|
||||
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.";
|
||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
||||
return sendMailSsl.sendEmail(message, htmlEmail);
|
||||
}
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ public class HelpMessagesService implements Reloadable {
|
||||
|
||||
public String getMessage(DefaultPermission defaultPermission) {
|
||||
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
|
||||
String path = DEFAULT_PERMISSIONS_PATH +
|
||||
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
String path = DEFAULT_PERMISSIONS_PATH
|
||||
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
return messageFileHandler.getMessage(path);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import java.util.Set;
|
||||
|
||||
public class MySQL implements DataSource {
|
||||
|
||||
private boolean useSSL;
|
||||
private boolean useSsl;
|
||||
private String host;
|
||||
private String port;
|
||||
private String username;
|
||||
@ -45,10 +45,10 @@ public class MySQL implements DataSource {
|
||||
private HikariDataSource ds;
|
||||
|
||||
private String phpBbPrefix;
|
||||
private String IPBPrefix;
|
||||
private String ipbPrefix;
|
||||
private int phpBbGroup;
|
||||
private int IPBGroup;
|
||||
private int XFGroup;
|
||||
private int ipbGroup;
|
||||
private int xfGroup;
|
||||
private String wordpressPrefix;
|
||||
|
||||
public MySQL(Settings settings) throws ClassNotFoundException, SQLException {
|
||||
@ -99,15 +99,15 @@ public class MySQL implements DataSource {
|
||||
this.hashAlgorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
|
||||
this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX);
|
||||
this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID);
|
||||
this.IPBPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
|
||||
this.IPBGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
|
||||
this.XFGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
|
||||
this.ipbPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
|
||||
this.ipbGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
|
||||
this.xfGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
|
||||
this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX);
|
||||
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
||||
if (poolSize == -1) {
|
||||
poolSize = Utils.getCoreCount()*3;
|
||||
}
|
||||
this.useSSL = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
||||
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
||||
}
|
||||
|
||||
private void setConnectionArguments() {
|
||||
@ -125,7 +125,7 @@ public class MySQL implements DataSource {
|
||||
ds.setPassword(this.password);
|
||||
|
||||
// Request mysql over SSL
|
||||
ds.addDataSourceProperty("useSSL", useSSL);
|
||||
ds.addDataSourceProperty("useSSL", useSsl);
|
||||
|
||||
// Encoding
|
||||
ds.addDataSourceProperty("characterEncoding", "utf8");
|
||||
@ -347,23 +347,23 @@ public class MySQL implements DataSource {
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()){
|
||||
// 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.setInt(1, IPBGroup);
|
||||
pst2.setInt(1, ipbGroup);
|
||||
pst2.setString(2, auth.getNickname());
|
||||
pst2.executeUpdate();
|
||||
pst2.close();
|
||||
// Get current time without ms
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
// 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.setLong(1, time);
|
||||
pst2.setString(2, auth.getNickname());
|
||||
pst2.executeUpdate();
|
||||
pst2.close();
|
||||
// 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.setLong(1, time);
|
||||
pst2.setString(2, auth.getNickname());
|
||||
@ -531,14 +531,14 @@ public class MySQL implements DataSource {
|
||||
// Update player group in xf_users
|
||||
sql = "UPDATE " + tableName + " SET "+ tableName + ".user_group_id=? WHERE " + col.NAME + "=?;";
|
||||
pst2 = con.prepareStatement(sql);
|
||||
pst2.setInt(1, XFGroup);
|
||||
pst2.setInt(1, xfGroup);
|
||||
pst2.setString(2, auth.getNickname());
|
||||
pst2.executeUpdate();
|
||||
pst2.close();
|
||||
// Update player permission combination in xf_users
|
||||
sql = "UPDATE " + tableName + " SET "+ tableName + ".permission_combination_id=? WHERE " + col.NAME + "=?;";
|
||||
pst2 = con.prepareStatement(sql);
|
||||
pst2.setInt(1, XFGroup);
|
||||
pst2.setInt(1, xfGroup);
|
||||
pst2.setString(2, auth.getNickname());
|
||||
pst2.executeUpdate();
|
||||
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 (?,?,?)";
|
||||
pst2 = con.prepareStatement(sql);
|
||||
pst2.setInt(1, id);
|
||||
pst2.setInt(2, XFGroup);
|
||||
pst2.setInt(2, xfGroup);
|
||||
pst2.setString(3, "1");
|
||||
pst2.executeUpdate();
|
||||
pst2.close();
|
||||
|
@ -46,7 +46,7 @@ public class RakamakConverter implements Converter {
|
||||
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
|
||||
File source = new File(pluginFolder, fileName);
|
||||
File ipFiles = new File(pluginFolder, ipFileName);
|
||||
Map<String, String> playerIP = new HashMap<>();
|
||||
Map<String, String> playerIp = new HashMap<>();
|
||||
Map<String, HashedPassword> playerPassword = new HashMap<>();
|
||||
try {
|
||||
BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
|
||||
@ -56,7 +56,7 @@ public class RakamakConverter implements Converter {
|
||||
while ((tempLine = ipFile.readLine()) != null) {
|
||||
if (tempLine.contains("=")) {
|
||||
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()) {
|
||||
String playerName = m.getKey();
|
||||
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()
|
||||
.name(playerName)
|
||||
.realName(playerName)
|
||||
|
@ -25,18 +25,18 @@ public class EmailService {
|
||||
private final File dataFolder;
|
||||
private final String serverName;
|
||||
private final Settings settings;
|
||||
private final SendMailSSL sendMailSSL;
|
||||
private final SendMailSsl sendMailSsl;
|
||||
|
||||
@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.serverName = server.getServerName();
|
||||
this.settings = settings;
|
||||
this.sendMailSSL = sendMailSSL;
|
||||
this.sendMailSsl = sendMailSsl;
|
||||
}
|
||||
|
||||
public boolean hasAllInformation() {
|
||||
return sendMailSSL.hasAllInformation();
|
||||
return sendMailSsl.hasAllInformation();
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ public class EmailService {
|
||||
|
||||
HtmlEmail email;
|
||||
try {
|
||||
email = sendMailSSL.initializeMail(mailAddress);
|
||||
email = sendMailSsl.initializeMail(mailAddress);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
||||
return false;
|
||||
@ -75,7 +75,7 @@ public class EmailService {
|
||||
}
|
||||
}
|
||||
|
||||
boolean couldSendEmail = sendMailSSL.sendEmail(mailText, email);
|
||||
boolean couldSendEmail = sendMailSsl.sendEmail(mailText, email);
|
||||
FileUtils.delete(file);
|
||||
return couldSendEmail;
|
||||
}
|
||||
@ -83,7 +83,7 @@ public class EmailService {
|
||||
public boolean sendRecoveryCode(String name, String email, String code) {
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = sendMailSSL.initializeMail(email);
|
||||
htmlEmail = sendMailSsl.initializeMail(email);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email for recovery code:", e);
|
||||
return false;
|
||||
@ -91,7 +91,7 @@ public class EmailService {
|
||||
|
||||
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(),
|
||||
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 {
|
||||
|
@ -24,7 +24,7 @@ import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||
/**
|
||||
* Sends emails to players on behalf of the server.
|
||||
*/
|
||||
public class SendMailSSL {
|
||||
public class SendMailSsl {
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
@ -67,7 +67,7 @@ public class SendMailSSL {
|
||||
}
|
||||
|
||||
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
|
||||
// cf. http://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
|
||||
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
|
@ -79,8 +79,8 @@ public class AuthGroupHandler implements Reloadable {
|
||||
throw new IllegalStateException("Encountered unhandled auth group type '" + groupType + "'");
|
||||
}
|
||||
|
||||
ConsoleLogger.debug(
|
||||
() -> player.getName() + " changed to " + groupType + ": has groups " + permissionsManager.getGroups(player));
|
||||
ConsoleLogger.debug(() -> player.getName() + " changed to "
|
||||
+ groupType + ": has groups " + permissionsManager.getGroups(player));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ public class PermissionsManager implements Reloadable {
|
||||
// Loop through all the available permissions system types
|
||||
for (PermissionsSystemType type : PermissionsSystemType.values()) {
|
||||
try {
|
||||
PermissionHandler handler = getPermissionHandler(type);
|
||||
PermissionHandler handler = createPermissionHandler(type);
|
||||
if (handler != null) {
|
||||
// Show a success message and return
|
||||
this.handler = handler;
|
||||
@ -91,7 +91,14 @@ public class PermissionsManager implements Reloadable {
|
||||
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
|
||||
Plugin plugin = pluginManager.getPlugin(type.getPluginName());
|
||||
|
||||
|
@ -17,7 +17,7 @@ public interface PermissionHandler {
|
||||
* @param group The name of the group.
|
||||
*
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
boolean addToGroup(Player player, String group);
|
||||
|
||||
@ -47,7 +47,7 @@ public interface PermissionHandler {
|
||||
* @param group The group name.
|
||||
*
|
||||
* @return True if the player is in the specified group, false otherwise.
|
||||
* False is also returned if groups aren't supported by the used permissions system.
|
||||
* False is also returned if groups aren't supported by the used permissions system.
|
||||
*/
|
||||
default boolean isInGroup(Player player, String group) {
|
||||
return getGroups(player).contains(group);
|
||||
@ -60,7 +60,7 @@ public interface PermissionHandler {
|
||||
* @param group The name of the group.
|
||||
*
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
boolean removeFromGroup(Player player, String group);
|
||||
|
||||
@ -72,7 +72,7 @@ public interface PermissionHandler {
|
||||
* @param group The name of the group.
|
||||
*
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
boolean setGroup(Player player, String group);
|
||||
|
||||
|
@ -96,6 +96,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
* Checks the precondition for authentication (like user known) and returns
|
||||
* 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
|
||||
* (e.g. because he is already logged in)
|
||||
*/
|
||||
|
@ -17,6 +17,8 @@ import javax.inject.Inject;
|
||||
/**
|
||||
* Registration executor for registration methods where the password
|
||||
* is supplied by the user.
|
||||
*
|
||||
* @param <P> the parameters type
|
||||
*/
|
||||
abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegisterParams>
|
||||
implements RegistrationExecutor<P> {
|
||||
|
@ -4,6 +4,8 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
|
||||
/**
|
||||
* Performs the registration action.
|
||||
*
|
||||
* @param <P> the registration parameters type
|
||||
*/
|
||||
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>
|
||||
* as passing a constant of this class along with a parameters object to a method can
|
||||
* be restricted to the correct parameters type.
|
||||
*
|
||||
* @param <P> the registration parameters type the method uses
|
||||
*/
|
||||
public final class RegistrationMethod<P extends RegistrationParameters> {
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class BukkitService implements SettingsDependent {
|
||||
@Inject
|
||||
BukkitService(AuthMe authMe, Settings settings) {
|
||||
this.authMe = authMe;
|
||||
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
|
||||
getOnlinePlayersIsCollection = doesOnlinePlayersMethodReturnCollection();
|
||||
reload(settings);
|
||||
}
|
||||
|
||||
@ -301,11 +301,12 @@ public class BukkitService implements SettingsDependent {
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
private static boolean initializeOnlinePlayersIsCollectionField() {
|
||||
private static boolean doesOnlinePlayersMethodReturnCollection() {
|
||||
try {
|
||||
Method method = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
||||
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.
|
||||
*
|
||||
* @param <E> the enum type
|
||||
*/
|
||||
public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
||||
|
||||
|
@ -7,6 +7,8 @@ import java.util.concurrent.TimeUnit;
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* @param <K> the type of the key
|
||||
*/
|
||||
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.getValue() <= 0) {
|
||||
remove(key);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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 java.util.Arrays.asList;
|
||||
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.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.command.executable.authme.debug;
|
||||
|
||||
import fr.xephi.authme.ClassCollector;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -22,8 +23,8 @@ public class DebugSectionConsistencyTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void collectClasses() {
|
||||
debugClasses = new ClassCollector("src/main/java", "fr/xephi/authme/command/executable/authme/debug")
|
||||
.collectClasses();
|
||||
debugClasses = new ClassCollector(
|
||||
TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "command/executable/authme/debug").collectClasses();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -48,7 +48,7 @@ public class EmailServiceTest {
|
||||
@Mock
|
||||
private Server server;
|
||||
@Mock
|
||||
private SendMailSSL sendMailSSL;
|
||||
private SendMailSsl sendMailSsl;
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
|
||||
@ -66,7 +66,7 @@ public class EmailServiceTest {
|
||||
given(server.getServerName()).willReturn("serverName");
|
||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("mail@example.org");
|
||||
given(settings.getProperty(EmailSettings.MAIL_PASSWORD)).willReturn("pass1234");
|
||||
given(sendMailSSL.hasAllInformation()).willReturn(true);
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -82,17 +82,17 @@ public class EmailServiceTest {
|
||||
.willReturn("Hi <playername />, your new password for <servername /> is <generatedpass />");
|
||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSSL.sendEmail(anyString(), eq(email))).willReturn(true);
|
||||
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSsl.sendEmail(anyString(), eq(email))).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(sendMailSSL).initializeMail("user@example.com");
|
||||
verify(sendMailSsl).initializeMail("user@example.com");
|
||||
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 Player, your new password for serverName is new_password"));
|
||||
}
|
||||
@ -100,15 +100,15 @@ public class EmailServiceTest {
|
||||
@Test
|
||||
public void shouldHandleMailCreationError() throws EmailException {
|
||||
// given
|
||||
doThrow(EmailException.class).when(sendMailSSL).initializeMail(anyString());
|
||||
doThrow(EmailException.class).when(sendMailSsl).initializeMail(anyString());
|
||||
|
||||
// when
|
||||
boolean result = emailService.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSSL).initializeMail("user@example.com");
|
||||
verify(sendMailSSL, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
verify(sendMailSsl).initializeMail("user@example.com");
|
||||
verify(sendMailSsl, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -117,17 +117,17 @@ public class EmailServiceTest {
|
||||
given(settings.getPasswordEmailMessage()).willReturn("Hi <playername />, your new pass is <generatedpass />");
|
||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||
|
||||
// when
|
||||
boolean result = emailService.sendPasswordMail("bobby", "user@example.com", "myPassw0rd");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSSL).initializeMail("user@example.com");
|
||||
verify(sendMailSsl).initializeMail("user@example.com");
|
||||
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"));
|
||||
}
|
||||
|
||||
@ -138,32 +138,32 @@ public class EmailServiceTest {
|
||||
given(settings.getRecoveryCodeEmailMessage())
|
||||
.willReturn("Hi <playername />, your code on <servername /> is <recoverycode /> (valid <hoursvalid /> hours)");
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(true);
|
||||
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = emailService.sendRecoveryCode("Timmy", "tim@example.com", "12C56A");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(sendMailSSL).initializeMail("tim@example.com");
|
||||
verify(sendMailSsl).initializeMail("tim@example.com");
|
||||
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)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMailCreationErrorForRecoveryCode() throws EmailException {
|
||||
// given
|
||||
given(sendMailSSL.initializeMail(anyString())).willThrow(EmailException.class);
|
||||
given(sendMailSsl.initializeMail(anyString())).willThrow(EmailException.class);
|
||||
|
||||
// when
|
||||
boolean result = emailService.sendRecoveryCode("Player", "player@example.org", "ABC1234");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSSL).initializeMail("player@example.org");
|
||||
verify(sendMailSSL, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
verify(sendMailSsl).initializeMail("player@example.org");
|
||||
verify(sendMailSsl, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -173,17 +173,17 @@ public class EmailServiceTest {
|
||||
given(settings.getRecoveryCodeEmailMessage()).willReturn("Hi <playername />, your code is <recoverycode />");
|
||||
EmailService sendMailSpy = spy(emailService);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
given(sendMailSSL.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSSL.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||
given(sendMailSsl.initializeMail(anyString())).willReturn(email);
|
||||
given(sendMailSsl.sendEmail(anyString(), any(HtmlEmail.class))).willReturn(false);
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendRecoveryCode("John", "user@example.com", "1DEF77");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSSL).initializeMail("user@example.com");
|
||||
verify(sendMailSsl).initializeMail("user@example.com");
|
||||
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"));
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,13 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Test for {@link SendMailSSL}.
|
||||
* Test for {@link SendMailSsl}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class SendMailSSLTest {
|
||||
public class SendMailSslTest {
|
||||
|
||||
@InjectDelayed
|
||||
private SendMailSSL sendMailSSL;
|
||||
private SendMailSsl sendMailSsl;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@ -57,7 +57,7 @@ public class SendMailSSLTest {
|
||||
@Test
|
||||
public void shouldHaveAllInformation() {
|
||||
// given / when / then
|
||||
assertThat(sendMailSSL.hasAllInformation(), equalTo(true));
|
||||
assertThat(sendMailSsl.hasAllInformation(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -73,7 +73,7 @@ public class SendMailSSLTest {
|
||||
given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(LogLevel.DEBUG);
|
||||
|
||||
// when
|
||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
||||
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||
|
||||
// then
|
||||
assertThat(email, not(nullValue()));
|
||||
@ -99,7 +99,7 @@ public class SendMailSSLTest {
|
||||
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
|
||||
|
||||
// when
|
||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
||||
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||
|
||||
// then
|
||||
assertThat(email, not(nullValue()));
|
||||
@ -122,7 +122,7 @@ public class SendMailSSLTest {
|
||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
|
||||
|
||||
// when
|
||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
||||
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
|
||||
|
||||
// then
|
||||
assertThat(email, not(nullValue()));
|
@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import fr.xephi.authme.ClassCollector;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
@ -126,7 +127,7 @@ public class SettingsConsistencyTest {
|
||||
private List<Method> getSectionCommentMethods() {
|
||||
// Find all SettingsHolder classes
|
||||
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);
|
||||
checkArgument(!settingsClasses.isEmpty(), "Could not find any SettingsHolder classes");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user