X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FConfiguredTest.java;h=808ddd678486dd0784e340d281aca7add3e3a4a1;hb=16316c8617f9da0b1e20ad0f54ce33e381f4da39;hp=72461038453e1b4ebdf46e397b420cb57a756f3a;hpb=9af691cb9d611b73907468af22e40cafa8b0200b;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java index 72461038..808ddd67 100644 --- a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java +++ b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java @@ -1,5 +1,7 @@ package org.cacert.gigi.testUtils; +import static org.junit.Assert.*; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -10,13 +12,25 @@ import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.Signature; +import java.sql.SQLException; import java.util.Properties; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.database.DatabaseConnection.Link; +import org.cacert.gigi.database.GigiPreparedStatement; +import org.cacert.gigi.database.SQLFileManager.ImportType; +import org.cacert.gigi.dbObjects.CATS.CATSType; +import org.cacert.gigi.dbObjects.Domain; +import org.cacert.gigi.dbObjects.DomainPingType; +import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail; +import org.cacert.gigi.util.DatabaseManager; +import org.cacert.gigi.util.DomainAssessment; import org.cacert.gigi.util.PEM; +import org.cacert.gigi.util.ServerConstants; import org.junit.BeforeClass; import sun.security.pkcs10.PKCS10; @@ -37,19 +51,63 @@ public abstract class ConfiguredTest { private static boolean envInited = false; + /** + * Some password that fulfills the password criteria. + */ + public static final String TEST_PASSWORD = "xvXV12°§"; + + public static final String DIFFICULT_CHARS = "ÜÖÄß𐀀"; + @BeforeClass - public static void initEnvironment() throws IOException { + public static void initEnvironmentHook() throws IOException { + initEnvironment(); + } + + public static Properties initEnvironment() throws IOException { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); if (envInited) { - return; + return generateProps(); } envInited = true; try (FileInputStream inStream = new FileInputStream("config/test.properties")) { testProps.load(inStream); } + Properties props = generateProps(); + ServerConstants.init(props); + DomainAssessment.init(props); + if ( !DatabaseConnection.isInited()) { DatabaseConnection.init(testProps); + try { + l = DatabaseConnection.newLink(false); + } catch (InterruptedException e) { + throw new Error(e); + } + } + return props; + + } + + private static Properties generateProps() throws Error { + Properties mainProps = new Properties(); + mainProps.setProperty("name.secure", testProps.getProperty("name.secure")); + mainProps.setProperty("name.www", testProps.getProperty("name.www")); + mainProps.setProperty("name.static", testProps.getProperty("name.static")); + mainProps.setProperty("name.api", testProps.getProperty("name.api")); + + mainProps.setProperty("https.port", testProps.getProperty("serverPort.https")); + mainProps.setProperty("http.port", testProps.getProperty("serverPort.http")); + + File out = new File("financial.dat"); + if ( !out.exists()) { + try (FileOutputStream fos = new FileOutputStream(out)) { + fos.write("google.com\ntwitter.com\n".getBytes("UTF-8")); + } catch (IOException e) { + throw new Error(e); + } } + mainProps.setProperty("highFinancialValue", out.getAbsolutePath()); + return mainProps; } public static KeyPair generateKeypair() throws GeneralSecurityException { @@ -95,6 +153,8 @@ public abstract class ConfiguredTest { static int count = 0; + private static Link l; + public static String createUniqueName() { return "test" + System.currentTimeMillis() + "a" + (count++) + "u"; } @@ -108,4 +168,48 @@ public abstract class ConfiguredTest { } return i; } + + public static void makeAssurer(int uid) { + try (GigiPreparedStatement ps1 = new GigiPreparedStatement("INSERT INTO cats_passed SET user_id=?, variant_id=?, language='en_EN', version=1")) { + ps1.setInt(1, uid); + ps1.setInt(2, CATSType.ASSURER_CHALLENGE.getId()); + ps1.execute(); + } + + try (GigiPreparedStatement ps2 = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, points='100'")) { + ps2.setInt(1, uid); + ps2.setInt(2, uid); + ps2.execute(); + } + } + + public MailReceiver getMailReciever() { + throw new Error("Feature requires Business or ManagedTest."); + } + + public void verify(Domain d) { + try { + d.addPing(DomainPingType.EMAIL, "admin"); + TestMail testMail = getMailReciever().receive(); + testMail.verify(); + assertTrue(d.isVerified()); + } catch (GigiApiException e) { + throw new Error(e); + } catch (IOException e) { + throw new Error(e); + } + } + + public static void purgeOnlyDB() throws SQLException, IOException { + System.out.print("... resetting Database"); + long ms = System.currentTimeMillis(); + try { + DatabaseManager.run(new String[] { + testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password") + }, ImportType.TRUNCATE); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms"); + } }