1 package org.cacert.gigi.util;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
8 import org.cacert.gigi.database.DatabaseConnection;
9 import org.cacert.gigi.database.GigiPreparedStatement;
10 import org.cacert.gigi.database.GigiResultSet;
11 import org.cacert.gigi.testUtils.ManagedTest;
12 import org.cacert.gigi.testUtils.RegisteredUser;
13 import org.junit.Rule;
14 import org.junit.Test;
16 public class TestPasswordMigration extends ManagedTest {
19 public RegisteredUser ru = new RegisteredUser();
22 public void testPasswordMigration() throws IOException {
23 GigiPreparedStatement stmt = DatabaseConnection.getInstance().prepare("UPDATE users SET `password`=SHA1(?) WHERE id=?");
24 stmt.setString(1, "a");
25 stmt.setInt(2, ru.getUser().getId());
27 String cookie = login(ru.getUser().getEmail(), "a");
28 assertTrue(isLoggedin(cookie));
30 stmt = DatabaseConnection.getInstance().prepare("SELECT `password` FROM users WHERE id=?");
31 stmt.setInt(1, ru.getUser().getId());
32 GigiResultSet res = stmt.executeQuery();
33 assertTrue(res.next());
34 String newHash = res.getString(1);
35 assertThat(newHash, containsString("$"));