VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/net/tstSSLCertDownloads.cpp@ 58847

Last change on this file since 58847 was 58847, checked in by vboxsync, 9 years ago

header fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: tstSSLCertDownloads.cpp 58847 2015-11-25 11:24:25Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Simple cURL testcase.
4 */
5
6/*
7 * Copyright (C) 2012-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <iprt/err.h>
23#include <iprt/mem.h>
24#include <iprt/test.h>
25
26
27/*
28 * It's a private class we're testing, so we must include the source.
29 * Better than emedding the testcase as public function in the class.
30 */
31#include "UINetworkReply.cpp"
32
33
34
35/*static*/ void UINetworkReplyPrivateThread::testIt(RTTEST hTest)
36{
37 NOREF(hTest);
38 QUrl Dummy1;
39 UserDictionary Dummy2;
40 UINetworkReplyPrivateThread TestObj(UINetworkRequestType_GET, Dummy1, Dummy2);
41
42 /*
43 * Do the first setup things that UINetworkReplyPrivateThread::run.
44 */
45 RTTESTI_CHECK_RC(RTHttpCreate(&TestObj.m_hHttp), VINF_SUCCESS);
46 RTTESTI_CHECK_RC(TestObj.applyProxyRules(), VINF_SUCCESS);
47
48 /*
49 * Duplicate much of downloadMissingCertificates, but making sure we
50 * can both get the certificate from the ZIP file(s) and the first
51 * PEM URL (as the rest are currently busted).
52 */
53 RTTestISub("SSL Cert downloading");
54 RTCRSTORE hStore;
55 RTTESTI_CHECK_RC(RTCrStoreCreateInMem(&hStore, RT_ELEMENTS(s_aCerts) * 2), VINF_SUCCESS);
56
57 int rc;
58
59 /* ZIP files: */
60 for (uint32_t iUrl = 0; iUrl < RT_ELEMENTS(s_apszRootsZipUrls); iUrl++)
61 {
62 RTTestIPrintf(RTTESTLVL_ALWAYS, "URL: %s\n", s_apszRootsZipUrls[iUrl]);
63 void *pvRootsZip;
64 size_t cbRootsZip;
65 rc = RTHttpGetBinary(TestObj.m_hHttp, s_apszRootsZipUrls[iUrl], &pvRootsZip, &cbRootsZip);
66 if (RT_SUCCESS(rc))
67 {
68 for (uint32_t i = 0; i < RT_ELEMENTS(s_aCerts); i++)
69 {
70 CERTINFO const *pInfo = (CERTINFO const *)s_aCerts[i].pvUser;
71 if (pInfo->pszZipFile)
72 {
73 void *pvFile;
74 size_t cbFile;
75 RTTESTI_CHECK_RC_BREAK(RTZipPkzipMemDecompress(&pvFile, &cbFile, pvRootsZip, cbRootsZip, pInfo->pszZipFile),
76 VINF_SUCCESS);
77 RTTESTI_CHECK_RC(convertVerifyAndAddPemCertificateToStore(hStore, pvFile, cbFile, &TestObj.s_aCerts[i]),
78 VINF_SUCCESS);
79 RTMemFree(pvFile);
80 }
81 }
82 RTHttpFreeResponse(pvRootsZip);
83 }
84 else if ( rc != VERR_HTTP_PROXY_NOT_FOUND
85 && rc != VERR_HTTP_COULDNT_CONNECT)
86 RTTestIFailed("%Rrc on '%s'", rc, s_apszRootsZipUrls[iUrl]); /* code or link broken */
87 }
88
89 /* PEM files: */
90 for (uint32_t i = 0; i < RT_ELEMENTS(s_aCerts); i++)
91 {
92 uint32_t iUrl = 0; /* First URL must always work. */
93 UINetworkReplyPrivateThread::CERTINFO const *pInfo;
94 pInfo = (UINetworkReplyPrivateThread::CERTINFO const *)s_aCerts[i].pvUser;
95 if (pInfo->apszUrls[iUrl])
96 {
97 RTTestIPrintf(RTTESTLVL_ALWAYS, "URL: %s\n", pInfo->apszUrls[iUrl]);
98 void *pvResponse;
99 size_t cbResponse;
100 rc = RTHttpGetBinary(TestObj.m_hHttp, pInfo->apszUrls[iUrl], &pvResponse, &cbResponse);
101 if (RT_SUCCESS(rc))
102 {
103 RTTESTI_CHECK_RC_OK(convertVerifyAndAddPemCertificateToStore(hStore, pvResponse, cbResponse,
104 &TestObj.s_aCerts[i]));
105 RTHttpFreeResponse(pvResponse);
106 }
107 else if ( rc != VERR_HTTP_PROXY_NOT_FOUND
108 && rc != VERR_HTTP_COULDNT_CONNECT)
109 RTTestIFailed("%Rrc on '%s'", rc, pInfo->apszUrls[iUrl]); /* code or link broken */
110 }
111 }
112
113 RTTESTI_CHECK(RTCrStoreRelease(hStore) == 0);
114
115 /*
116 * Now check the gathering of certificates on the system doesn't crash.
117 */
118 RTTestISub("Refreshing certificates");
119
120 /* create an empty store and do the refresh operation, writing it to /dev/null. */
121 RTTESTI_CHECK_RC(RTCrStoreCreateInMem(&hStore, RT_ELEMENTS(s_aCerts) * 2), VINF_SUCCESS);
122 bool afFoundCerts[RT_ELEMENTS(s_aCerts)];
123 RT_ZERO(afFoundCerts);
124#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
125 RTTESTI_CHECK_RC_OK(TestObj.refreshCertificates(NIL_RTHTTP, &hStore, afFoundCerts, "nul"));
126#else
127 RTTESTI_CHECK_RC_OK(TestObj.refreshCertificates(NIL_RTHTTP, &hStore, afFoundCerts, "/dev/null"));
128#endif
129
130 /* Log how many certificates we found and require at least one. */
131 uint32_t cCerts = RTCrStoreCertCount(hStore);
132 RTTestIValue("certificates", cCerts, RTTESTUNIT_NONE);
133 RTTESTI_CHECK(cCerts > 0);
134
135 RTTESTI_CHECK(RTCrStoreRelease(hStore) == 0);
136
137 /*
138 * We're done.
139 */
140 //RTTESTI_CHECK_RC(RTHttpDestroy(TestObj.m_hHttp), VINF_SUCCESS);
141 RTHttpDestroy(TestObj.m_hHttp);
142 TestObj.m_hHttp = NIL_RTHTTP;
143}
144
145
146int main()
147{
148 RTTEST hTest;
149 RTEXITCODE rcExit = RTTestInitAndCreate("tstSSLCertDownloads", &hTest);
150 if (rcExit != RTEXITCODE_SUCCESS)
151 return rcExit;
152 RTTestBanner(hTest);
153
154 UINetworkReplyPrivateThread::testIt(hTest);
155
156 return RTTestSummaryAndDestroy(hTest);
157}
158
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette