Merge lp:~alecu/unity-lens-music/sign-opened-urls into lp:unity-lens-music

Proposed by Alejandro J. Cura
Status: Needs review
Proposed branch: lp:~alecu/unity-lens-music/sign-opened-urls
Merge into: lp:unity-lens-music
Diff against target: 89 lines (+48/-5)
3 files modified
src/musicstore-scope.vala (+13/-5)
src/ubuntuone-webservices.vala (+14/-0)
tests/unit/test-ubuntuone-purchases.vala (+21/-0)
To merge this branch: bzr merge lp:~alecu/unity-lens-music/sign-opened-urls
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+174089@code.launchpad.net

Commit message

* Use credentials from keyring to sign urls for the Ubuntu One website

Description of the change

* Use credentials from keyring to sign urls for the Ubuntu One website

To post a comment you must log in.
149. By Alejandro J. Cura

Open it anyway if no credentials available

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
150. By Alejandro J. Cura

remove debugging from test

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

150. By Alejandro J. Cura

remove debugging from test

149. By Alejandro J. Cura

Open it anyway if no credentials available

148. By Alejandro J. Cura

Only use the autologin urls for ubuntu one prefixed urls

147. By Alejandro J. Cura

Use credentials to log into Ubuntu One website

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/musicstore-scope.vala'
2--- src/musicstore-scope.vala 2013-06-20 13:23:37 +0000
3+++ src/musicstore-scope.vala 2013-07-11 12:27:27 +0000
4@@ -89,11 +89,19 @@
5 public Unity.ActivationResponse open_uri (string uri)
6 {
7 /* launch the music store streaming client or the webstore or whatevz */
8- try {
9- AppInfo.launch_default_for_uri (uri, null);
10- } catch (GLib.Error e) {
11- warning ("Failed to open uri %s. %s", uri, e.message);
12- }
13+ purchase_service.build_logged_url.begin(uri, (obj, res) => {
14+ try {
15+ var full_url = purchase_service.build_logged_url.end (res);
16+ if (uri.has_prefix ("https://one.ubuntu.com/") || uri.has_prefix ("http://musicsearch.ubuntu.com/")) {
17+ AppInfo.launch_default_for_uri (full_url, null);
18+ } else {
19+ AppInfo.launch_default_for_uri (uri, null);
20+ }
21+ } catch (PurchaseError e) {
22+ debug ("Can't fetch credentials: %s to open url: %s", e.message, uri);
23+ AppInfo.launch_default_for_uri (uri, null);
24+ }
25+ });
26 return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
27 }
28
29
30=== modified file 'src/ubuntuone-webservices.vala'
31--- src/ubuntuone-webservices.vala 2013-05-29 15:04:08 +0000
32+++ src/ubuntuone-webservices.vala 2013-07-11 12:27:27 +0000
33@@ -336,5 +336,19 @@
34 purchase_with_default_payment (album_id, purchase_token);
35 debug ("purchase completed.");
36 }
37+
38+ public virtual async string build_logged_url (string dest_url) throws PurchaseError
39+ {
40+ const string U1_OAUTH_LOGIN = "https://one.ubuntu.com/api/1.0/from_oauth/?next=";
41+ if (!got_credentials ()) {
42+ yield fetch_credentials();
43+ }
44+ if (got_credentials ()) {
45+ var full_url = U1_OAUTH_LOGIN + Soup.URI.encode(dest_url, null);
46+ return oauth_sign(full_url);
47+ } else {
48+ return dest_url;
49+ }
50+ }
51 }
52 }
53
54=== modified file 'tests/unit/test-ubuntuone-purchases.vala'
55--- tests/unit/test-ubuntuone-purchases.vala 2013-05-29 15:04:08 +0000
56+++ tests/unit/test-ubuntuone-purchases.vala 2013-07-11 12:27:27 +0000
57@@ -128,6 +128,7 @@
58 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseDefaultPaymentBroken", test_purchase_with_default_payment_broken_json);
59 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseConnectionFails", test_purchase_with_default_payment_connection_fails);
60 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseDefaultPaymentFails", test_purchase_with_default_payment_fails);
61+ Test.add_data_func ("/Unit/PurchaseChecker/SignUbuntuoneUrls", test_sign_ubuntuone_urls);
62
63 return Test.run ();
64 }
65@@ -716,4 +717,24 @@
66 assert (e is PurchaseError.PURCHASE_ERROR);
67 }
68 }
69+
70+ private static void test_sign_ubuntuone_urls ()
71+ {
72+ string dest = "https://one.ubuntu.com/contacts/";
73+ var purchase_service = new BaseTestPurchaseService ();
74+ string full_url = null;
75+
76+ MainLoop mainloop = new MainLoop ();
77+ purchase_service.build_logged_url.begin(dest, (obj, res) => {
78+ mainloop.quit ();
79+ try {
80+ full_url = purchase_service.build_logged_url.end (res);
81+ } catch (PurchaseError e) {
82+ warning ("Can't fetch credentials: %s", e.message);
83+ assert_not_reached ();
84+ }
85+ });
86+ assert (run_with_timeout (mainloop, 1000));
87+ assert (full_url.contains("oauth_consumer_key"));
88+ }
89 }

Subscribers

People subscribed via source and target branches

to all changes: