broker/DBAuthenticatorTest: code formatter used
This commit is contained in:
@@ -1,15 +1,14 @@
|
|||||||
|
|
||||||
package io.moquette.spi.impl.security;
|
package io.moquette.spi.impl.security;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Hex;
|
import org.apache.commons.codec.binary.Hex;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ public class DBAuthenticatorTest {
|
|||||||
public static final String SHA_256 = "SHA-256";
|
public static final String SHA_256 = "SHA-256";
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws ClassNotFoundException, SQLException, NoSuchAlgorithmException {
|
public void setup() throws ClassNotFoundException, SQLException, NoSuchAlgorithmException {
|
||||||
Class.forName(ORG_H2_DRIVER);
|
Class.forName(ORG_H2_DRIVER);
|
||||||
@@ -51,28 +49,38 @@ public class DBAuthenticatorTest {
|
|||||||
}
|
}
|
||||||
LOG.info("Table User created");
|
LOG.info("Table User created");
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void Db_verifyValid() {
|
public void Db_verifyValid() {
|
||||||
final DBAuthenticator dbAuthenticator = new DBAuthenticator(ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256);
|
final DBAuthenticator dbAuthenticator = new DBAuthenticator(
|
||||||
|
ORG_H2_DRIVER,
|
||||||
|
JDBC_H2_MEM_TEST,
|
||||||
|
"SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?",
|
||||||
|
SHA_256);
|
||||||
assertTrue(dbAuthenticator.checkValid(null, "dbuser", "password".getBytes()));
|
assertTrue(dbAuthenticator.checkValid(null, "dbuser", "password".getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void Db_verifyInvalidLogin() {
|
public void Db_verifyInvalidLogin() {
|
||||||
final DBAuthenticator dbAuthenticator = new DBAuthenticator(ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256);
|
final DBAuthenticator dbAuthenticator = new DBAuthenticator(
|
||||||
|
ORG_H2_DRIVER,
|
||||||
|
JDBC_H2_MEM_TEST,
|
||||||
|
"SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?",
|
||||||
|
SHA_256);
|
||||||
assertFalse(dbAuthenticator.checkValid(null, "dbuser2", "password".getBytes()));
|
assertFalse(dbAuthenticator.checkValid(null, "dbuser2", "password".getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void Db_verifyInvalidPassword() {
|
public void Db_verifyInvalidPassword() {
|
||||||
final DBAuthenticator dbAuthenticator = new DBAuthenticator(ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256);
|
final DBAuthenticator dbAuthenticator = new DBAuthenticator(
|
||||||
|
ORG_H2_DRIVER,
|
||||||
|
JDBC_H2_MEM_TEST,
|
||||||
|
"SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?",
|
||||||
|
SHA_256);
|
||||||
assertFalse(dbAuthenticator.checkValid(null, "dbuser", "wrongPassword".getBytes()));
|
assertFalse(dbAuthenticator.checkValid(null, "dbuser", "wrongPassword".getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void teardown() {
|
public void teardown() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user