]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/util/TestPasswordMigration.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / tests / org / cacert / gigi / util / TestPasswordMigration.java
1 package org.cacert.gigi.util;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7
8 import org.cacert.gigi.database.GigiPreparedStatement;
9 import org.cacert.gigi.database.GigiResultSet;
10 import org.cacert.gigi.testUtils.ManagedTest;
11 import org.cacert.gigi.testUtils.RegisteredUser;
12 import org.junit.Rule;
13 import org.junit.Test;
14
15 public class TestPasswordMigration extends ManagedTest {
16
17     @Rule
18     public RegisteredUser ru = new RegisteredUser();
19
20     @Test
21     public void testPasswordMigration() throws IOException {
22         try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE users SET `password`=? WHERE id=?")) {
23             stmt.setString(1, PasswordHash.sha1("a"));
24             stmt.setInt(2, ru.getUser().getId());
25             stmt.execute();
26         }
27         String cookie = login(ru.getUser().getEmail(), "a");
28         assertTrue(isLoggedin(cookie));
29
30         try (GigiPreparedStatement stmt = new GigiPreparedStatement("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("$"));
36         }
37     }
38 }