jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1708223 - in /jmeter/trunk/test: resources/org/ resources/org/apache/ resources/org/apache/jmeter/ resources/org/apache/jmeter/assertions/ src/org/apache/jmeter/assertions/
Date Mon, 12 Oct 2015 20:10:37 GMT
Author: fschumacher
Date: Mon Oct 12 20:10:37 2015
New Revision: 1708223

URL: http://svn.apache.org/viewvc?rev=1708223&view=rev
Log:
Add test cases for SMIMEAssertion.

Bugzilla Id: 58303

Added:
    jmeter/trunk/test/resources/org/
    jmeter/trunk/test/resources/org/apache/
    jmeter/trunk/test/resources/org/apache/jmeter/
    jmeter/trunk/test/resources/org/apache/jmeter/assertions/
    jmeter/trunk/test/resources/org/apache/jmeter/assertions/email.pem
    jmeter/trunk/test/resources/org/apache/jmeter/assertions/signed_email.eml
    jmeter/trunk/test/src/org/apache/jmeter/assertions/SMIMEAssertionTest.java

Added: jmeter/trunk/test/resources/org/apache/jmeter/assertions/email.pem
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/resources/org/apache/jmeter/assertions/email.pem?rev=1708223&view=auto
==============================================================================
--- jmeter/trunk/test/resources/org/apache/jmeter/assertions/email.pem (added)
+++ jmeter/trunk/test/resources/org/apache/jmeter/assertions/email.pem Mon Oct 12 20:10:37
2015
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDsTCCApmgAwIBAgIJAMjEb4+/nr6kMA0GCSqGSIb3DQEBCwUAMHIxFjAUBgNV
+BAMTDWFsaWNlIGV4YW1wbGUxIjAgBgkqhkiG9w0BCQEWE2FsaWNlQGEuZXhhbXBs
+ZS5jb20xFDASBgNVBAoTC0V4YW1wbGUgTHRkMREwDwYDVQQHEwhXaGVyZXZlcjEL
+MAkGA1UEBhMCQVUwHhcNMTUxMDA4MTcxMzAwWhcNMTYxMDA3MTcxMzAwWjByMRYw
+FAYDVQQDEw1hbGljZSBleGFtcGxlMSIwIAYJKoZIhvcNAQkBFhNhbGljZUBhLmV4
+YW1wbGUuY29tMRQwEgYDVQQKEwtFeGFtcGxlIEx0ZDERMA8GA1UEBxMIV2hlcmV2
+ZXIxCzAJBgNVBAYTAkFVMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
+tvFwdH/wkxMHX4CU8j6nnrH4BOu8aeDfjgE3Bb7S7sgUuouvWzUbLk/QxQzaH0uh
+kkjK6pvYQBnrzvjtWjxE/tgZAY3YYNPux0N1YGcgzsTm8e2b//hXWYZP7+ru4ify
+oMDn8T5H5ZLwuAaKKUJZbg5HbRHZLanEaksXyNIbeeJ1E8VOBsgpYLayrCYCTZeI
+N5S0lat77I6Eak8qxCy4BNBWNZC4CpFPgZ+vanS8ZNHlwWcD05+cgyubSedvCyq1
+UpmHeNs4GrFfJxy7rqMNcDxxqQ+y8sK/kvp/E7EyhUjPct/WJVeyezb7ICqRg/SA
+4iBiBmQw0xsVR98718ePSQIDAQABo0owSDBGBgNVHREEPzA9gRNhbGljZUBhLmV4
+YW1wbGUuY29tgRFib2JAYi5leGFtcGxlLmNvbYETY2hhcmxpZUBleGFtcGxlLmNv
+bTANBgkqhkiG9w0BAQsFAAOCAQEAEa7gGC44HIidRWvCswdKtTvO9yduG7yy1izT
+LBJd3OSuqJ/tcy4QmImcBvtM0p/M0dIegIJBWueiymf4Rj5d/l4Zs4pO0T72e4qG
+tjMIWNShkM1EXHqI4T5bSx8dUstDxyop54WhoriLotxAB4fLbqWcDr9x7PaE9FZ8
+c8O73u3Yo5IgteGJGmSh/SWxFOglDcBkjasNG0LoyC4A8OYtOIZslFDSBBBCovIV
+3VYKwNgczwj2zpHa8jh3GyqBIscTZyKHU79hR1nrUgVzgaBIhiQ0ZLIFar7XuyMC
+xqgk0AeDAAcyqbADF5NfDYgWDIrB4WDgnufwVg9Q5hQi5h6z5w==
+-----END CERTIFICATE-----

Added: jmeter/trunk/test/resources/org/apache/jmeter/assertions/signed_email.eml
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/resources/org/apache/jmeter/assertions/signed_email.eml?rev=1708223&view=auto
==============================================================================
--- jmeter/trunk/test/resources/org/apache/jmeter/assertions/signed_email.eml (added)
+++ jmeter/trunk/test/resources/org/apache/jmeter/assertions/signed_email.eml Mon Oct 12 20:10:37
2015
@@ -0,0 +1,56 @@
+To: someone@example.com
+From: bob@b.example.com
+Subject: Signed Message
+MIME-Version: 1.0
+Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha-256";
boundary="----5EFD563634B646BB8C420E6DA8819BE6"
+
+This is an S/MIME signed message
+
+------5EFD563634B646BB8C420E6DA8819BE6
+Content-type: text/plain
+
+This was really written by me.
+
+------5EFD563634B646BB8C420E6DA8819BE6
+Content-Type: application/x-pkcs7-signature; name="smime.p7s"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename="smime.p7s"
+
+MIIGggYJKoZIhvcNAQcCoIIGczCCBm8CAQExDzANBglghkgBZQMEAgEFADALBgkq
+hkiG9w0BBwGgggO1MIIDsTCCApmgAwIBAgIJAMjEb4+/nr6kMA0GCSqGSIb3DQEB
+CwUAMHIxFjAUBgNVBAMTDWFsaWNlIGV4YW1wbGUxIjAgBgkqhkiG9w0BCQEWE2Fs
+aWNlQGEuZXhhbXBsZS5jb20xFDASBgNVBAoTC0V4YW1wbGUgTHRkMREwDwYDVQQH
+EwhXaGVyZXZlcjELMAkGA1UEBhMCQVUwHhcNMTUxMDA4MTcxMzAwWhcNMTYxMDA3
+MTcxMzAwWjByMRYwFAYDVQQDEw1hbGljZSBleGFtcGxlMSIwIAYJKoZIhvcNAQkB
+FhNhbGljZUBhLmV4YW1wbGUuY29tMRQwEgYDVQQKEwtFeGFtcGxlIEx0ZDERMA8G
+A1UEBxMIV2hlcmV2ZXIxCzAJBgNVBAYTAkFVMIIBIjANBgkqhkiG9w0BAQEFAAOC
+AQ8AMIIBCgKCAQEAtvFwdH/wkxMHX4CU8j6nnrH4BOu8aeDfjgE3Bb7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FMQ8XDTE1MTAwODE3MTMwMFowLwYJKoZIhvcNAQkEMSIEIMGcHDb2GAxu
+gaLHZ+WhdwrgMnYTgE58z3xhClvyHMJqMHkGCSqGSIb3DQEJDzFsMGowCwYJYIZI
+AWUDBAEqMAsGCWCGSAFlAwQBFjALBglghkgBZQMEAQIwCgYIKoZIhvcNAwcwDgYI
+KoZIhvcNAwICAgCAMA0GCCqGSIb3DQMCAgFAMAcGBSsOAwIHMA0GCCqGSIb3DQMC
+AgEoMA0GCSqGSIb3DQEBAQUABIIBAAMGc7T6RiYkZ6i50saYRmXKWw04ft4ocdy+
+f/T/bllQ9Evrpl/swWlJSKjhjhRigM2g/l/N1sGeOv5dh4+ElNUCSvMwP4p2U8XE
+MjhPP3UoIkQKC0mYE4oYJttnXrfIPovvOHkqUGBl2XYcNbbVwD41uuq1gP+mOkcW
+oaScHXBz/bOB0k1PJC8VjYCRfZsx+8IpZTcBMGY0Eij32jEy6T5moFL8DLBeM4S/
+0fchDro8qJ2arHQXbMnjdo+pXkQb5wS3yfHCZEFjikrHSSGuISYfX/81aXFhbuVC
+1pwzfLWPX8gV8eU3n9zrf1smiIWw81ujN7aBWi917w9gC6xwim0=
+
+------5EFD563634B646BB8C420E6DA8819BE6--
+

Added: jmeter/trunk/test/src/org/apache/jmeter/assertions/SMIMEAssertionTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/assertions/SMIMEAssertionTest.java?rev=1708223&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/SMIMEAssertionTest.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/SMIMEAssertionTest.java Mon Oct 12
20:10:37 2015
@@ -0,0 +1,172 @@
+package org.apache.jmeter.assertions;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.jmeter.samplers.SampleResult;
+
+/**
+ * Tests for the SMIMEAssertion.
+ * <p>
+ * 
+ * A signed email named {@code signed_email.eml} is needed to complete these
+ * tests. The one included was generated with the following script:
+ * 
+ * <pre>
+ * {@code
+ * # Create a key without a password
+ * openssl genrsa -out email.key 2048 -nodes
+ * 
+ * # Create a config for the certificate request
+ * cat > email.cnf <<EOF
+ * [req]
+ * prompt = no
+ * distinguished_name = dn
+ * req_extensions = ext
+ * 
+ * [dn]
+ * CN = alice example
+ * emailAddress = alice@a.example.com
+ * O = Example Ltd
+ * L = Wherever
+ * C = AU
+ * 
+ * [ext]
+ * subjectAltName = email:alice@a.example.com,email:bob@b.example.com,email:charlie@example.com,DNS:notused.example.com
+ * EOF
+ * 
+ * # Create a certificate request
+ * openssl req -new -config email.cnf -key email.key -out email.csr
+ * 
+ * cat > email.ext <<EOF
+ * subjectAltName = email:alice@a.example.com,email:bob@b.example.com,email:charlie@example.com
+ * EOF
+ * 
+ * # Self-Sign the request and add the subjectAltName
+ * openssl x509 -req -days 365 -in email.csr -signkey email.key -out email.pem -extfile email.ext
+ * 
+ * # Create a simple email text
+ * cat >email.txt <<EOF
+ * Content-type: text/plain
+ * 
+ * This was really written by me.
+ * EOF
+ * 
+ * # Create the smime with the generated key and the simple mail
+ * openssl smime -sign -from bob@b.example.com -to someone@example.com \
+ *               -subject "Signed Message" -signer email.pem \
+ *               -in email.txt -inkey email.key -out signed_email.eml
+ * }
+ * </pre>
+ * 
+ * If a new signed email is generated, the signer key and certificate will
+ * change, and thus the tests will have to be changed as well (serial number!).
+ */
+public class SMIMEAssertionTest extends TestCase {
+
+    private MimeMessage msg;
+    private SampleResult parent;
+
+    public void setUp() throws MessagingException, IOException {
+        Session mailSession = Session.getDefaultInstance(new Properties());
+        msg = new MimeMessage(mailSession, this.getClass().getResourceAsStream(
+                "signed_email.eml"));
+        parent = new SampleResult();
+        parent.sampleStart();
+        parent.addSubResult(createChildSample());
+    }
+
+    public void testSignature() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setVerifySignature(true);
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    public void testSignerEmail() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setSignerCheckConstraints(true);
+        testElement.setSignerEmail("bob@b.example.com");
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    public void testSignerSerial() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setSignerCheckConstraints(true);
+        testElement.setSignerSerial("0xc8c46f8fbf9ebea4");
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    public void testSignerSignerDN() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setSignerCheckConstraints(true);
+//        String signerDn = "CN=alice example, E=alice@a.example.com, O=Example Ltd, L=Wherever,
C=AU";
+        String signerDn = "C=AU, L=Wherever, O=Example Ltd, E=alice@a.example.com, CN=alice
example";
+        testElement
+                .setSignerDn(signerDn);
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    public void testSignerIssuerDN() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setSignerCheckConstraints(true);
+        String issuerDn = "C=AU, L=Wherever, O=Example Ltd, E=alice@a.example.com, CN=alice
example";
+        testElement
+                .setIssuerDn(issuerDn);
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    public void testSignerCert() {
+        SMIMEAssertionTestElement testElement = new SMIMEAssertionTestElement();
+        testElement.setSignerCheckConstraints(true);
+        testElement.setSignerCheckByFile(true);
+        testElement.setSignerCertFile(getClass().getResource("email.pem")
+                .getPath());
+        AssertionResult result = SMIMEAssertion.getResult(testElement, parent,
+                "Test");
+        assertFalse("Result should not be an error", result.isError());
+        assertFalse("Result should not fail: " + result.getFailureMessage(),
+                result.isFailure());
+    }
+
+    private SampleResult createChildSample() throws MessagingException,
+            IOException {
+        SampleResult child = new SampleResult();
+        child.setSampleLabel("Message " + msg.getMessageNumber());
+        child.setContentType(msg.getContentType());
+        child.setEncodingAndType(msg.getContentType());
+        ByteArrayOutputStream outbuf = new ByteArrayOutputStream();
+        msg.writeTo(outbuf);
+        child.setResponseData(outbuf.toByteArray());
+        child.setDataType(SampleResult.TEXT);
+        child.setResponseOK();
+        return child;
+    }
+
+}



Mime
View raw message