Merge lp:~mardy/ubuntu-system-settings/rtm-lp1387734 into lp:ubuntu-system-settings/rtm-14.09

Proposed by Alberto Mardegan
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 975
Merged at revision: 975
Proposed branch: lp:~mardy/ubuntu-system-settings/rtm-lp1387734
Merge into: lp:ubuntu-system-settings/rtm-14.09
Diff against target: 170 lines (+72/-20)
2 files modified
plugins/security-privacy/trust-store-model.cpp (+19/-8)
tests/plugins/security-privacy/tst_trust_store_model.cpp (+53/-12)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings/rtm-lp1387734
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Approve
David Barth (community) Approve
Review via email: mp+247709@code.launchpad.net

Commit message

Security: ignore older requests when building the applications' grants

Also update the unit tests to ensure that we'll compute the same results no matter what the order of the rows is.

Description of the change

Security: ignore older requests when building the applications' grants

Also update the unit tests to ensure that we'll compute the same results no matter what the order of the rows is.

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :

Same as the vivid branch which was tested to work fine

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/security-privacy/trust-store-model.cpp'
--- plugins/security-privacy/trust-store-model.cpp 2014-09-29 11:02:13 +0000
+++ plugins/security-privacy/trust-store-model.cpp 2015-01-27 13:47:59 +0000
@@ -35,6 +35,11 @@
35class Application35class Application
36{36{
37public:37public:
38 struct GrantData {
39 bool granted{false};
40 std::chrono::system_clock::time_point timestamp; // initialized with the epoch
41 };
42
38 Application() {}43 Application() {}
3944
40 void setId(const QString &id) {45 void setId(const QString &id) {
@@ -125,19 +130,25 @@
125 }130 }
126131
127 void addRequest(const core::trust::Request &request) {132 void addRequest(const core::trust::Request &request) {
128 if (request.answer == core::trust::Request::Answer::granted) {133 GrantData &data = grantedFeatures[request.feature.value];
129 grantedFeatures.insert(request.feature.value);134 /* Ignore older requests */
130 } else {135 if (request.when <= data.timestamp) return;
131 grantedFeatures.remove(request.feature.value);136
137 data.granted = (request.answer == core::trust::Request::Answer::granted);
138 data.timestamp = request.when;
139 }
140
141 bool hasGrants() const {
142 Q_FOREACH(const GrantData &data, grantedFeatures) {
143 if (data.granted) return true;
132 }144 }
145 return false;
133 }146 }
134147
135 bool hasGrants() const { return !grantedFeatures.isEmpty(); }
136
137 QString id;148 QString id;
138 QString displayName;149 QString displayName;
139 QString iconName;150 QString iconName;
140 QSet<std::uint64_t> grantedFeatures;151 QHash<std::uint64_t,GrantData> grantedFeatures;
141};152};
142153
143class TrustStoreModelPrivate: public QObject154class TrustStoreModelPrivate: public QObject
@@ -355,7 +366,7 @@
355366
356 /* When disabling, we must disable all the features */367 /* When disabling, we must disable all the features */
357 if (!enabled) {368 if (!enabled) {
358 Q_FOREACH(std::int64_t feature, app.grantedFeatures) {369 Q_FOREACH(std::int64_t feature, app.grantedFeatures.keys()) {
359 /* Skip the default feature, we already disabled it */370 /* Skip the default feature, we already disabled it */
360 if (feature == core::trust::Request::default_feature) continue;371 if (feature == core::trust::Request::default_feature) continue;
361372
362373
=== modified file 'tests/plugins/security-privacy/tst_trust_store_model.cpp'
--- tests/plugins/security-privacy/tst_trust_store_model.cpp 2014-08-11 09:38:00 +0000
+++ tests/plugins/security-privacy/tst_trust_store_model.cpp 2015-01-27 13:47:59 +0000
@@ -32,11 +32,20 @@
32{32{
33struct Store: public core::trust::Store33struct Store: public core::trust::Store
34{34{
35 enum SortOrder {
36 Unsorted = 0,
37 TimeAsc,
38 TimeDesc,
39 LastSortOrder
40 };
41
35 std::string m_name;42 std::string m_name;
36 std::list<core::trust::Request> m_allRequests;43 std::list<core::trust::Request> m_allRequests;
44 SortOrder m_sortOrder;
37 static std::shared_ptr<mock::Store> m_instance;45 static std::shared_ptr<mock::Store> m_instance;
3846
39 Store()47 Store():
48 m_sortOrder(Unsorted)
40 {49 {
41 }50 }
4251
@@ -48,6 +57,22 @@
48 m_instance = store;57 m_instance = store;
49 }58 }
5059
60 void setSortOrder(SortOrder order) {
61 m_sortOrder = order;
62 }
63
64 static bool requestCompareTimeAsc(const core::trust::Request &left,
65 const core::trust::Request &right)
66 {
67 return left.when < right.when;
68 }
69
70 static bool requestCompareTimeDesc(const core::trust::Request &left,
71 const core::trust::Request &right)
72 {
73 return left.when > right.when;
74 }
75
51 struct Query: public core::trust::Store::Query76 struct Query: public core::trust::Store::Query
52 {77 {
53 mock::Store *m_store;78 mock::Store *m_store;
@@ -98,6 +123,12 @@
98 }123 }
99 }124 }
100 }125 }
126 // sort the results
127 if (m_store->m_sortOrder != Unsorted) {
128 m_requests.sort(m_store->m_sortOrder == TimeAsc ?
129 requestCompareTimeAsc : requestCompareTimeDesc);
130 }
131
101 m_it = m_requests.begin();132 m_it = m_requests.begin();
102 m_status = (m_it == m_requests.end()) ?133 m_status = (m_it == m_requests.end()) ?
103 core::trust::Store::Query::Status::eor :134 core::trust::Store::Query::Status::eor :
@@ -263,13 +294,17 @@
263 QFETCH(QStringList, expectedAppIds);294 QFETCH(QStringList, expectedAppIds);
264 QFETCH(QList<bool>, expectedAppGrants);295 QFETCH(QList<bool>, expectedAppGrants);
265296
297 std::chrono::system_clock::time_point requestTime =
298 std::chrono::system_clock::now();
299
266 for (int i = 0; i < appIds.count(); i++) {300 for (int i = 0; i < appIds.count(); i++) {
267 core::trust::Request r;301 core::trust::Request r;
268 r.from = appIds[i].toStdString();302 r.from = appIds[i].toStdString();
269 r.feature = core::trust::Feature(core::trust::Request::default_feature);303 r.feature = core::trust::Feature(core::trust::Request::default_feature);
270 r.answer = appGrants[i] ?304 r.answer = appGrants[i] ?
271 core::trust::Request::Answer::granted : core::trust::Request::Answer::denied;305 core::trust::Request::Answer::granted : core::trust::Request::Answer::denied;
272 r.when = std::chrono::system_clock::now();306 // make sure all times are monotonically increasing
307 r.when = requestTime + std::chrono::duration<int>(i);
273 m_store->add(r);308 m_store->add(r);
274 }309 }
275310
@@ -280,16 +315,22 @@
280 " serviceName: \"storeTest\"\n"315 " serviceName: \"storeTest\"\n"
281 "}",316 "}",
282 QUrl());317 QUrl());
283 QObject *object = component.create();318 // Test unsorted, sorted asc and sorted desc
284 QVERIFY(object != 0);319 for (int i_order = 0; i_order < mock::Store::LastSortOrder; i_order++) {
285 QAbstractListModel *model = qobject_cast<QAbstractListModel*>(object);320 m_store->setSortOrder(mock::Store::SortOrder(i_order));
286 QVERIFY(model != 0);321 QObject *object = component.create();
287322 QVERIFY(object != 0);
288 QCOMPARE(model->rowCount(), expectedAppIds.count());323 QAbstractListModel *model = qobject_cast<QAbstractListModel*>(object);
289324 QVERIFY(model != 0);
290 for (int i = 0; i < model->rowCount(); i++) {325
291 QCOMPARE(get(model, i, "applicationId").toString(), expectedAppIds[i]);326 QCOMPARE(model->rowCount(), expectedAppIds.count());
292 QCOMPARE(get(model, i, "granted").toBool(), expectedAppGrants[i]);327
328 for (int i = 0; i < model->rowCount(); i++) {
329 QCOMPARE(get(model, i, "applicationId").toString(), expectedAppIds[i]);
330 QCOMPARE(get(model, i, "granted").toBool(), expectedAppGrants[i]);
331 }
332
333 delete object;
293 }334 }
294}335}
295336

Subscribers

People subscribed via source and target branches