Merge lp:~ted/pay-service/verify-after-purchase into lp:pay-service/14.10

Proposed by Ted Gould
Status: Merged
Approved by: dobey
Approved revision: 25
Merged at revision: 21
Proposed branch: lp:~ted/pay-service/verify-after-purchase
Merge into: lp:pay-service/14.10
Diff against target: 172 lines (+53/-27)
6 files modified
libpay/pay-package.h (+2/-1)
service/item-memory.cpp (+9/-15)
service/verification-curl.cpp (+15/-8)
tests/item-memory-tests.cpp (+15/-3)
tests/verification-curl-tests.cpp (+9/-0)
tests/verification-test.h (+3/-0)
To merge this branch: bzr merge lp:~ted/pay-service/verify-after-purchase
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+226728@code.launchpad.net

Commit message

Verify purchase status after running Purchase UI

Description of the change

This makes it so that we always verify the status after each time we run the UI so that we don't have to trust its return code. It also fixes some bugs found with multiple verify calls.

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
dobey (dobey) wrote :

Solves the hang I was seeing in my testing, and does result in verification when the payui exits regardless of exit code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libpay/pay-package.h'
2--- libpay/pay-package.h 2014-06-14 02:56:52 +0000
3+++ libpay/pay-package.h 2014-07-14 18:39:31 +0000
4@@ -33,7 +33,8 @@
5 * The states that an purchased item can be in.
6 */
7 typedef enum
8-{ /*< prefix=PAY_PACKAGE_ITEM_STATUS */
9+{
10+ /*< prefix=PAY_PACKAGE_ITEM_STATUS */
11 PAY_PACKAGE_ITEM_STATUS_UNKNOWN, /*< nick=unknown */
12 PAY_PACKAGE_ITEM_STATUS_VERIFYING, /*< nick=verifying */
13 PAY_PACKAGE_ITEM_STATUS_PURCHASED, /*< nick=purchased */
14
15=== modified file 'service/item-memory.cpp'
16--- service/item-memory.cpp 2014-05-30 12:50:42 +0000
17+++ service/item-memory.cpp 2014-07-14 18:39:31 +0000
18@@ -60,16 +60,16 @@
19
20 bool verify (void)
21 {
22- if (vitem != nullptr)
23- {
24- return true;
25- }
26 if (!vfactory->running())
27 {
28 return false;
29 }
30
31- vitem = vfactory->verifyItem(app, id);
32+ if (vitem == nullptr)
33+ {
34+ vitem = vfactory->verifyItem(app, id);
35+ }
36+
37 if (vitem == nullptr)
38 {
39 /* Uhg, failed */
40@@ -121,17 +121,11 @@
41
42 pitem->purchaseComplete.connect([this](Purchase::Item::Status status)
43 {
44- switch (status)
45+ /* Verifying on each time the purchase UI runs right now because
46+ we're not getting reliable status back from them. */
47+ if (!verify())
48 {
49- case Purchase::Item::PURCHASED:
50- setStatus(Item::Status::PURCHASED);
51- break;
52- case Purchase::Item::ERROR:
53- case Purchase::Item::NOT_PURCHASED:
54- default: /* Fall through, an error is same as status we don't know */
55- /* We know we were not purchased before, so let's stay that way */
56- setStatus(Item::Status::NOT_PURCHASED);
57- break;
58+ setStatus(Item::Status::NOT_PURCHASED);
59 }
60 return;
61 });
62
63=== modified file 'service/verification-curl.cpp'
64--- service/verification-curl.cpp 2014-07-10 21:11:03 +0000
65+++ service/verification-curl.cpp 2014-07-14 18:39:31 +0000
66@@ -87,25 +87,32 @@
67
68 ~CurlItem (void)
69 {
70+ stopThread();
71+
72+ curl_easy_cleanup(handle);
73+
74+ if (curlHeaders != nullptr)
75+ {
76+ curl_slist_free_all (curlHeaders) ;
77+ curlHeaders = nullptr;
78+ }
79+ }
80+
81+ void stopThread (void)
82+ {
83 stop = true;
84
85 if (exec.joinable())
86 {
87 exec.join();
88 }
89-
90- curl_easy_cleanup(handle);
91-
92- if (curlHeaders != nullptr)
93- {
94- curl_slist_free_all (curlHeaders) ;
95- curlHeaders = nullptr;
96- }
97 }
98
99 virtual bool run (void)
100 {
101+ stopThread();
102 transferBuffer.clear();
103+ stop = false;
104
105 /* Do the execution in another thread so we can wait on the
106 network socket. */
107
108=== modified file 'tests/item-memory-tests.cpp'
109--- tests/item-memory-tests.cpp 2014-05-08 21:42:53 +0000
110+++ tests/item-memory-tests.cpp 2014-07-14 18:39:31 +0000
111@@ -180,12 +180,24 @@
112 usleep(50 * 1000);
113 EXPECT_EQ(Item::Item::Status::NOT_PURCHASED, item->getStatus());
114
115+ /* Assume the purchase UI is a liar */
116+ std::string fitemname("falsely-purchased-item");
117+ pfactory->test_setPurchase(appname, fitemname, true);
118+ auto fitem = store->getItem(appname, fitemname);
119+
120+ ASSERT_TRUE(fitem->verify());
121+ usleep(50 * 1000);
122+ ASSERT_TRUE(fitem->purchase());
123+ usleep(50 * 1000);
124+
125+ EXPECT_EQ(Item::Item::Status::NOT_PURCHASED, fitem->getStatus());
126+
127+ /* Legit purchase with verification */
128 std::string pitemname("purchased-item");
129 pfactory->test_setPurchase(appname, pitemname, true);
130+ vfactory->test_setPurchase(appname, pitemname, true);
131+
132 auto pitem = store->getItem(appname, pitemname);
133-
134- ASSERT_TRUE(pitem->verify());
135- usleep(50 * 1000);
136 ASSERT_TRUE(pitem->purchase());
137 usleep(50 * 1000);
138
139
140=== modified file 'tests/verification-curl-tests.cpp'
141--- tests/verification-curl-tests.cpp 2014-06-12 20:55:13 +0000
142+++ tests/verification-curl-tests.cpp 2014-07-14 18:39:31 +0000
143@@ -67,6 +67,15 @@
144
145 EXPECT_EQ(Verification::Item::Status::NOT_PURCHASED, status);
146
147+ /* Verify it can be run twice on the same item */
148+ status = Verification::Item::Status::ERROR;
149+
150+ ASSERT_TRUE(item->run());
151+ usleep(20 * 1000);
152+
153+ EXPECT_EQ(Verification::Item::Status::NOT_PURCHASED, status);
154+
155+ /* Bad App ID */
156 std::string badappid("bad");
157 auto baditem = verify->verifyItem(badappid, itemid);
158 ASSERT_NE(nullptr, item);
159
160=== modified file 'tests/verification-test.h'
161--- tests/verification-test.h 2014-05-05 18:51:08 +0000
162+++ tests/verification-test.h 2014-07-14 18:39:31 +0000
163@@ -38,6 +38,9 @@
164 }
165
166 virtual bool run (void) {
167+ if (t.joinable())
168+ t.join();
169+
170 t = std::thread([this]() {
171 /* Fastest website in the world */
172 usleep(10 * 1000);

Subscribers

People subscribed via source and target branches