Merge lp:~marcustomlinson/unity-scopes-api/remove_oa_pub_sub into lp:unity-scopes-api/devel

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 268
Merged at revision: 505
Proposed branch: lp:~marcustomlinson/unity-scopes-api/remove_oa_pub_sub
Merge into: lp:unity-scopes-api/devel
Diff against target: 248 lines (+6/-132)
4 files modified
include/unity/scopes/OnlineAccountClient.h (+0/-2)
include/unity/scopes/internal/OnlineAccountClientImpl.h (+0/-7)
src/scopes/internal/OnlineAccountClientImpl.cpp (+2/-110)
test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp (+4/-13)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scopes-api/remove_oa_pub_sub
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+237811@code.launchpad.net

Commit message

1. Removed SIGNON_SESSION_DATA_UI_POLICY specification (use default always) as this is actually a bug in OA not scopes (Bug #1374394).

2. Removed pub-sub network for authentication as this is no longer needed when using the default UI policy.

3. Updated test.

To post a comment you must log in.
268. By Marcus Tomlinson

Reverted staging specific change

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/unity/scopes/OnlineAccountClient.h'
2--- include/unity/scopes/OnlineAccountClient.h 2014-10-06 07:53:41 +0000
3+++ include/unity/scopes/OnlineAccountClient.h 2014-10-09 16:20:29 +0000
4@@ -80,8 +80,6 @@
5 {
6 RunInExternalMainLoop, ///< An external main loop already exists and is running.
7 CreateInternalMainLoop, ///< An external main loop does not exist.
8- RunInExternalUiMainLoop, ///< An external UI main loop exists and is running (Intended for
9- /// shell use only. A scope should not be running a UI main loop).
10 };
11
12 /**
13
14=== modified file 'include/unity/scopes/internal/OnlineAccountClientImpl.h'
15--- include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-10-06 07:53:41 +0000
16+++ include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-10-09 16:20:29 +0000
17@@ -19,7 +19,6 @@
18 #ifndef UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H
19 #define UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H
20
21-#include <unity/scopes/internal/MiddlewareBase.h>
22 #include <unity/scopes/OnlineAccountClient.h>
23
24 #include <libaccounts-glib/accounts-glib.h>
25@@ -88,7 +87,6 @@
26
27 std::shared_ptr<AgManager> manager();
28 std::string service_name();
29- OnlineAccountClient::MainLoopSelect main_loop_select();
30 std::shared_ptr<GMainContext> main_loop_context();
31
32 void callback(AccountInfo const* info, std::string const& error = "");
33@@ -119,12 +117,7 @@
34 std::shared_ptr<AgManager> manager_;
35 std::map<AgAccountId, std::shared_ptr<AccountInfo>> accounts_;
36
37- MiddlewareBase::SPtr mw_;
38- MWPublisher::UPtr auth_publisher_;
39- MWSubscriber::UPtr auth_subscriber_;
40-
41 void main_loop_thread();
42- void auth_callback(std::string const& details_json);
43 };
44
45 } // namespace internal
46
47=== modified file 'src/scopes/internal/OnlineAccountClientImpl.cpp'
48--- src/scopes/internal/OnlineAccountClientImpl.cpp 2014-10-06 07:53:41 +0000
49+++ src/scopes/internal/OnlineAccountClientImpl.cpp 2014-10-09 16:20:29 +0000
50@@ -18,10 +18,6 @@
51
52 #include <unity/scopes/internal/OnlineAccountClientImpl.h>
53
54-#include <unity/scopes/internal/JsonCppNode.h>
55-#include <unity/scopes/internal/MiddlewareFactory.h>
56-#include <unity/scopes/internal/RuntimeConfig.h>
57-#include <unity/scopes/internal/RuntimeImpl.h>
58 #include <unity/UnityExceptions.h>
59
60 #include <iostream>
61@@ -93,40 +89,6 @@
62 return service_status;
63 }
64
65-static std::string details_to_json(OnlineAccountClient::ServiceStatus const& details)
66-{
67- VariantMap vm;
68- vm["account_id"] = details.account_id;
69- vm["service_enabled"] = details.service_enabled;
70- vm["service_authenticated"] = details.service_authenticated;
71- vm["client_id"] = details.client_id;
72- vm["client_secret"] = details.client_secret;
73- vm["access_token"] = details.access_token;
74- vm["token_secret"] = details.token_secret;
75- vm["error"] = details.error;
76-
77- Variant var(vm);
78- JsonCppNode node(var);
79- return node.to_json_string();
80-}
81-
82-static OnlineAccountClient::ServiceStatus json_to_details(std::string const& json)
83-{
84- OnlineAccountClient::ServiceStatus details;
85- JsonCppNode node(json);
86-
87- details.account_id = node.get_node("account_id")->as_int();
88- details.service_enabled = node.get_node("service_enabled")->as_bool();
89- details.service_authenticated = node.get_node("service_authenticated")->as_bool();
90- details.client_id = node.get_node("client_id")->as_string();
91- details.client_secret = node.get_node("client_secret")->as_string();
92- details.access_token = node.get_node("access_token")->as_string();
93- details.token_secret = node.get_node("token_secret")->as_string();
94- details.error = node.get_node("error")->as_string();
95-
96- return details;
97-}
98-
99 static void clear_session(AccountInfo* info)
100 {
101 if (info->session)
102@@ -198,24 +160,8 @@
103 }
104
105 // Get authorization parameters then attempt to signon
106- GVariantBuilder builder;
107- g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
108-
109- if (info->account_client->main_loop_select() == OnlineAccountClient::RunInExternalUiMainLoop)
110- {
111- g_variant_builder_add(&builder, "{sv}",
112- SIGNON_SESSION_DATA_UI_POLICY,
113- g_variant_new_int32(SIGNON_POLICY_DEFAULT)); // LCOV_EXCL_LINE
114- }
115- else
116- {
117- g_variant_builder_add(&builder, "{sv}",
118- SIGNON_SESSION_DATA_UI_POLICY,
119- g_variant_new_int32(SIGNON_POLICY_NO_USER_INTERACTION));
120- }
121-
122 info->auth_params.reset(
123- g_variant_ref_sink(ag_auth_data_get_login_parameters(auth_data.get(), g_variant_builder_end(&builder))), free_variant);
124+ g_variant_ref_sink(ag_auth_data_get_login_parameters(auth_data.get(), nullptr)), free_variant);
125
126 // Start signon process
127 signon_auth_session_process_async(info->session.get(),
128@@ -290,25 +236,6 @@
129 , main_loop_select_(main_loop_select)
130 , main_loop_is_running_(main_loop_select != OnlineAccountClient::CreateInternalMainLoop)
131 {
132- // Set up authentication pub/sub
133- std::string oa_id = provider_name + ":" + service_type + ":" + service_name;
134- RuntimeImpl::UPtr rt = RuntimeImpl::create(oa_id);
135- MiddlewareFactory mw_factory(rt.get());
136- RuntimeConfig rt_config("");
137-
138- mw_ = mw_factory.create(oa_id, rt_config.default_middleware(), rt_config.default_middleware_configfile());
139- if (main_loop_select == OnlineAccountClient::RunInExternalUiMainLoop)
140- {
141- // If this client was created by the shell, set up as the publisher
142- auth_publisher_ = mw_->create_publisher(oa_id);
143- }
144- else
145- {
146- // If this client was created by a scope, set up as a subscriber
147- auth_subscriber_ = mw_->create_subscriber(oa_id);
148- auth_subscriber_->message_received().connect(std::bind(&OnlineAccountClientImpl::auth_callback, this, std::placeholders::_1));
149- }
150-
151 // If we are responsible for the main loop
152 if (main_loop_select_ == OnlineAccountClient::CreateInternalMainLoop)
153 {
154@@ -576,11 +503,6 @@
155 return service_name_;
156 }
157
158-OnlineAccountClient::MainLoopSelect OnlineAccountClientImpl::main_loop_select()
159-{
160- return main_loop_select_;
161-}
162-
163 std::shared_ptr<GMainContext> OnlineAccountClientImpl::main_loop_context()
164 {
165 return main_loop_context_;
166@@ -589,14 +511,9 @@
167 void OnlineAccountClientImpl::callback(AccountInfo const* info, std::string const& error)
168 {
169 std::lock_guard<std::mutex> lock(callback_mutex_);
170- auto service_status = info_to_details(info, error);
171- if (service_status.service_authenticated && auth_publisher_)
172- {
173- auth_publisher_->send_message(details_to_json(service_status));
174- }
175 if (callback_)
176 {
177- callback_(service_status);
178+ callback_(info_to_details(info, error));
179 }
180 }
181
182@@ -667,31 +584,6 @@
183 // LCOV_EXCL_STOP
184 }
185
186-void OnlineAccountClientImpl::auth_callback(std::string const& details_json)
187-{
188- OnlineAccountClient::ServiceStatus details = json_to_details(details_json);
189-
190- // Update account info
191- {
192- std::lock_guard<std::mutex> lock(mutex_);
193- auto info_it = accounts_.find(details.account_id);
194- if (info_it == accounts_.end())
195- {
196- return;
197- }
198- auto info = info_it->second;
199-
200- GVariantDict dict;
201- g_variant_dict_init(&dict, nullptr);
202- g_variant_dict_insert(&dict, "AccessToken", "s", details.access_token.c_str());
203- g_variant_dict_insert(&dict, "TokenSecret", "s", details.token_secret.c_str());
204- info->session_data.reset(g_variant_ref_sink(g_variant_dict_end(&dict)), free_variant);
205- }
206-
207- std::lock_guard<std::mutex> lock(callback_mutex_);
208- callback_(details);
209-}
210-
211 } // namespace internal
212
213 } // namespace scopes
214
215=== modified file 'test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp'
216--- test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-10-09 01:16:53 +0000
217+++ test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-10-09 16:20:29 +0000
218@@ -521,17 +521,8 @@
219 EXPECT_TRUE(statuses[0].service_enabled);
220 }
221
222-TEST_F(OnlineAccountClientTestNoMainLoop, pub_sub_authentication)
223+TEST_F(OnlineAccountClientTestNoMainLoop, authentication)
224 {
225- std::shared_ptr<OnlineAccountClient> shell_oa_client;
226- shell_oa_client.reset(new OnlineAccountClient("TestService", "sharing", "TestProvider", OnlineAccountClient::RunInExternalUiMainLoop));
227-
228- std::shared_ptr<OnlineAccountClient> scope_oa_client;
229- scope_oa_client.reset(new OnlineAccountClient("TestService", "sharing", "TestProvider", OnlineAccountClient::RunInExternalMainLoop));
230-
231- create_account();
232- scope_oa_client->refresh_service_statuses();
233-
234 std::shared_ptr<AccountInfo> info(new AccountInfo);
235 info->account_id = 1;
236 info->service_enabled = true;
237@@ -550,9 +541,9 @@
238 info->session_data.reset(g_variant_ref_sink(g_variant_dict_end(&dict)), safe_g_variant_free_);
239 }
240
241- // Invoke callback on shell_oa_client which should invoke a callback on scope_oa_client via pub/sub
242- scope_oa_client->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_auth, this, std::placeholders::_1));
243- invoke_callback(shell_oa_client, info.get(), "not really an error, but just to test");
244+ // Manually invoke the callback with a valid access token, which should result in service_authenticated = true
245+ oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_auth, this, std::placeholders::_1));
246+ invoke_callback(oa_client(), info.get(), "not really an error, but just to test");
247 wait_for_service_update();
248 }
249

Subscribers

People subscribed via source and target branches

to all changes: