Merge lp:~dobey/unity-scope-click/send-device-id into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: Charles Kerr
Approved revision: 390
Merged at revision: 392
Proposed branch: lp:~dobey/unity-scope-click/send-device-id
Merge into: lp:unity-scope-click
Diff against target: 161 lines (+52/-5)
5 files modified
libclickscope/click/configuration.cpp (+22/-1)
libclickscope/click/configuration.h (+4/-1)
libclickscope/click/webclient.cpp (+4/-1)
libclickscope/click/webclient.h (+3/-1)
libclickscope/tests/test_configuration.cpp (+19/-1)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/send-device-id
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+278496@code.launchpad.net

Commit message

Set the device header on all requests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/configuration.cpp'
2--- libclickscope/click/configuration.cpp 2014-10-01 13:11:49 +0000
3+++ libclickscope/click/configuration.cpp 2015-11-24 19:28:37 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2014 Canonical Ltd.
7+ * Copyright (C) 2014-2015 Canonical Ltd.
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 3, as published
11@@ -30,6 +30,9 @@
12 #include <string>
13 #include <vector>
14
15+#include <QDBusInterface>
16+#include <QDBusReply>
17+#include <QDBusConnection>
18 #include <QDir>
19 #include <QProcess>
20 #include <QStringList>
21@@ -182,6 +185,24 @@
22 != FULL_LANG_CODES.end();
23 }
24
25+std::string Configuration::deviceIdFromWhoopsie()
26+{
27+ QDBusInterface iface("com.ubuntu.WhoopsiePreferences",
28+ "/com/ubuntu/WhoopsiePreferences",
29+ "com.ubuntu.WhoopsiePreferences",
30+ QDBusConnection::systemBus(), 0);
31+ QDBusReply<QString> reply = iface.call("GetIdentifier");
32+ auto value = reply.value();
33+
34+ return value.toStdString();
35+}
36+
37+std::string Configuration::get_device_id()
38+{
39+ static const std::string whoopsie_id {deviceIdFromWhoopsie()};
40+ return whoopsie_id;
41+}
42+
43 const std::vector<std::string> Configuration::get_dconf_strings(const std::string& schema, const std::string& key) const
44 {
45 if (!QGSettings::isSchemaInstalled(schema.c_str()))
46
47=== modified file 'libclickscope/click/configuration.h'
48--- libclickscope/click/configuration.h 2014-11-17 13:53:23 +0000
49+++ libclickscope/click/configuration.h 2015-11-24 19:28:37 +0000
50@@ -1,5 +1,5 @@
51 /*
52- * Copyright (C) 2014 Canonical Ltd.
53+ * Copyright (C) 2014-2015 Canonical Ltd.
54 *
55 * This program is free software: you can redistribute it and/or modify it
56 * under the terms of the GNU General Public License version 3, as published
57@@ -62,6 +62,8 @@
58 virtual std::string get_accept_languages();
59 static bool is_full_lang_code(const std::string& language);
60
61+ virtual std::string get_device_id();
62+
63 constexpr static const char* COREAPPS_SCHEMA {"com.canonical.Unity.ClickScope"};
64 constexpr static const char* COREAPPS_KEY {"coreApps"};
65
66@@ -70,6 +72,7 @@
67 protected:
68 virtual std::vector<std::string> list_folder(const std::string &folder, const std::string &pattern);
69 virtual std::string architectureFromDpkg();
70+ virtual std::string deviceIdFromWhoopsie();
71 virtual const std::vector<std::string> get_dconf_strings(const std::string& schema, const std::string& key) const;
72 static const std::vector<std::string>& get_default_core_apps() {
73 static std::vector<std::string> default_apps {
74
75=== modified file 'libclickscope/click/webclient.cpp'
76--- libclickscope/click/webclient.cpp 2014-10-17 17:07:31 +0000
77+++ libclickscope/click/webclient.cpp 2015-11-24 19:28:37 +0000
78@@ -1,5 +1,5 @@
79 /*
80- * Copyright (C) 2014 Canonical Ltd.
81+ * Copyright (C) 2014-2015 Canonical Ltd.
82 *
83 * This program is free software: you can redistribute it and/or modify it
84 * under the terms of the GNU General Public License version 3, as published
85@@ -119,6 +119,9 @@
86 responsePtr->setReply(reply);
87 };
88
89+ auto deviceId = Configuration().get_device_id();
90+ request->setRawHeader(DEVICE_ID_HEADER.c_str(), deviceId.data());
91+
92 if (sign && !impl->sso.isNull()) {
93 click::utils::SmartConnect sc(responsePtr.data());
94 sc.connect(impl->sso.data(), &click::CredentialsService::credentialsFound,
95
96=== modified file 'libclickscope/click/webclient.h'
97--- libclickscope/click/webclient.h 2014-10-01 15:27:44 +0000
98+++ libclickscope/click/webclient.h 2015-11-24 19:28:37 +0000
99@@ -1,5 +1,5 @@
100 /*
101- * Copyright (C) 2014 Canonical Ltd.
102+ * Copyright (C) 2014-2015 Canonical Ltd.
103 *
104 * This program is free software: you can redistribute it and/or modify it
105 * under the terms of the GNU General Public License version 3, as published
106@@ -52,6 +52,7 @@
107 const std::string ACCEPT_LANGUAGE_HEADER ="Accept-Language";
108 const std::string AUTHORIZATION_HEADER = "Authorization";
109 const std::string CONTENT_TYPE_HEADER = "Content-Type";
110+const std::string DEVICE_ID_HEADER = "X-Device-Id";
111
112 const std::string CONTENT_TYPE_JSON = "application/json";
113
114@@ -123,6 +124,7 @@
115 const std::string& data = "",
116 const CallParams& params = CallParams());
117 void setCredentialsService(const QSharedPointer<click::CredentialsService>& sso);
118+
119 private:
120 struct Private;
121 QScopedPointer<Private> impl;
122
123=== modified file 'libclickscope/tests/test_configuration.cpp'
124--- libclickscope/tests/test_configuration.cpp 2014-11-17 14:59:03 +0000
125+++ libclickscope/tests/test_configuration.cpp 2015-11-24 19:28:37 +0000
126@@ -1,5 +1,5 @@
127 /*
128- * Copyright (C) 2014 Canonical Ltd.
129+ * Copyright (C) 2014-2015 Canonical Ltd.
130 *
131 * This program is free software: you can redistribute it and/or modify it
132 * under the terms of the GNU General Public License version 3, as published
133@@ -42,6 +42,7 @@
134 class FakeConfiguration : public click::Configuration
135 {
136 public:
137+ MOCK_METHOD0(deviceIdFromWhoopsie, std::string());
138 MOCK_METHOD2(list_folder, std::vector<std::string>(
139 const std::string& folder, const std::string& pattern));
140 MOCK_CONST_METHOD2(get_dconf_strings, const std::vector<std::string>(const std::string& schema, const std::string& key));
141@@ -276,3 +277,20 @@
142 EXPECT_EQ("USD", Configuration().get_currency());
143 ASSERT_EQ(unsetenv(Configuration::CURRENCY_ENVVAR), 0);
144 }
145+
146+TEST(Configuration, getDeviceIdCached)
147+{
148+ using namespace ::testing;
149+ FakeConfiguration c;
150+ FakeConfiguration d;
151+
152+ const char* expected = "HAL-9000";
153+
154+ EXPECT_CALL(c, deviceIdFromWhoopsie()).Times(1).
155+ WillOnce(Return(expected));
156+
157+ EXPECT_EQ(expected, c.get_device_id());
158+
159+ EXPECT_CALL(d, deviceIdFromWhoopsie()).Times(0);
160+ EXPECT_EQ(expected, d.get_device_id());
161+}

Subscribers

People subscribed via source and target branches

to all changes: