crypt32/tests: Always compare serialized stores in memory.

This commit is contained in:
Juan Lang 2010-05-24 14:21:28 -07:00 committed by Alexandre Julliard
parent 6451b9621e
commit 1d94702431
1 changed files with 38 additions and 62 deletions

View File

@ -277,29 +277,35 @@ static void testMemStore(void)
CertCloseStore(store1, 0); CertCloseStore(store1, 0);
} }
static void compareFile(LPCWSTR filename, const BYTE *pb, DWORD cb) static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb,
DWORD cb, BOOL todo)
{ {
HANDLE h;
BYTE buf[200];
BOOL ret; BOOL ret;
DWORD cbRead = 0, totalRead = 0; CRYPT_DATA_BLOB blob = { 0, NULL };
h = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, ret = CertSaveStore(store, X509_ASN_ENCODING, CERT_STORE_SAVE_AS_STORE,
FILE_ATTRIBUTE_NORMAL, NULL); CERT_STORE_SAVE_TO_MEMORY, &blob, 0);
if (h == INVALID_HANDLE_VALUE) ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
return; if (todo)
do { todo_wine
ret = ReadFile(h, buf, sizeof(buf), &cbRead, NULL); ok(blob.cbData == cb, "%s: expected size %d, got %d\n", name, cb,
if (ret && cbRead) blob.cbData);
{ else
ok(totalRead + cbRead <= cb, "Expected total count %d, see %d\n", ok(blob.cbData == cb, "%s: expected size %d, got %d\n", name, cb,
cb, totalRead + cbRead); blob.cbData);
ok(!memcmp(pb + totalRead, buf, cbRead), blob.pbData = HeapAlloc(GetProcessHeap(), 0, blob.cbData);
"Unexpected data in file\n"); if (blob.pbData)
totalRead += cbRead; {
} ret = CertSaveStore(store, X509_ASN_ENCODING, CERT_STORE_SAVE_AS_STORE,
} while (ret && cbRead); CERT_STORE_SAVE_TO_MEMORY, &blob, 0);
CloseHandle(h); ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
if (todo)
todo_wine
ok(!memcmp(pb, blob.pbData, cb), "%s: unexpected value\n", name);
else
ok(!memcmp(pb, blob.pbData, cb), "%s: unexpected value\n", name);
HeapFree(GetProcessHeap(), 0, blob.pbData);
}
} }
static const BYTE serializedStoreWithCert[] = { static const BYTE serializedStoreWithCert[] = {
@ -689,11 +695,10 @@ static void testCollectionStore(void)
GetLastError()); GetLastError());
ret = pCertControlStore(collection, 0, CERT_STORE_CTRL_COMMIT, NULL); ret = pCertControlStore(collection, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %d\n", ret); ok(ret, "CertControlStore failed: %d\n", ret);
compareStore(collection, "serialized store with cert",
serializedStoreWithCert, sizeof(serializedStoreWithCert), FALSE);
CertCloseStore(collection, 0); CertCloseStore(collection, 0);
compareFile(filename, serializedStoreWithCert,
sizeof(serializedStoreWithCert));
DeleteFileW(filename); DeleteFileW(filename);
} }
@ -1294,8 +1299,8 @@ static void testFileStore(void)
/* with commits enabled, commit is allowed */ /* with commits enabled, commit is allowed */
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL); ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %d\n", ret); ok(ret, "CertControlStore failed: %d\n", ret);
compareFile(filename, serializedStoreWithCert, compareStore(store, "serialized store with cert",
sizeof(serializedStoreWithCert)); serializedStoreWithCert, sizeof(serializedStoreWithCert), FALSE);
CertCloseStore(store, 0); CertCloseStore(store, 0);
} }
file = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, file = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@ -1311,9 +1316,10 @@ static void testFileStore(void)
ret = CertAddEncodedCRLToStore(store, X509_ASN_ENCODING, signedCRL, ret = CertAddEncodedCRLToStore(store, X509_ASN_ENCODING, signedCRL,
sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, NULL); sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError()); ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
compareStore(store, "serialized store with cert and CRL",
serializedStoreWithCertAndCRL, sizeof(serializedStoreWithCertAndCRL),
FALSE);
CertCloseStore(store, 0); CertCloseStore(store, 0);
compareFile(filename, serializedStoreWithCertAndCRL,
sizeof(serializedStoreWithCertAndCRL));
} }
DeleteFileW(filename); DeleteFileW(filename);
@ -1517,9 +1523,9 @@ static void testFileNameStore(void)
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL); bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
GetLastError()); GetLastError());
compareStore(store, "serialized store with cert",
serializedStoreWithCert, sizeof(serializedStoreWithCert), FALSE);
CertCloseStore(store, 0); CertCloseStore(store, 0);
compareFile(filename, serializedStoreWithCert,
sizeof(serializedStoreWithCert));
} }
store = CertOpenStore(CERT_STORE_PROV_FILENAME_W, 0, 0, store = CertOpenStore(CERT_STORE_PROV_FILENAME_W, 0, 0,
CERT_FILE_STORE_COMMIT_ENABLE_FLAG, filename); CERT_FILE_STORE_COMMIT_ENABLE_FLAG, filename);
@ -1529,9 +1535,10 @@ static void testFileNameStore(void)
ret = CertAddEncodedCRLToStore(store, X509_ASN_ENCODING, ret = CertAddEncodedCRLToStore(store, X509_ASN_ENCODING,
signedCRL, sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, NULL); signedCRL, sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError()); ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
compareStore(store, "serialized store with cert and CRL",
serializedStoreWithCertAndCRL, sizeof(serializedStoreWithCertAndCRL),
FALSE);
CertCloseStore(store, 0); CertCloseStore(store, 0);
compareFile(filename, serializedStoreWithCertAndCRL,
sizeof(serializedStoreWithCertAndCRL));
} }
DeleteFileW(filename); DeleteFileW(filename);
@ -2063,37 +2070,6 @@ static void testAddSerialized(void)
CertCloseStore(store, 0); CertCloseStore(store, 0);
} }
static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb,
DWORD cb, BOOL todo)
{
BOOL ret;
CRYPT_DATA_BLOB blob = { 0, NULL };
ret = CertSaveStore(store, X509_ASN_ENCODING, CERT_STORE_SAVE_AS_STORE,
CERT_STORE_SAVE_TO_MEMORY, &blob, 0);
ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
if (todo)
todo_wine
ok(blob.cbData == cb, "%s: expected size %d, got %d\n", name, cb,
blob.cbData);
else
ok(blob.cbData == cb, "%s: expected size %d, got %d\n", name, cb,
blob.cbData);
blob.pbData = HeapAlloc(GetProcessHeap(), 0, blob.cbData);
if (blob.pbData)
{
ret = CertSaveStore(store, X509_ASN_ENCODING, CERT_STORE_SAVE_AS_STORE,
CERT_STORE_SAVE_TO_MEMORY, &blob, 0);
ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
if (todo)
todo_wine
ok(!memcmp(pb, blob.pbData, cb), "%s: unexpected value\n", name);
else
ok(!memcmp(pb, blob.pbData, cb), "%s: unexpected value\n", name);
HeapFree(GetProcessHeap(), 0, blob.pbData);
}
}
static const BYTE serializedCertWithFriendlyName[] = { static const BYTE serializedCertWithFriendlyName[] = {
0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x57,0x00,0x69, 0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x57,0x00,0x69,
0x00,0x6e,0x00,0x65,0x00,0x54,0x00,0x65,0x00,0x73,0x00,0x74,0x00,0x00,0x00, 0x00,0x6e,0x00,0x65,0x00,0x54,0x00,0x65,0x00,0x73,0x00,0x74,0x00,0x00,0x00,