X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Futil%2FTestNotary.java;h=22f75b2362789c0f84c92d5608343c483ab50806;hb=d7be034f96e06985f57d86d2779c434276b5bd4d;hp=2f99840d5fa9a3eef76b91f441849db482af7335;hpb=ac859aa8ebfc991dcc3233ce57f23c46ec6df033;p=gigi.git diff --git a/tests/org/cacert/gigi/util/TestNotary.java b/tests/org/cacert/gigi/util/TestNotary.java index 2f99840d..22f75b23 100644 --- a/tests/org/cacert/gigi/util/TestNotary.java +++ b/tests/org/cacert/gigi/util/TestNotary.java @@ -1,34 +1,42 @@ package org.cacert.gigi.util; -import java.sql.PreparedStatement; +import static org.junit.Assert.*; + +import java.io.IOException; import java.sql.SQLException; import java.util.Date; import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.database.GigiPreparedStatement; +import org.cacert.gigi.dbObjects.Assurance.AssuranceType; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.output.DateSelector; import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; -import static org.junit.Assert.*; - public class TestNotary extends ManagedTest { + // These tests create a lot of users and therefore require resetting of the + // registering-rate-limit. @Test public void testNormalAssurance() throws SQLException, GigiApiException { + try { + clearCaches(); + } catch (IOException e) { + throw new Error(e); + } User[] users = new User[30]; for (int i = 0; i < users.length; i++) { int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD); - users[i] = new User(id); + users[i] = User.getById(id); } - User assurer = new User(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD)); + User assurer = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD)); int[] result = new int[] { 10, 10, 10, 10, 15, 15, 15, 15, 15, 20, 20, 20, 20, 20, 25, 25, 25, 25, 25, 30, 30, 30, 30, 30, 35, 35, 35, 35, 35, 35 }; try { - Notary.assure(assurer, users[0], -1, "test-notary", "2014-01-01"); + Notary.assure(assurer, users[0], users[0].getName(), users[0].getDoB(), -1, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE); fail("This shouldn't have passed"); } catch (GigiApiException e) { // expected @@ -37,7 +45,7 @@ public class TestNotary extends ManagedTest { assertEquals(result[i], assurer.getMaxAssurePoints()); assuranceFail(assurer, users[i], result[i] + 1, "test-notary", "2014-01-01"); - Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"); + Notary.assure(assurer, users[i], users[i].getName(), users[i].getDoB(), result[i], "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE); assuranceFail(assurer, users[i], result[i], "test-notary", "2014-01-01"); } @@ -49,7 +57,7 @@ public class TestNotary extends ManagedTest { private void assuranceFail(User assurer, User user, int i, String location, String date) throws SQLException { try { - Notary.assure(assurer, user, i, location, date); + Notary.assure(assurer, user, user.getName(), user.getDoB(), i, location, date, AssuranceType.FACE_TO_FACE); fail("This shouldn't have passed"); } catch (GigiApiException e) { // expected @@ -58,28 +66,36 @@ public class TestNotary extends ManagedTest { @Test public void testPoJam() throws SQLException, GigiApiException { + try { + clearCaches(); + } catch (IOException e) { + throw new Error(e); + } User[] users = new User[30]; for (int i = 0; i < users.length; i++) { int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD); - users[i] = new User(id); + users[i] = User.getById(id); } int id = createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD); - PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET dob=NOW() WHERE id=?"); - ps.setInt(1, id); - ps.execute(); - User assurer = new User(id); + try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `users` SET dob=NOW() - interval '15 years' WHERE id=?")) { + ps.setInt(1, id); + ps.execute(); + } + User assurer = User.getById(id); for (int i = 0; i < users.length; i++) { assuranceFail(assurer, users[i], -1, "test-notary", "2014-01-01"); assuranceFail(assurer, users[i], 11, "test-notary", "2014-01-01"); - Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"); + if (User.POJAM_ENABLED) { + Notary.assure(assurer, users[i], users[i].getName(), users[i].getDoB(), 10, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE); + } assuranceFail(assurer, users[i], 10, "test-notary", "2014-01-01"); } } @Test public void testFail() throws SQLException, GigiApiException { - User assuranceUser = new User(createAssuranceUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD)); - User assuree = new User(createVerifiedUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD)); + User assuranceUser = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD)); + User assuree = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD)); // invalid date format assuranceFail(assuranceUser, assuree, 10, "notary-junit-test", "2014-01-blah"); @@ -106,7 +122,7 @@ public class TestNotary extends ManagedTest { assuranceFail(assuree, assuranceUser, 10, "notary-junit-test", "2014-01-01"); // valid - Notary.assure(assuranceUser, assuree, 10, "notary-junit-test", "2014-01-01"); + Notary.assure(assuranceUser, assuree, assuree.getName(), assuree.getDoB(), 10, "notary-junit-test", "2014-01-01", AssuranceType.FACE_TO_FACE); // assure double assuranceFail(assuranceUser, assuree, 10, "notary-junit-test", "2014-01-01");