Search in sources :

Example 1 with Md5Crypt

use of games.strategy.util.Md5Crypt in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() {
    final Map<String, String> response = new HashMap<>();
    response.put(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString());
    assertNull(generateChallenge(null).apply(challenge -> response));
    // create a user, verify we can't login with a username that already exists
    // we should not be able to login now
    assertNotNull(generateChallenge(new HashedPassword(md5Crypt("foo"))).apply(challenge -> response));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) HashMap(java.util.HashMap) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Test(org.junit.jupiter.api.Test)

Example 2 with Md5Crypt

use of games.strategy.util.Md5Crypt in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method testAnonymousLoginBadName.

@Test
public void testAnonymousLoginBadName() {
    final String name = "bitCh" + Util.createUniqueTimeStamp();
    try {
        new BadWordController().addBadWord("bitCh");
    } catch (final Exception ignore) {
    // this is probably a duplicate insertion error, we can ignore that as it only means we already added the bad
    // word previously
    }
    assertEquals(LobbyLoginValidator.ErrorMessages.THATS_NOT_A_NICE_NAME, generateChallenge(name, new HashedPassword(md5Crypt("foo"))).apply(challenge -> new HashMap<>(Collections.singletonMap(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString()))));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) HashMap(java.util.HashMap) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Test(org.junit.jupiter.api.Test)

Aggregations

LobbyServer (games.strategy.engine.lobby.server.LobbyServer)2 BadWordController (games.strategy.engine.lobby.server.db.BadWordController)2 HashedPassword (games.strategy.engine.lobby.server.db.HashedPassword)2 UserController (games.strategy.engine.lobby.server.db.UserController)2 RsaAuthenticator.hashPasswordWithSalt (games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt)2 DBUser (games.strategy.engine.lobby.server.userDB.DBUser)2 ILoginValidator (games.strategy.net.ILoginValidator)2 MacFinder (games.strategy.net.MacFinder)2 Integration (games.strategy.test.Integration)2 Md5Crypt (games.strategy.util.Md5Crypt)2 Util (games.strategy.util.Util)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Nullable (javax.annotation.Nullable)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2