Juan Lang : crypt32: Add more tests for CertCompareCertificateName.

Alexandre Julliard julliard at winehq.org
Tue Nov 17 09:28:18 CST 2009


Module: wine
Branch: master
Commit: 4a948fa92908b254b036a40c0c2dae5fb4bde06f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4a948fa92908b254b036a40c0c2dae5fb4bde06f

Author: Juan Lang <juan.lang at gmail.com>
Date:   Mon Nov 16 11:48:46 2009 -0800

crypt32: Add more tests for CertCompareCertificateName.

---

 dlls/crypt32/tests/cert.c |   60 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index e1c8262..5463641 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -2541,6 +2541,29 @@ static void testGetValidUsages(void)
     CertFreeCertificateContext(contexts[2]);
 }
 
+static BYTE cn[] = {
+0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,
+0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67 };
+static BYTE cnWithLeadingSpace[] = {
+0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x20,0x4a,
+0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67 };
+static BYTE cnWithTrailingSpace[] = {
+0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
+0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x20 };
+static BYTE cnWithIntermediateSpace[] = {
+0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
+0x61,0x6e,0x20,0x20,0x4c,0x61,0x6e,0x67 };
+static BYTE cnThenO[] = {
+0x30,0x2d,0x31,0x2b,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,
+0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,0x17,0x06,0x03,0x55,0x04,0x0a,0x13,
+0x10,0x54,0x68,0x65,0x20,0x57,0x69,0x6e,0x65,0x20,0x50,0x72,0x6f,0x6a,0x65,
+0x63,0x74 };
+static BYTE oThenCN[] = {
+0x30,0x2d,0x31,0x2b,0x30,0x10,0x06,0x03,0x55,0x04,0x0a,0x13,0x09,0x4a,0x75,
+0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,0x17,0x06,0x03,0x55,0x04,0x03,0x13,
+0x10,0x54,0x68,0x65,0x20,0x57,0x69,0x6e,0x65,0x20,0x50,0x72,0x6f,0x6a,0x65,
+0x63,0x74 };
+
 static void testCompareCertName(void)
 {
     static BYTE bogus[] = { 1, 2, 3, 4 };
@@ -2572,6 +2595,43 @@ static void testCompareCertName(void)
     blob2.cbData = sizeof(emptyPrime);
     ret = CertCompareCertificateName(0, &blob1, &blob2);
     ok(!ret, "Expected failure\n");
+    /* Tests to show that CertCompareCertificateName doesn't decode the name
+     * to remove spaces, or to do an order-independent comparison.
+     */
+    /* Compare CN="Juan Lang" with CN=" Juan Lang" */
+    blob1.pbData = cn;
+    blob1.cbData = sizeof(cn);
+    blob2.pbData = cnWithLeadingSpace;
+    blob2.cbData = sizeof(cnWithLeadingSpace);
+    ret = CertCompareCertificateName(0, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    ret = CertCompareCertificateName(X509_ASN_ENCODING, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    /* Compare CN="Juan Lang" with CN="Juan Lang " */
+    blob2.pbData = cnWithTrailingSpace;
+    blob2.cbData = sizeof(cnWithTrailingSpace);
+    ret = CertCompareCertificateName(0, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    ret = CertCompareCertificateName(X509_ASN_ENCODING, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    /* Compare CN="Juan Lang" with CN="Juan  Lang" */
+    blob2.pbData = cnWithIntermediateSpace;
+    blob2.cbData = sizeof(cnWithIntermediateSpace);
+    ret = CertCompareCertificateName(0, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    ret = CertCompareCertificateName(X509_ASN_ENCODING, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    /* Compare 'CN="Juan Lang", O="The Wine Project"' with
+     * 'O="The Wine Project", CN="Juan Lang"'
+     */
+    blob1.pbData = cnThenO;
+    blob1.cbData = sizeof(cnThenO);
+    blob2.pbData = oThenCN;
+    blob2.cbData = sizeof(oThenCN);
+    ret = CertCompareCertificateName(0, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
+    ret = CertCompareCertificateName(X509_ASN_ENCODING, &blob1, &blob2);
+    ok(!ret, "Expected failure\n");
 }
 
 static BYTE int1[] = { 0x88, 0xff, 0xff, 0xff };




More information about the wine-cvs mailing list