Merge lp:~dobey/ubuntuone-credentials/qdatetime-valid into lp:ubuntuone-credentials

Proposed by dobey
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 145
Merged at revision: 146
Proposed branch: lp:~dobey/ubuntuone-credentials/qdatetime-valid
Merge into: lp:ubuntuone-credentials
Diff against target: 225 lines (+103/-13)
6 files modified
debian/libubuntuoneauth-2.0-0.symbols (+3/-2)
libubuntuoneauth/ssoservice.cpp (+2/-1)
libubuntuoneauth/tests/test_token.cpp (+56/-7)
libubuntuoneauth/tests/test_token.h (+6/-0)
libubuntuoneauth/token.cpp (+31/-3)
libubuntuoneauth/token.h (+5/-0)
To merge this branch: bzr merge lp:~dobey/ubuntuone-credentials/qdatetime-valid
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+233827@code.launchpad.net

Commit message

Add new ctor for Token to accept created/updated date strings.
Use the new ctor when creating the token from the REST response.
Turn the date string returned from the server into an ISO string for parsing.
Add more tests.

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Please refactor the parsing of the date to a function, and unit test the date parsing only on it.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
145. By dobey

Abstract ISO date conversion to separate method.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libubuntuoneauth-2.0-0.symbols'
2--- debian/libubuntuoneauth-2.0-0.symbols 2014-08-18 17:54:29 +0000
3+++ debian/libubuntuoneauth-2.0-0.symbols 2014-09-09 13:53:37 +0000
4@@ -106,8 +106,9 @@
5 (c++)"UbuntuOne::Token::buildTokenName()@Base" 13.08
6 (c++)"UbuntuOne::Token::toQuery()@Base" 13.08
7 (c++)"UbuntuOne::Token::fromQuery(QString)@Base" 13.08
8- (c++)"UbuntuOne::Token::Token(QString, QString, QString, QString)@Base" 13.08
9- (c++)"UbuntuOne::Token::Token(QString, QString, QString, QString)@Base" 13.08
10+ (c++)"UbuntuOne::Token::dateStringToISO(QString)@Base" 14.04+14.10.20140908
11+ (c++)"UbuntuOne::Token::Token(QString, QString, QString, QString)@Base" 13.08
12+ (c++)"UbuntuOne::Token::Token(QString, QString, QString, QString, QString, QString)@Base" 14.04+14.10.20140908
13 (c++)"UbuntuOne::Token::~Token()@Base" 13.08
14 (c++)"UbuntuOne::Token::created() const@Base" 14.04+14.10.20140818
15 (c++)"UbuntuOne::Token::updated() const@Base" 14.04+14.10.20140818
16
17=== modified file 'libubuntuoneauth/ssoservice.cpp'
18--- libubuntuoneauth/ssoservice.cpp 2014-08-12 20:38:39 +0000
19+++ libubuntuoneauth/ssoservice.cpp 2014-09-09 13:53:37 +0000
20@@ -145,7 +145,8 @@
21 void SSOService::tokenReceived(const OAuthTokenResponse& token)
22 {
23 Token realToken = Token(token.token_key(), token.token_secret(),
24- token.consumer_key(), token.consumer_secret());
25+ token.consumer_key(), token.consumer_secret(),
26+ token.date_created(), token.date_updated());
27 _keyring->storeToken(realToken, _tempEmail);
28 }
29
30
31=== modified file 'libubuntuoneauth/tests/test_token.cpp'
32--- libubuntuoneauth/tests/test_token.cpp 2014-08-15 18:44:37 +0000
33+++ libubuntuoneauth/tests/test_token.cpp 2014-09-09 13:53:37 +0000
34@@ -87,23 +87,72 @@
35 Token *token = Token::fromQuery("consumer_key=c&consumer_secret=c_s&name=Name+%40+hostname&token=t&token_secret=t_s&updated=2014-08-11+18%3A40%3A20.777777&created=2014-08-11+18%3A40%3A20.777777");
36 QVERIFY(token->isValid());
37 QString query = token->toQuery();
38- QVERIFY(query.contains("updated=2014-08-11+18%3A40%3A20.777777"));
39- QVERIFY(query.contains("created=2014-08-11+18%3A40%3A20.777777"));
40+ // Dates are converted to ISO when parsed.
41+ QVERIFY(query.contains("updated=2014-08-11T18:40:20Z"));
42+ QVERIFY(query.contains("created=2014-08-11T18:40:20Z"));
43 delete token;
44 }
45
46 void TestToken::testCreatedParsed()
47 {
48 Token *token = Token::fromQuery("consumer_key=c&consumer_secret=c_s&name=Name+%40+hostname&token=t&token_secret=t_s&updated=2014-08-11+18%3A40%3A20.777777&created=2014-08-11+18%3A40%3A20.777777");
49- unsigned int expected = 4294967295;
50- QCOMPARE(token->updated().toTime_t(), expected);
51+ unsigned int expected = 1407782420;
52+ QVERIFY(token->created().isValid());
53+ QCOMPARE(token->created().toTime_t(), expected);
54 delete token;
55 }
56
57 void TestToken::testUpdatedParsed()
58 {
59 Token *token = Token::fromQuery("consumer_key=c&consumer_secret=c_s&name=Name+%40+hostname&token=t&token_secret=t_s&updated=2014-08-11+18%3A40%3A20.777777&created=2014-08-11+18%3A40%3A20.777777");
60- unsigned int expected = 4294967295;
61- QCOMPARE(token->updated().toTime_t(), expected);
62- delete token;
63+ unsigned int expected = 1407782420;
64+ QVERIFY(token->updated().isValid());
65+ QCOMPARE(token->updated().toTime_t(), expected);
66+ delete token;
67+}
68+
69+void TestToken::testCreatedMissing()
70+{
71+ Token *token = Token::fromQuery("consumer_key=c&consumer_secret=c_s&name=Name+%40+hostname&token=t&token_secret=t_s");
72+ QVERIFY(token->isValid());
73+ QVERIFY(!token->created().isValid());
74+ QCOMPARE(token->created().toTime_t(), UINT_MAX);
75+ delete token;
76+}
77+
78+void TestToken::testUpdatedMissing()
79+{
80+ Token *token = Token::fromQuery("consumer_key=c&consumer_secret=c_s&name=Name+%40+hostname&token=t&token_secret=t_s");
81+ QVERIFY(token->isValid());
82+ QVERIFY(!token->updated().isValid());
83+ QCOMPARE(token->updated().toTime_t(), UINT_MAX);
84+ delete token;
85+}
86+
87+void TestToken::testNewWithDates()
88+{
89+ Token *token = new Token("token", "t_secret", "consumer", "c_secret",
90+ "2014-08-11+18%3A40%3A20.777777",
91+ "2014-08-11T18:40:20Z");
92+ unsigned int expected = 1407782420;
93+
94+ QVERIFY(token->isValid());
95+ QVERIFY(token->created().isValid());
96+ QCOMPARE(token->created().toTime_t(), expected);
97+ QVERIFY(token->updated().isValid());
98+ QCOMPARE(token->updated().toTime_t(), expected);
99+ delete token;
100+}
101+
102+void TestToken::testSSODateToISO()
103+{
104+ QString in_date{"2014-08-11+18%3A40%3A20.777777"};
105+ QString expected{"2014-08-11T18:40:20Z"};
106+ QCOMPARE(Token::dateStringToISO(in_date), expected);
107+}
108+
109+void TestToken::testISODateToISO()
110+{
111+ QString in_date{"2014-08-11T18:40:20Z"};
112+ QCOMPARE(Token::dateStringToISO(in_date), in_date);
113 }
114
115=== modified file 'libubuntuoneauth/tests/test_token.h'
116--- libubuntuoneauth/tests/test_token.h 2014-08-15 18:44:37 +0000
117+++ libubuntuoneauth/tests/test_token.h 2014-09-09 13:53:37 +0000
118@@ -44,6 +44,12 @@
119 void testTimesCached();
120 void testCreatedParsed();
121 void testUpdatedParsed();
122+ void testCreatedMissing();
123+ void testUpdatedMissing();
124+ void testNewWithDates();
125+
126+ void testSSODateToISO();
127+ void testISODateToISO();
128 };
129
130 #endif /* _TEST_TOKEN_H_ */
131
132=== modified file 'libubuntuoneauth/token.cpp'
133--- libubuntuoneauth/token.cpp 2014-08-15 18:44:37 +0000
134+++ libubuntuoneauth/token.cpp 2014-09-09 13:53:37 +0000
135@@ -46,6 +46,19 @@
136 _tokenHash[TOKEN_CONSUMER_SEC_KEY] = consumer_secret;
137 }
138
139+ Token::Token(QString token_key, QString token_secret,
140+ QString consumer_key, QString consumer_secret,
141+ QString created_date, QString updated_date)
142+ {
143+ _tokenHash[TOKEN_NAME_KEY] = buildTokenName();
144+ _tokenHash[TOKEN_TOKEN_KEY] = token_key;
145+ _tokenHash[TOKEN_TOKEN_SEC_KEY] = token_secret;
146+ _tokenHash[TOKEN_CONSUMER_KEY] = consumer_key;
147+ _tokenHash[TOKEN_CONSUMER_SEC_KEY] = consumer_secret;
148+ _tokenHash[TOKEN_CREATED_KEY] = dateStringToISO(created_date);
149+ _tokenHash[TOKEN_UPDATED_KEY] = dateStringToISO(updated_date);
150+ }
151+
152 /**
153 * \fn QString Token::toQuery()
154 *
155@@ -97,7 +110,7 @@
156 {
157 if (_tokenHash.contains(QStringLiteral(TOKEN_CREATED_KEY))) {
158 return QDateTime::fromString(_tokenHash[TOKEN_CREATED_KEY],
159- "yyyy-MM-dd+HH'%3A'mm'%3A'ss.zzz");
160+ Qt::ISODate);
161 }
162 return QDateTime();
163 }
164@@ -112,7 +125,7 @@
165 {
166 if (_tokenHash.contains(QStringLiteral(TOKEN_UPDATED_KEY))) {
167 return QDateTime::fromString(_tokenHash[TOKEN_UPDATED_KEY],
168- "yyyy-MM-dd+HH'%3A'mm'%3A'ss.zzz");
169+ Qt::ISODate);
170 }
171 return QDateTime();
172 }
173@@ -176,8 +189,11 @@
174 // QUrl::fromPercentEncoding at this point in the code.
175 QString value = pair.at(1);
176 token->_tokenHash[pair.at(0)] = QString(value.replace("+", " ").replace("%40", "@"));
177- } else
178+ } else if (pair.at(0) == TOKEN_UPDATED_KEY || pair.at(0) == TOKEN_CREATED_KEY) {
179+ token->_tokenHash[pair.at(0)] = dateStringToISO(pair.at(1));
180+ } else {
181 token->_tokenHash[pair.at(0)] = pair.at(1);
182+ }
183 }
184
185 return token;
186@@ -196,4 +212,16 @@
187 return QStringLiteral(TOKEN_ID) + QStringLiteral(TOKEN_SEP) + computer_name;
188 }
189
190+ /**
191+ * \fn QString Token::dateStringToISO(const QString date)
192+ *
193+ * Convert the date string from SSO server to ISO format, if needed.
194+ **/
195+ QString Token::dateStringToISO(const QString date)
196+ {
197+ // Force the date strings to be ISO formattted, not pythonish.
198+ // We can force GMT here, as we use it on the server.
199+ return QString(date).replace("+", "T").replace("%3A", ":").replace(QRegExp("\\.[0-9]+"), "Z");
200+ }
201+
202 } // namespace UbuntuOne
203
204=== modified file 'libubuntuoneauth/token.h'
205--- libubuntuoneauth/token.h 2014-08-15 18:44:37 +0000
206+++ libubuntuoneauth/token.h 2014-09-09 13:53:37 +0000
207@@ -35,6 +35,9 @@
208 Token() {};
209 Token(QString token_key, QString token_secret,
210 QString consumer_key, QString consumer_secret);
211+ Token(QString token_key, QString token_secret,
212+ QString consumer_key, QString consumer_secret,
213+ QString created_date, QString updated_date);
214
215 QString toQuery();
216 bool isValid() const;
217@@ -47,6 +50,8 @@
218 static Token *fromQuery(const QString query);
219 static QString buildTokenName();
220
221+ static QString dateStringToISO(const QString date);
222+
223 private:
224 QHash<QString, QString> _tokenHash;
225 };

Subscribers

People subscribed via source and target branches

to all changes: