From b59c37e88149d0463ab4b802cacb6f0ea883acfb Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Mon, 18 Jul 2016 11:27:56 +0200 Subject: [PATCH] add: country information where verification took place fixes issue #78 Change-Id: I0e677dfc0dde671a95186f9c64388fad2da4446b --- doc/Data.uxf | 11 ++--- .../gigi/database/DatabaseConnection.java | 2 +- .../cacert/gigi/database/tableStructure.sql | 3 +- .../cacert/gigi/database/upgrade/from_21.sql | 1 + src/org/cacert/gigi/dbObjects/Assurance.java | 8 +++- src/org/cacert/gigi/dbObjects/User.java | 7 +++- .../cacert/gigi/output/AssurancesDisplay.java | 2 +- .../cacert/gigi/pages/wot/AssuranceForm.java | 9 +++- .../cacert/gigi/pages/wot/AssuranceForm.templ | 6 +++ src/org/cacert/gigi/util/Notary.java | 35 ++++++++++------ tests/org/cacert/gigi/TestUser.java | 4 +- .../gigi/dbObjects/TestAssuranceMail.java | 32 +++++++------- .../cacert/gigi/dbObjects/TestAssureName.java | 9 ++-- .../account/TestPasswordResetExternal.java | 2 +- .../cacert/gigi/pages/wot/TestAssurance.java | 42 +++++++++---------- tests/org/cacert/gigi/util/TestNotary.java | 18 ++++---- .../org/cacert/gigi/pages/Manager.java | 6 ++- 17 files changed, 120 insertions(+), 77 deletions(-) create mode 100644 src/org/cacert/gigi/database/upgrade/from_21.sql diff --git a/doc/Data.uxf b/doc/Data.uxf index 8854e265..225ae2d2 100644 --- a/doc/Data.uxf +++ b/doc/Data.uxf @@ -1,5 +1,5 @@ - + 10 com.baselet.element.old.element.Class @@ -318,7 +318,7 @@ executed as> 710 1090 390 - 180 + 200 Assurance -- @@ -331,6 +331,7 @@ executed as> -expire: timestamp -sponsor: User (??????????) -deleted: timestamp +-country: varchar(2) @@ -351,14 +352,14 @@ Assurer> com.baselet.element.old.element.Relation 580 - 1060 + 1070 150 - 70 + 80 lt=- m1=0..n Assuree> - 130;50;30;50 + 130;60;30;40 com.baselet.element.old.element.Class diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 80f96e8d..d9febb08 100644 --- a/src/org/cacert/gigi/database/DatabaseConnection.java +++ b/src/org/cacert/gigi/database/DatabaseConnection.java @@ -122,7 +122,7 @@ public class DatabaseConnection { } - public static final int CURRENT_SCHEMA_VERSION = 21; + public static final int CURRENT_SCHEMA_VERSION = 22; public static final int CONNECTION_TIMEOUT = 24 * 60 * 60; diff --git a/src/org/cacert/gigi/database/tableStructure.sql b/src/org/cacert/gigi/database/tableStructure.sql index f9010ccb..a8d92f57 100644 --- a/src/org/cacert/gigi/database/tableStructure.sql +++ b/src/org/cacert/gigi/database/tableStructure.sql @@ -271,6 +271,7 @@ CREATE TABLE "notary" ( "sponsor" int NOT NULL DEFAULT '0', # date when verification was deleted (or 0) "deleted" timestamp NULL DEFAULT NULL, + "country" varchar(2) NULL, PRIMARY KEY ("id") ); @@ -372,7 +373,7 @@ CREATE TABLE "schemeVersion" ( "version" smallint NOT NULL, PRIMARY KEY ("version") ); -INSERT INTO "schemeVersion" (version) VALUES(21); +INSERT INTO "schemeVersion" (version) VALUES(22); DROP TABLE IF EXISTS `passwordResetTickets`; CREATE TABLE `passwordResetTickets` ( diff --git a/src/org/cacert/gigi/database/upgrade/from_21.sql b/src/org/cacert/gigi/database/upgrade/from_21.sql new file mode 100644 index 00000000..e565d9f4 --- /dev/null +++ b/src/org/cacert/gigi/database/upgrade/from_21.sql @@ -0,0 +1 @@ +ALTER TABLE "notary" ADD COLUMN "country" varchar(2) NULL; diff --git a/src/org/cacert/gigi/dbObjects/Assurance.java b/src/org/cacert/gigi/dbObjects/Assurance.java index dbcc20b6..486b5a34 100644 --- a/src/org/cacert/gigi/dbObjects/Assurance.java +++ b/src/org/cacert/gigi/dbObjects/Assurance.java @@ -33,7 +33,9 @@ public class Assurance { private String date; - public Assurance(int id, User from, Name to, String location, String method, int points, String date) { + private CountryCode country; + + public Assurance(int id, User from, Name to, String location, String method, int points, String date, CountryCode country) { this.id = id; this.from = from; this.to = to; @@ -41,6 +43,7 @@ public class Assurance { this.method = method; this.points = points; this.date = date; + this.country = country; } @@ -72,4 +75,7 @@ public class Assurance { return date; } + public CountryCode getCountry() { + return country; + } } diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index 00981476..a6e1d3f1 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -16,6 +16,7 @@ import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; import org.cacert.gigi.dbObjects.CATS.CATSType; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.localisation.Language; import org.cacert.gigi.output.DateSelector; import org.cacert.gigi.pages.PasswordResetPage; @@ -595,7 +596,11 @@ public class User extends CertificateOwner { } private Assurance assuranceByRes(GigiResultSet res) { - return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), Name.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date")); + try { + return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), Name.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date"), res.getString("country") == null ? null : CountryCode.getCountryCode(res.getString("country"), CountryCodeType.CODE_2_CHARS)); + } catch (GigiApiException e) { + throw new Error(e); + } } public boolean isInVerificationLimit() { diff --git a/src/org/cacert/gigi/output/AssurancesDisplay.java b/src/org/cacert/gigi/output/AssurancesDisplay.java index f6d5362a..c412a4eb 100644 --- a/src/org/cacert/gigi/output/AssurancesDisplay.java +++ b/src/org/cacert/gigi/output/AssurancesDisplay.java @@ -60,7 +60,7 @@ public class AssurancesDisplay implements Outputable { vars.put("myName", to == null ? l.getTranslation("own name removed") : to); } vars.put("date", assurance.getDate()); - vars.put("location", assurance.getLocation()); + vars.put("location", assurance.getLocation() + " (" + (assurance.getCountry() == null ? l.getTranslation("not given") : assurance.getCountry().getCountry()) + ")"); vars.put("points", assurance.getPoints()); i++; return true; diff --git a/src/org/cacert/gigi/pages/wot/AssuranceForm.java b/src/org/cacert/gigi/pages/wot/AssuranceForm.java index e5521dab..8ad735fb 100644 --- a/src/org/cacert/gigi/pages/wot/AssuranceForm.java +++ b/src/org/cacert/gigi/pages/wot/AssuranceForm.java @@ -17,6 +17,7 @@ import org.cacert.gigi.dbObjects.Name; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.localisation.Language; import org.cacert.gigi.output.ArrayIterable; +import org.cacert.gigi.output.CountrySelector; import org.cacert.gigi.output.template.Form; import org.cacert.gigi.output.template.IterableDataset; import org.cacert.gigi.output.template.SprintfCommand; @@ -48,6 +49,8 @@ public class AssuranceForm extends Form { private static final Template templ = new Template(AssuranceForm.class.getResource("AssuranceForm.templ")); + private CountrySelector cs; + public AssuranceForm(HttpServletRequest hsr, User assuree) throws GigiApiException { super(hsr); assurer = Page.getUser(hsr); @@ -73,6 +76,7 @@ public class AssuranceForm extends Form { assureeNames = names.toArray(new Name[names.size()]); dob = this.assuree.getDoB(); selected = new boolean[assureeNames.length]; + cs = new CountrySelector("countryCode", false); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -100,6 +104,8 @@ public class AssuranceForm extends Form { res.put("location", location); res.put("date", date); res.put("aword", aword); + res.put("countryCode", cs); + final LinkedList ats = new LinkedList<>(); for (AssuranceType at : AssuranceType.values()) { try { @@ -131,6 +137,7 @@ public class AssuranceForm extends Form { public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { location = req.getParameter("location"); date = req.getParameter("date"); + cs.update(req); GigiApiException gae = new GigiApiException(); if (date == null || location == null) { gae.mergeInto(new GigiApiException("You need to enter location and date!")); @@ -187,7 +194,7 @@ public class AssuranceForm extends Form { throw new GigiApiException("You must confirm at least one name to verify an account."); } - Notary.assureAll(assurer, assuree, dob, pointsI, location, req.getParameter("date"), type, toAssure.toArray(new Name[toAssure.size()])); + Notary.assureAll(assurer, assuree, dob, pointsI, location, req.getParameter("date"), type, toAssure.toArray(new Name[toAssure.size()]), cs.getCountry()); if (aword != null && !aword.equals("")) { Language langApplicant = Language.getInstance(assuree.getPreferredLocale()); diff --git a/src/org/cacert/gigi/pages/wot/AssuranceForm.templ b/src/org/cacert/gigi/pages/wot/AssuranceForm.templ index 297397c6..f846bc96 100644 --- a/src/org/cacert/gigi/pages/wot/AssuranceForm.templ +++ b/src/org/cacert/gigi/pages/wot/AssuranceForm.templ @@ -19,6 +19,12 @@ + + + + + + diff --git a/src/org/cacert/gigi/util/Notary.java b/src/org/cacert/gigi/util/Notary.java index ed1ce238..f43e3195 100644 --- a/src/org/cacert/gigi/util/Notary.java +++ b/src/org/cacert/gigi/util/Notary.java @@ -12,6 +12,7 @@ import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; +import org.cacert.gigi.dbObjects.CountryCode; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.Name; import org.cacert.gigi.dbObjects.User; @@ -80,7 +81,7 @@ public class Notary { * @throws GigiApiException * if the assurance fails (for various reasons) */ - public synchronized static void assure(User assurer, User assuree, Name assureeName, DayDate dob, int awarded, String location, String date, AssuranceType type) throws GigiApiException { + public synchronized static void assure(User assurer, User assuree, Name assureeName, DayDate dob, int awarded, String location, String date, AssuranceType type, CountryCode country) throws GigiApiException { may(assurer, assuree, AssuranceType.FACE_TO_FACE); GigiApiException gae = new GigiApiException(); if ( !gae.isEmpty()) { @@ -112,6 +113,11 @@ public class Notary { } else if (location.length() <= 2) { gae.mergeInto(new GigiApiException("You must enter a location with at least 3 characters eg town and country.")); } + + if (country == null) { + gae.mergeInto(new GigiApiException("You failed to enter the country of your meeting.")); + } + synchronized (assuree) { if (assurer.getId() == assuree.getId()) { throw new GigiApiException("You cannot verify yourself."); @@ -150,11 +156,11 @@ public class Notary { } if (type == AssuranceType.FACE_TO_FACE) { - assureF2F(assurer, assuree, assureeName, awarded, location, date); + assureF2F(assurer, assuree, assureeName, awarded, location, date, country); } else if (type == AssuranceType.NUCLEUS) { - assureNucleus(assurer, assuree, assureeName, awarded, location, date); + assureNucleus(assurer, assuree, assureeName, awarded, location, date, country); } else if (type == AssuranceType.TTP_ASSISTED) { - assureTTP(assurer, assuree, assureeName, awarded, location, date); + assureTTP(assurer, assuree, assureeName, awarded, location, date, country); } else { throw new GigiApiException(SprintfCommand.createSimple("Unknown Verification type: {0}", type.toString())); } @@ -163,26 +169,28 @@ public class Notary { } } - private static void assureF2F(User assurer, User assuree, Name name, int awarded, String location, String date) throws GigiApiException { + private static void assureF2F(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException { may(assurer, assuree, AssuranceType.FACE_TO_FACE); - try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?")) { ps.setInt(1, assurer.getId()); ps.setInt(2, name.getId()); ps.setInt(3, awarded); ps.setString(4, location); ps.setString(5, date); + ps.setString(6, country.getCountryCode()); ps.execute(); } } - private static void assureTTP(User assurer, User assuree, Name name, int awarded, String location, String date) throws GigiApiException { + private static void assureTTP(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException { may(assurer, assuree, AssuranceType.TTP_ASSISTED); - try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `method`='TTP-Assisted'")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?, `method`='TTP-Assisted'")) { ps.setInt(1, assurer.getId()); ps.setInt(2, name.getId()); ps.setInt(3, awarded); ps.setString(4, location); ps.setString(5, date); + ps.setString(6, country.getCountryCode()); ps.execute(); assuree.revokeGroup(assurer, Group.TTP_APPLICANT); } @@ -215,11 +223,11 @@ public class Notary { throw new GigiApiException("Verification type not possible."); } - private static void assureNucleus(User assurer, User assuree, Name name, int awarded, String location, String date) throws GigiApiException { + private static void assureNucleus(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException { may(assurer, assuree, AssuranceType.NUCLEUS); // Do up to 35 points as f2f int f2fPoints = Math.min(assurer.getMaxAssurePoints(), awarded); - assureF2F(assurer, assuree, name, f2fPoints, location, date); + assureF2F(assurer, assuree, name, f2fPoints, location, date, country); awarded -= f2fPoints; if (awarded <= 0) { @@ -228,17 +236,18 @@ public class Notary { // Assure remaining points as "Nucleus Bonus" // Valid for 4 Weeks = 28 days - try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `method`='Nucleus Bonus', `expire` = CURRENT_TIMESTAMP + interval '28 days'")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?, `method`='Nucleus Bonus', `expire` = CURRENT_TIMESTAMP + interval '28 days'")) { ps.setInt(1, assurer.getId()); ps.setInt(2, name.getId()); ps.setInt(3, awarded); ps.setString(4, location); ps.setString(5, date); + ps.setString(6, country.getCountryCode()); ps.execute(); } } - public synchronized static void assureAll(User assurer, User assuree, DayDate dob, int awarded, String location, String date, AssuranceType type, Name[] toAssure) throws GigiApiException { + public synchronized static void assureAll(User assurer, User assuree, DayDate dob, int awarded, String location, String date, AssuranceType type, Name[] toAssure, CountryCode country) throws GigiApiException { if (toAssure.length == 0) { throw new GigiApiException("You must confirm at least one name to verify an account."); } @@ -247,7 +256,7 @@ public class Notary { for (int i = 0; i < toAssure.length; i++) { hadLessThan50Points[i] = toAssure[i].getAssurancePoints() < 50; - assure(assurer, assuree, toAssure[i], dob, awarded, location, date, type); + assure(assurer, assuree, toAssure[i], dob, awarded, location, date, type, country); } sendVerificationNotificationApplicant(assurer, assuree, toAssure, awarded, hadLessThan50Points, hadTotalLessThan100); } diff --git a/tests/org/cacert/gigi/TestUser.java b/tests/org/cacert/gigi/TestUser.java index f665a7a6..ff67b4f2 100644 --- a/tests/org/cacert/gigi/TestUser.java +++ b/tests/org/cacert/gigi/TestUser.java @@ -9,6 +9,8 @@ import java.util.Locale; import org.cacert.gigi.dbObjects.Assurance; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; +import org.cacert.gigi.dbObjects.CountryCode; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.Domain; import org.cacert.gigi.dbObjects.EmailAddress; import org.cacert.gigi.dbObjects.Name; @@ -109,7 +111,7 @@ public class TestUser extends BusinessTest { User[] us = new User[5]; for (int i = 0; i < us.length; i++) { us[i] = User.getById(createAssuranceUser("f", "l", createUniqueName() + "@email.com", TEST_PASSWORD)); - Notary.assure(us[i], u, u.getPreferredName(), u.getDoB(), 10, "here", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(us[i], u, u.getPreferredName(), u.getDoB(), 10, "here", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); } assertTrue(u.isValidName("aä b")); diff --git a/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java b/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java index dcb45039..d8661811 100644 --- a/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java +++ b/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java @@ -8,10 +8,8 @@ import java.sql.Timestamp; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; -import org.cacert.gigi.dbObjects.Name; -import org.cacert.gigi.dbObjects.NamePart; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.NamePart.NamePartType; -import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.testUtils.BusinessTest; import org.cacert.gigi.util.DayDate; import org.cacert.gigi.util.Notary; @@ -48,7 +46,7 @@ public class TestAssuranceMail extends BusinessTest { int applicantId = createVerifiedUser("John", "Doe", applicantT, TEST_PASSWORD); User applicantXP = User.getById(applicantId); applicantXP = User.getById(applicantId); - Notary.assure(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); } } @@ -57,7 +55,7 @@ public class TestAssuranceMail extends BusinessTest { } private void enterVerification(int points, Name... names) throws GigiApiException { - Notary.assureAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), AssuranceType.FACE_TO_FACE, names); + Notary.assureAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), AssuranceType.FACE_TO_FACE, names, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); } private void enterVerificationInPast(int points, Name name) { @@ -275,20 +273,20 @@ public class TestAssuranceMail extends BusinessTest { // verify with 35 VP newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); - Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); - Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); - Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); - Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); // add first Verification in the past result first name 45 VP newAgent(); @@ -304,16 +302,16 @@ public class TestAssuranceMail extends BusinessTest { // verify first name to 85 VP newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); newAgent(); - Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); // add first Verification in the past result first name 95 VP newAgent(); diff --git a/tests/org/cacert/gigi/dbObjects/TestAssureName.java b/tests/org/cacert/gigi/dbObjects/TestAssureName.java index 03df9a3c..dd800cbb 100644 --- a/tests/org/cacert/gigi/dbObjects/TestAssureName.java +++ b/tests/org/cacert/gigi/dbObjects/TestAssureName.java @@ -4,6 +4,7 @@ import static org.junit.Assert.*; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.NamePart.NamePartType; import org.cacert.gigi.testUtils.ClientBusinessTest; import org.cacert.gigi.util.Notary; @@ -19,13 +20,13 @@ public class TestAssureName extends ClientBusinessTest { Name n4 = new Name(u, new NamePart(NamePartType.SINGLE_NAME, "Testiaac")); assertEquals(0, n0.getAssurancePoints()); - Notary.assure(u0, u, n0, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(u0, u, n0, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); assertEquals(10, n0.getAssurancePoints()); - Notary.assure(u0, u, n2, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(u0, u, n2, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); assertEquals(10, n2.getAssurancePoints()); - Notary.assure(u0, u, n3, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(u0, u, n3, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); assertEquals(10, n3.getAssurancePoints()); - Notary.assure(u0, u, n4, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(u0, u, n4, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); assertEquals(10, n4.getAssurancePoints()); assertEquals(10, u.getMaxAssurePoints()); } diff --git a/tests/org/cacert/gigi/pages/account/TestPasswordResetExternal.java b/tests/org/cacert/gigi/pages/account/TestPasswordResetExternal.java index 2e74670e..7112bd2d 100644 --- a/tests/org/cacert/gigi/pages/account/TestPasswordResetExternal.java +++ b/tests/org/cacert/gigi/pages/account/TestPasswordResetExternal.java @@ -29,7 +29,7 @@ public class TestPasswordResetExternal extends ClientTest { String cookie2 = login(u.getEmail(), TEST_PASSWORD); URLConnection uc = TestAssurance.buildupAssureFormConnection(cookie2, email, true); String avalue = RandomToken.generateToken(32); - uc.getOutputStream().write(("assuredName=" + this.u.getPreferredName().getId() + "&date=" + TestAssurance.validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10&passwordReset=1&passwordResetValue=" + URLEncoder.encode(avalue, "UTF-8")).getBytes("UTF-8")); + uc.getOutputStream().write(("assuredName=" + this.u.getPreferredName().getId() + "&date=" + TestAssurance.validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10&passwordReset=1&passwordResetValue=" + URLEncoder.encode(avalue, "UTF-8")).getBytes("UTF-8")); uc.getOutputStream().flush(); String error = fetchStartErrorMessage(IOUtils.readURL(uc)); assertNull(error); diff --git a/tests/org/cacert/gigi/pages/wot/TestAssurance.java b/tests/org/cacert/gigi/pages/wot/TestAssurance.java index 136ca610..84cd6dc4 100644 --- a/tests/org/cacert/gigi/pages/wot/TestAssurance.java +++ b/tests/org/cacert/gigi/pages/wot/TestAssurance.java @@ -93,13 +93,13 @@ public class TestAssurance extends ManagedTest { @Test public void testAssureForm() throws IOException { - executeSuccess("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test public void testAssureFormEmpty() throws IOException { URLConnection uc = buildupAssureFormConnection(true); - uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&rules=1&assertion=1&points=10").getBytes("UTF-8")); + uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&rules=1&assertion=1&points=10").getBytes("UTF-8")); uc.getOutputStream().flush(); String data = IOUtils.readURL(uc); assertThat(data, hasError()); @@ -108,7 +108,7 @@ public class TestAssurance extends ManagedTest { @Test public void testAssureFormContanisData() throws IOException { URLConnection uc = buildupAssureFormConnection(true); - uc.getOutputStream().write(("assuredName=" + assureeName + "&date=" + validVerificationDateString() + "&location=testcase&rules=1&assertion=1&points=10").getBytes("UTF-8")); + uc.getOutputStream().write(("assuredName=" + assureeName + "&date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&rules=1&assertion=1&points=10").getBytes("UTF-8")); uc.getOutputStream().flush(); String data = IOUtils.readURL(uc); assertThat(data, containsString(validVerificationDateString())); @@ -119,7 +119,7 @@ public class TestAssurance extends ManagedTest { public void testAssureFormNoCSRF() throws IOException { // override csrf HttpURLConnection uc = (HttpURLConnection) buildupAssureFormConnection(false); - uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8")); + uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8")); uc.getOutputStream().flush(); assertEquals(500, uc.getResponseCode()); } @@ -128,7 +128,7 @@ public class TestAssurance extends ManagedTest { public void testAssureFormWrongCSRF() throws IOException { // override csrf HttpURLConnection uc = (HttpURLConnection) buildupAssureFormConnection(false); - uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10&csrf=aragc").getBytes("UTF-8")); + uc.getOutputStream().write(("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10&csrf=aragc").getBytes("UTF-8")); uc.getOutputStream().flush(); assertEquals(500, uc.getResponseCode()); } @@ -151,7 +151,7 @@ public class TestAssurance extends ManagedTest { assertNull(executeBasicWebInteraction(assureeCookie, MyDetails.PATH, newDob + "&action=updateDoB", 0)); - uc.getOutputStream().write(("assuredName=" + assureeName + "&date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8")); + uc.getOutputStream().write(("assuredName=" + assureeName + "&date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8")); uc.getOutputStream().flush(); String error = fetchStartErrorMessage(IOUtils.readURL(uc)); if (succeed) { @@ -166,7 +166,7 @@ public class TestAssurance extends ManagedTest { public void testAssureFormFuture() throws IOException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); int year = Integer.parseInt(sdf.format(new Date(System.currentTimeMillis()))) + 2; - executeFails("date=" + year + "-01-01&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=" + year + "-01-01&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test @@ -176,12 +176,12 @@ public class TestAssurance extends ManagedTest { c.setTimeInMillis(System.currentTimeMillis()); c.add(Calendar.HOUR_OF_DAY, 12); - executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test public void testAssureFormPastInRange() throws IOException { - executeSuccess("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test @@ -192,7 +192,7 @@ public class TestAssurance extends ManagedTest { c.add(Calendar.MONTH, -Notary.LIMIT_MAX_MONTHS_VERIFICATION); c.add(Calendar.DAY_OF_MONTH, 1); - executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test @@ -202,32 +202,32 @@ public class TestAssurance extends ManagedTest { c.setTimeInMillis(System.currentTimeMillis()); c.add(Calendar.MONTH, -Notary.LIMIT_MAX_MONTHS_VERIFICATION); - executeFails("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test public void testAssureFormNoLoc() throws IOException { - executeFails("date=" + validVerificationDateString() + "&location=a&certify=1&rules=1&assertion=1&points=10"); - executeFails("date=" + validVerificationDateString() + "&location=&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=" + validVerificationDateString() + "&location=a&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=" + validVerificationDateString() + "&location=&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test public void testAssureFormInvalDate() throws IOException { - executeFails("date=20000101&location=testcase&certify=1&rules=1&assertion=1&points=10"); - executeFails("date=&location=testcase&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=20000101&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + executeFails("date=&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); } @Test public void testAssureFormBoxes() throws IOException { - executeFails("date=" + validVerificationDateString() + "&location=testcase&certify=0&rules=1&assertion=1&points=10"); - executeFails("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=&assertion=1&points=10"); - executeFails("date=" + validVerificationDateString() + "&location=testcase&certify=1&rules=1&assertion=z&points=10"); + executeFails("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=0&rules=1&assertion=1&points=10"); + executeFails("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=&assertion=1&points=10"); + executeFails("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=z&points=10"); } @Test public void testAssureListingValid() throws IOException { String uniqueLoc = createUniqueName(); - execute("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&certify=1&rules=1&assertion=1&points=10"); + execute("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); String cookie = login(assureeM, TEST_PASSWORD); URLConnection url = get(cookie, Points.PATH); @@ -239,7 +239,7 @@ public class TestAssurance extends ManagedTest { @Test public void testAssurerListingValid() throws IOException { String uniqueLoc = createUniqueName(); - executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); String cookie = login(assurerM, TEST_PASSWORD); URLConnection url = get(cookie, Points.PATH); String resp = IOUtils.readURL(url); @@ -304,7 +304,7 @@ public class TestAssurance extends ManagedTest { // enter second entry String uniqueLoc = createUniqueName(); - executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); // enter third entry on the same day URLConnection uc = get(cookie, AssurePage.PATH); diff --git a/tests/org/cacert/gigi/util/TestNotary.java b/tests/org/cacert/gigi/util/TestNotary.java index 37451573..c0426b9b 100644 --- a/tests/org/cacert/gigi/util/TestNotary.java +++ b/tests/org/cacert/gigi/util/TestNotary.java @@ -8,6 +8,8 @@ import java.util.Date; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.dbObjects.Assurance.AssuranceType; +import org.cacert.gigi.dbObjects.CountryCode; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.ObjectCache; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.output.DateSelector; @@ -16,8 +18,10 @@ import org.junit.Test; public class TestNotary extends BusinessTest { - // These tests create a lot of users and therefore require resetting of the - // registering-rate-limit. + public final CountryCode DE = CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS); + + public TestNotary() throws GigiApiException {} + @Test public void testNormalAssurance() throws SQLException, GigiApiException { User[] users = new User[30]; @@ -31,7 +35,7 @@ public class TestNotary extends BusinessTest { }; try { - Notary.assure(assurer, users[0], users[0].getPreferredName(), users[0].getDoB(), -1, "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(assurer, users[0], users[0].getPreferredName(), users[0].getDoB(), -1, "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE, DE); fail("This shouldn't have passed"); } catch (GigiApiException e) { // expected @@ -40,7 +44,7 @@ public class TestNotary extends BusinessTest { assertEquals(result[i], assurer.getMaxAssurePoints()); assuranceFail(assurer, users[i], result[i] + 1, "test-notary", validVerificationDateString()); - Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), result[i], "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), result[i], "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE, DE); assuranceFail(assurer, users[i], result[i], "test-notary", validVerificationDateString()); } @@ -52,7 +56,7 @@ public class TestNotary extends BusinessTest { private void assuranceFail(User assurer, User user, int i, String location, String date) throws SQLException { try { - Notary.assure(assurer, user, user.getPreferredName(), user.getDoB(), i, location, date, AssuranceType.FACE_TO_FACE); + Notary.assure(assurer, user, user.getPreferredName(), user.getDoB(), i, location, date, AssuranceType.FACE_TO_FACE, DE); fail("This shouldn't have passed"); } catch (GigiApiException e) { // expected @@ -77,7 +81,7 @@ public class TestNotary extends BusinessTest { assuranceFail(assurer, users[i], -1, "test-notary", validVerificationDateString()); assuranceFail(assurer, users[i], 11, "test-notary", validVerificationDateString()); if (User.POJAM_ENABLED) { - Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), 10, "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), 10, "test-notary", validVerificationDateString(), AssuranceType.FACE_TO_FACE, DE); } assuranceFail(assurer, users[i], 10, "test-notary", validVerificationDateString()); } @@ -113,7 +117,7 @@ public class TestNotary extends BusinessTest { assuranceFail(assuree, assuranceUser, 10, "notary-junit-test", validVerificationDateString()); // valid - Notary.assure(assuranceUser, assuree, assuree.getPreferredName(), assuree.getDoB(), 10, "notary-junit-test", validVerificationDateString(), AssuranceType.FACE_TO_FACE); + Notary.assure(assuranceUser, assuree, assuree.getPreferredName(), assuree.getDoB(), 10, "notary-junit-test", validVerificationDateString(), AssuranceType.FACE_TO_FACE, DE); // verify double assuranceFail(assuranceUser, assuree, 10, "notary-junit-test", validVerificationDateString()); diff --git a/util-testing/org/cacert/gigi/pages/Manager.java b/util-testing/org/cacert/gigi/pages/Manager.java index 0cf8e12d..f599fcd6 100644 --- a/util-testing/org/cacert/gigi/pages/Manager.java +++ b/util-testing/org/cacert/gigi/pages/Manager.java @@ -34,6 +34,8 @@ import org.cacert.gigi.dbObjects.CATS.CATSType; import org.cacert.gigi.dbObjects.Certificate; import org.cacert.gigi.dbObjects.Certificate.CertificateStatus; import org.cacert.gigi.dbObjects.CertificateOwner; +import org.cacert.gigi.dbObjects.CountryCode; +import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.Digest; import org.cacert.gigi.dbObjects.Domain; import org.cacert.gigi.dbObjects.DomainPingType; @@ -313,7 +315,7 @@ public class Manager extends Page { if (vp < 10) { currentVP = vp; } - Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); agentNumber += 1; vp -= currentVP; } @@ -330,7 +332,7 @@ public class Manager extends Page { try { for (int i = 0; i < 25; i++) { User a = getAssurer(i); - Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE); + Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS)); } } catch (GigiApiException e) { throw new Error(e); -- 2.39.2