From: Felix Dörre Date: Thu, 10 Jul 2014 06:56:08 +0000 (+0200) Subject: Adding dummy signer bot to managed testcases. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=a31dd5456040cff55d170f0ae292e852dbb2dc57 Adding dummy signer bot to managed testcases. --- diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index 2d6631ef..5f441d2b 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -28,6 +28,7 @@ import org.cacert.gigi.DevelLauncher; import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.testUtils.TestEmailReciever.TestMail; import org.cacert.gigi.util.DatabaseManager; +import org.cacert.gigi.util.SimpleSigner; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -113,12 +114,15 @@ public class ManagedTest { throw new Error("Server startup failed"); } ter = new TestEmailReciever(new InetSocketAddress("localhost", 8473)); + SimpleSigner.runSigner(); } catch (IOException e) { throw new Error(e); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (SQLException e1) { e1.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } @@ -131,6 +135,11 @@ public class ManagedTest { return; } gigi.destroy(); + try { + SimpleSigner.stopSigner(); + } catch (InterruptedException e) { + e.printStackTrace(); + } } @After diff --git a/util/org/cacert/gigi/util/SimpleSigner.java b/util/org/cacert/gigi/util/SimpleSigner.java index d67cb8e8..2aaa1659 100644 --- a/util/org/cacert/gigi/util/SimpleSigner.java +++ b/util/org/cacert/gigi/util/SimpleSigner.java @@ -22,12 +22,32 @@ public class SimpleSigner { private static PreparedStatement readyMail; private static PreparedStatement revoke; private static PreparedStatement revokeCompleted; + private static boolean running = true; + private static Thread runner; public static void main(String[] args) throws IOException, SQLException, InterruptedException { Properties p = new Properties(); p.load(new FileReader("config/gigi.properties")); DatabaseConnection.init(p); + runSigner(); + } + + public synchronized static void stopSigner() throws InterruptedException { + if (runner == null) { + throw new IllegalStateException("already stopped"); + } + running = false; + runner.interrupt(); + runner.join(); + runner = null; + } + + public synchronized static void runSigner() throws SQLException, IOException, InterruptedException { + if (runner != null) { + throw new IllegalStateException("already running"); + } + running = true; readyMail = DatabaseConnection.getInstance().prepare( "SELECT id, csr_name, subject FROM emailcerts" + " WHERE csr_name is not null"// + " AND created=0"// @@ -43,13 +63,31 @@ public class SimpleSigner { + " AND created != 0"// + " AND revoked = '1970-01-01'"); revokeCompleted = DatabaseConnection.getInstance().prepare("UPDATE emailcerts SET revoked=NOW() WHERE id=?"); - gencrl(); - while (true) { - System.out.println("ping"); - signCertificates(); - revokeCertificates(); - Thread.sleep(5000); - } + runner = new Thread() { + @Override + public void run() { + try { + gencrl(); + } catch (IOException e2) { + e2.printStackTrace(); + } catch (InterruptedException e2) { + e2.printStackTrace(); + } + while (running) { + try { + signCertificates(); + revokeCertificates(); + Thread.sleep(5000); + } catch (IOException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (InterruptedException e1) { + } + } + } + }; + runner.start(); } private static void revokeCertificates() throws SQLException, IOException, InterruptedException {