OpenCoverage

qnetworkaccessauthenticationmanager.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessauthenticationmanager.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11class QNetworkAuthenticationCache: private QVector<QNetworkAuthenticationCredential>,-
12 public QNetworkAccessCache::CacheableObject-
13{-
14public:-
15 QNetworkAuthenticationCache()-
16 {-
17 setExpires(false);-
18 setShareable(true);-
19 reserve(1);-
20 }
executed 315 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
315
21-
22 QNetworkAuthenticationCredential *findClosestMatch(const QString &domain)-
23 {-
24 iterator it = std::lower_bound(begin(), end(), domain);-
25 if (it == end()
it == end()Description
TRUEevaluated 346 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 366 times by 1 test
Evaluated by:
  • tst_QNetworkReply
&& !isEmpty()
!isEmpty()Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 315 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
31-366
26 --
executed 31 times by 1 test: --it;
Executed by:
  • tst_QNetworkReply
it;
executed 31 times by 1 test: --it;
Executed by:
  • tst_QNetworkReply
31
27 if (it == end()
it == end()Description
TRUEevaluated 315 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 397 times by 1 test
Evaluated by:
  • tst_QNetworkReply
|| !domain.startsWith(it->domain)
!domain.startsWith(it->domain)Description
TRUEnever evaluated
FALSEevaluated 397 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
0-397
28 return
executed 315 times by 2 tests: return 0;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
0;
executed 315 times by 2 tests: return 0;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
315
29 return
executed 397 times by 1 test: return &*it;
Executed by:
  • tst_QNetworkReply
&*it;
executed 397 times by 1 test: return &*it;
Executed by:
  • tst_QNetworkReply
397
30 }-
31-
32 void insert(const QString &domain, const QString &user, const QString &password)-
33 {-
34 QNetworkAuthenticationCredential *closestMatch = findClosestMatch(domain);-
35 if (closestMatch
closestMatchDescription
TRUEevaluated 358 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 315 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
&& closestMatch->domain == domain
closestMatch->domain == domainDescription
TRUEevaluated 358 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
) {
0-358
36-
37 closestMatch->user = user;-
38 closestMatch->password = password;-
39 }
executed 358 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
else {
358
40 QNetworkAuthenticationCredential newCredential;-
41 newCredential.domain = domain;-
42 newCredential.user = user;-
43 newCredential.password = password;-
44-
45 if (closestMatch
closestMatchDescription
TRUEnever evaluated
FALSEevaluated 315 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
0-315
46 QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential);
never executed: QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential);
0
47 else-
48 QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential);
executed 315 times by 2 tests: QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential);
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
315
49 }-
50 }-
51-
52 virtual void dispose() override { delete this; }
executed 315 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
315
53};-
54-
55-
56static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm)-
57{-
58 QUrl key;-
59-
60 switch (proxy.type()) {-
61 case
executed 78 times by 2 tests: case QNetworkProxy::Socks5Proxy:
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
QNetworkProxy::Socks5Proxy:
executed 78 times by 2 tests: case QNetworkProxy::Socks5Proxy:
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
78
62 key.setScheme(QLatin1String("proxy-socks5"));-
63 break;
executed 78 times by 2 tests: break;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
78
64-
65 case
executed 104 times by 2 tests: case QNetworkProxy::HttpProxy:
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
QNetworkProxy::HttpProxy:
executed 104 times by 2 tests: case QNetworkProxy::HttpProxy:
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
104
66 case
executed 21 times by 1 test: case QNetworkProxy::HttpCachingProxy:
Executed by:
  • tst_QNetworkReply
QNetworkProxy::HttpCachingProxy:
executed 21 times by 1 test: case QNetworkProxy::HttpCachingProxy:
Executed by:
  • tst_QNetworkReply
21
67 key.setScheme(QLatin1String("proxy-http"));-
68 break;
executed 125 times by 2 tests: break;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
125
69-
70 case
never executed: case QNetworkProxy::FtpCachingProxy:
QNetworkProxy::FtpCachingProxy:
never executed: case QNetworkProxy::FtpCachingProxy:
0
71 key.setScheme(QLatin1String("proxy-ftp"));-
72 break;
never executed: break;
0
73-
74 case
never executed: case QNetworkProxy::DefaultProxy:
QNetworkProxy::DefaultProxy:
never executed: case QNetworkProxy::DefaultProxy:
0
75 case
never executed: case QNetworkProxy::NoProxy:
QNetworkProxy::NoProxy:
never executed: case QNetworkProxy::NoProxy:
0
76-
77 return
never executed: return QByteArray();
QByteArray();
never executed: return QByteArray();
0
78-
79-
80-
81 }-
82-
83 if (key.scheme().isEmpty()
key.scheme().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 203 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
0-203
84-
85 return
never executed: return QByteArray();
QByteArray();
never executed: return QByteArray();
0
86-
87 key.setUserName(proxy.user());-
88 key.setHost(proxy.hostName());-
89 key.setPort(proxy.port());-
90 key.setFragment(realm);-
91 return
executed 203 times by 2 tests: return "auth:" + key.toEncoded();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
"auth:" + key.toEncoded();
executed 203 times by 2 tests: return "auth:" + key.toEncoded();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
203
92}-
93-
94-
95static inline QByteArray authenticationKey(const QUrl &url, const QString &realm)-
96{-
97 QUrl copy = url;-
98 copy.setFragment(realm);-
99 return
executed 932 times by 4 tests: return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery);
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
"auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery);
executed 932 times by 4 tests: return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery);
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
932
100}-
101-
102-
103-
104void QNetworkAccessAuthenticationManager::cacheProxyCredentials(const QNetworkProxy &p,-
105 const QAuthenticator *authenticator)-
106{-
107 ((!(authenticator)) ? qt_assert("authenticator",__FILE__,153) : qt_noop());-
108 ((!(p.type() != QNetworkProxy::DefaultProxy)) ? qt_assert("p.type() != QNetworkProxy::DefaultProxy",__FILE__,154) : qt_noop());-
109 ((!(p.type() != QNetworkProxy::NoProxy)) ? qt_assert("p.type() != QNetworkProxy::NoProxy",__FILE__,155) : qt_noop());-
110-
111 QMutexLocker mutexLocker(&mutex);-
112-
113 QString realm = authenticator->realm();-
114 QNetworkProxy proxy = p;-
115 proxy.setUser(authenticator->user());-
116-
117-
118 if (authenticator->password().isNull()
authenticator-...ord().isNull()Description
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 54 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
6-54
119 return;
executed 6 times by 2 tests: return;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
6
120-
121-
122 do {-
123-
124 do {-
125 QByteArray cacheKey = proxyAuthenticationKey(proxy, realm);-
126 if (cacheKey.isEmpty()
cacheKey.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 138 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
0-138
127 return;
never executed: return;
0
128-
129 QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache;-
130 auth->insert(QString(), authenticator->user(), authenticator->password());-
131 authenticationCache.addEntry(cacheKey, auth);-
132-
133 if (realm.isEmpty()
realm.isEmpty()Description
TRUEevaluated 108 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 30 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
) {
30-108
134 break;
executed 108 times by 2 tests: break;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
108
135 } else {-
136 realm.clear();-
137 }
executed 30 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
30
138 } while (true);-
139-
140 if (proxy.user().isEmpty()
proxy.user().isEmpty()Description
TRUEevaluated 54 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 54 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
54
141 break;
executed 54 times by 2 tests: break;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
54
142 else-
143 proxy.setUser(QString());
executed 54 times by 2 tests: proxy.setUser(QString());
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
54
144 } while (true);-
145}
executed 54 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
54
146-
147QNetworkAuthenticationCredential-
148QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(const QNetworkProxy &p,-
149 const QAuthenticator *authenticator)-
150{-
151 QNetworkProxy proxy = p;-
152 if (proxy.type() == QNetworkProxy::DefaultProxy
proxy.type() =...::DefaultProxyDescription
TRUEnever evaluated
FALSEevaluated 65 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
) {
0-65
153 proxy = QNetworkProxy::applicationProxy();-
154 }
never executed: end of block
0
155 if (!proxy.password().isEmpty()
!proxy.password().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 65 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
0-65
156 return
never executed: return QNetworkAuthenticationCredential();
QNetworkAuthenticationCredential();
never executed: return QNetworkAuthenticationCredential();
0
157-
158 QString realm;-
159 if (authenticator
authenticatorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 64 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
1-64
160 realm = authenticator->realm();
executed 1 time by 1 test: realm = authenticator->realm();
Executed by:
  • tst_QNetworkReply
1
161-
162 QMutexLocker mutexLocker(&mutex);-
163 QByteArray cacheKey = proxyAuthenticationKey(proxy, realm);-
164 if (cacheKey.isEmpty()
cacheKey.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 65 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
0-65
165 return
never executed: return QNetworkAuthenticationCredential();
QNetworkAuthenticationCredential();
never executed: return QNetworkAuthenticationCredential();
0
166 if (!authenticationCache.hasEntry(cacheKey)
!authenticatio...ntry(cacheKey)Description
TRUEevaluated 57 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
8-57
167 return
executed 57 times by 2 tests: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
QNetworkAuthenticationCredential();
executed 57 times by 2 tests: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
57
168-
169 QNetworkAuthenticationCache *auth =-
170 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));-
171 QNetworkAuthenticationCredential cred = *auth->findClosestMatch(QString());-
172 authenticationCache.releaseEntry(cacheKey);-
173-
174-
175 ((!(!cred.isNull())) ? qt_assert_x("QNetworkAccessManager", "Internal inconsistency: found a cache key for a proxy, but it's empty",-
176 __FILE__-
177 ,-
178 222-
179 ) : qt_noop())-
180 ;-
181 return
executed 8 times by 1 test: return cred;
Executed by:
  • tst_QNetworkReply
cred;
executed 8 times by 1 test: return cred;
Executed by:
  • tst_QNetworkReply
8
182}-
183-
184-
185-
186void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url,-
187 const QAuthenticator *authenticator)-
188{-
189 ((!(authenticator)) ? qt_assert("authenticator",__FILE__,231) : qt_noop());-
190 if (authenticator->isNull()
authenticator->isNull()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 273 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
3-273
191 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
3
192 QString domain = QString::fromLatin1("/");-
193 QString realm = authenticator->realm();-
194-
195 QMutexLocker mutexLocker(&mutex);-
196-
197-
198 QUrl copy = url;-
199 copy.setUserName(authenticator->user());-
200 do {-
201 QByteArray cacheKey = authenticationKey(copy, realm);-
202 if (authenticationCache.hasEntry(cacheKey)
authentication...ntry(cacheKey)Description
TRUEevaluated 358 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 177 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
177-358
203 QNetworkAuthenticationCache *auth =-
204 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));-
205 auth->insert(domain, authenticator->user(), authenticator->password());-
206 authenticationCache.releaseEntry(cacheKey);-
207 }
executed 358 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
else {
358
208 QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache;-
209 auth->insert(domain, authenticator->user(), authenticator->password());-
210 authenticationCache.addEntry(cacheKey, auth);-
211 }
executed 177 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
177
212-
213 if (copy.userName().isEmpty()
copy.userName().isEmpty()Description
TRUEevaluated 273 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 262 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
262-273
214 break;
executed 273 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
273
215 } else {-
216 copy.setUserName(QString());-
217 }
executed 262 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
262
218 } while (true);-
219}
executed 273 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
273
220QNetworkAuthenticationCredential-
221QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url,-
222 const QAuthenticator *authentication)-
223{-
224 if (!url.password().isEmpty()
!url.password().isEmpty()Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 397 times by 4 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
)
16-397
225 return
executed 16 times by 1 test: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QNetworkReply
QNetworkAuthenticationCredential();
executed 16 times by 1 test: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QNetworkReply
16
226-
227 QString realm;-
228 if (authentication
authenticationDescription
TRUEevaluated 89 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 308 times by 4 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
)
89-308
229 realm = authentication->realm();
executed 89 times by 1 test: realm = authentication->realm();
Executed by:
  • tst_QNetworkReply
89
230-
231 QByteArray cacheKey = authenticationKey(url, realm);-
232-
233 QMutexLocker mutexLocker(&mutex);-
234 if (!authenticationCache.hasEntry(cacheKey)
!authenticatio...ntry(cacheKey)Description
TRUEevaluated 366 times by 4 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
31-366
235 return
executed 366 times by 4 tests: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
QNetworkAuthenticationCredential();
executed 366 times by 4 tests: return QNetworkAuthenticationCredential();
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
366
236-
237 QNetworkAuthenticationCache *auth =-
238 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));-
239 QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path());-
240 QNetworkAuthenticationCredential ret;-
241 if (cred
credDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
)
0-31
242 ret = *cred;
executed 31 times by 1 test: ret = *cred;
Executed by:
  • tst_QNetworkReply
31
243 authenticationCache.releaseEntry(cacheKey);-
244 return
executed 31 times by 1 test: return ret;
Executed by:
  • tst_QNetworkReply
ret;
executed 31 times by 1 test: return ret;
Executed by:
  • tst_QNetworkReply
31
245}-
246-
247void QNetworkAccessAuthenticationManager::clearCache()-
248{-
249 authenticationCache.clear();-
250}
executed 646 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
646
251-
252-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9