• R/O
  • HTTP
  • SSH
  • HTTPS

BetaProject: 提交

Mail送信先確認プログラムβプロジェクト


Commit MetaInfo

修訂4e81aa42be24323ca0081b7e3d1f05e09836db75 (tree)
時間2011-05-08 06:14:42
作者Takuya Ono <takuya-o@user...>
CommiterTakuya Ono

Log Message

ADD: Untrusted server connection waring dialog jUnit test program.

Change Summary

差異

--- a/src/org/jent/checksmtp/ssl/WarningServerTrustFrame.java
+++ b/src/org/jent/checksmtp/ssl/WarningServerTrustFrame.java
@@ -12,6 +12,7 @@ package org.jent.checksmtp.ssl;
1212
1313 import java.awt.Dimension;
1414 import java.awt.Toolkit;
15+import java.io.File;
1516 import java.security.cert.X509Certificate;
1617
1718 /**
@@ -27,7 +28,12 @@ public class WarningServerTrustFrame extends javax.swing.JFrame {
2728 this.trustManager = trustManager;
2829 initComponents();
2930 jTextField.setText(chain[0].getSubjectDN().toString());
30- jTextArea.setText(chain.toString());
31+ StringBuffer str = new StringBuffer();
32+ for(int i=0; i<chain.length; i++) {
33+ str.append(chain[i].toString());
34+ str.append(System.getProperty("line.separator"));
35+ }
36+ jTextArea.setText(str.toString());
3137
3238 //Move to screen center.
3339 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
--- /dev/null
+++ b/test/org/jent/checksmtp/ssl/WarningServerTrustFrameTest.java
@@ -0,0 +1,96 @@
1+/*
2+ * To change this template, choose Tools | Templates
3+ * and open the template in the editor.
4+ */
5+package org.jent.checksmtp.ssl;
6+
7+import java.security.cert.X509Certificate;
8+import junit.framework.TestCase;
9+import sun.security.x509.CertificateSubjectName;
10+import sun.security.x509.CertificateSubjectUniqueIdentity;
11+import sun.security.x509.CertificateVersion;
12+import sun.security.x509.UniqueIdentity;
13+import sun.security.x509.X500Name;
14+import sun.security.x509.X509CertImpl;
15+import sun.security.x509.X509CertInfo;
16+
17+/**
18+ *
19+ * @author tkyn
20+ */
21+public class WarningServerTrustFrameTest extends TestCase {
22+
23+ public WarningServerTrustFrameTest(String testName) {
24+ super(testName);
25+ }
26+
27+ protected void setUp() throws Exception {
28+ super.setUp();
29+ }
30+
31+ protected void tearDown() throws Exception {
32+ super.tearDown();
33+ }
34+
35+ private void sleep(long millsec) {
36+ try {
37+ Thread.sleep(millsec);
38+ } catch (InterruptedException ex) {
39+ ex.printStackTrace();
40+ }
41+ }
42+
43+ private void wait(WarningServerTrustFrame ui) {
44+ System.out.print("Wait 30s:");
45+ for (int i = 0; i < 30; i++) {
46+ sleep(1000);
47+ System.out.print(".");
48+ if (!ui.isVisible()) {
49+ break;
50+ }
51+ }
52+ System.out.println(" OK");
53+ if (ui.isVisible()) {
54+ ui.dispose();
55+ fail("Forget human check. This unit test need to human decide.");
56+ }
57+ }
58+
59+ public void testSomeMethod() {
60+ WarningServerTrustFrame ui = null;
61+ RespondingX509TrustManager trustManager = null;
62+ try {
63+ trustManager = new RespondingX509TrustManager();
64+ X509CertInfo certInfo = new X509CertInfo();
65+ CertificateVersion certVer = new CertificateVersion(1);
66+ certInfo.set(X509CertInfo.VERSION, certVer);
67+ //UniqueIdentity id = new UniqueIdentity("Push OK Key".getBytes());
68+ //CertificateSubjectUniqueIdentity subjectid = new CertificateSubjectUniqueIdentity(id);
69+ //certInfo.set(X509CertInfo.SUBJECT_ID, subjectid);
70+ X500Name name = new X500Name("CN=Push OK Key");
71+ CertificateSubjectName subjectName = new CertificateSubjectName(name);
72+ certInfo.set(X509CertInfo.SUBJECT, subjectName);
73+ X509Certificate cert = new X509CertImpl(certInfo);
74+ X509Certificate[] chain = new X509Certificate[1];
75+ chain[0] = cert;
76+ ui = new WarningServerTrustFrame(trustManager, chain);
77+ } catch (Exception ex) {
78+ ex.printStackTrace();
79+ fail(ex.toString());
80+ }
81+
82+ System.out.print("Wait 30s:");
83+ for (int i = 0; i < 30; i++) {
84+ sleep(1000);
85+ System.out.print(".");
86+ if (!ui.isVisible()) {
87+ break;
88+ }
89+ }
90+ System.out.println(" OK");
91+ if (ui.isVisible()) {
92+ ui.dispose();
93+ fail("Forget human check. This unit test need to human decide.");
94+ }
95+ }
96+}
Show on old repository browser