~ubuntu-branches/ubuntu/raring/signon-plugin-oauth2/raring

« back to all changes in this revision

Viewing changes to tests/oauth2plugintest.cpp

  • Committer: Ken VanDine
  • Date: 2013-02-27 18:34:39 UTC
  • mfrom: (37.1.10)
  • Revision ID: ken.vandine@canonical.com-20130227183439-brtl5lev5tnaevfs
Tags: 0.15-0ubuntu1
releasing version 0.15-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "plugin.h"
27
27
#include "oauth2data.h"
 
28
#include "oauth2tokendata.h"
28
29
 
29
30
#include "oauth2plugintest.h"
30
31
 
202
203
    webServerData.setClientId("104660106251471");
203
204
    webServerData.setClientSecret("fa28f40b5a1f8c1d5628963d880636fbkjkjkj");
204
205
    webServerData.setRedirectUri("http://localhost/connect/login_success.html");
 
206
    webServerData.setScope(QStringList() << "scope1" << "scope2");
205
207
 
206
208
    //try without params
207
209
    m_testPlugin->process(webServerData, QString("web_server"));
243
245
    tokens.insert( webServerData.ClientId(), QVariant::fromValue(token));
244
246
    webServerData.m_data.insert(QLatin1String("Tokens"), tokens);
245
247
 
 
248
    /* try with missing cached scopes */
 
249
    m_testPlugin->process(webServerData, QString("web_server"));
 
250
    m_loop.exec();
 
251
    resp = m_response.data<OAuth2PluginTokenData>();
 
252
    QVERIFY(resp.AccessToken() != QLatin1String("tokenfromtest"));
 
253
    QCOMPARE(m_error.type(), int(Error::MissingData));
 
254
 
 
255
    /* try with incomplete cached scopes */
 
256
    token.insert("Scopes", QStringList("scope2"));
 
257
    tokens.insert(webServerData.ClientId(), QVariant::fromValue(token));
 
258
    webServerData.m_data.insert(QLatin1String("Tokens"), tokens);
 
259
    m_testPlugin->process(webServerData, QString("web_server"));
 
260
    m_loop.exec();
 
261
    resp = m_response.data<OAuth2PluginTokenData>();
 
262
    QVERIFY(resp.AccessToken() != QLatin1String("tokenfromtest"));
 
263
    QCOMPARE(m_error.type(), int(Error::MissingData));
 
264
 
 
265
    /* try with sufficient cached scopes */
 
266
    token.insert("Scopes",
 
267
                 QStringList() << "scope1" << "scope3" << "scope2");
 
268
    tokens.insert(webServerData.ClientId(), QVariant::fromValue(token));
 
269
    webServerData.m_data.insert(QLatin1String("Tokens"), tokens);
246
270
    m_testPlugin->process(webServerData, QString("web_server"));
247
271
    m_loop.exec();
248
272
    resp = m_response.data<OAuth2PluginTokenData>();
264
288
    data.setClientId("104660106251471");
265
289
    data.setClientSecret("fa28f40b5a1f8c1d5628963d880636fbkjkjkj");
266
290
    data.setRedirectUri("http://localhost/connect/login_success.html");
 
291
    QStringList scopes = QStringList() << "scope1" << "scope2";
 
292
    data.setScope(scopes);
267
293
 
268
294
    QObject::connect(m_testPlugin, SIGNAL(result(const SignOn::SessionData&)),
269
295
                  this,  SLOT(result(const SignOn::SessionData&)),Qt::QueuedConnection);
271
297
                  this,  SLOT(pluginError(const SignOn::Error &)),Qt::QueuedConnection);
272
298
    QObject::connect(m_testPlugin, SIGNAL(userActionRequired(const SignOn::UiSessionData&)),
273
299
                  this,  SLOT(uiRequest(const SignOn::UiSessionData&)),Qt::QueuedConnection);
 
300
    QObject::connect(m_testPlugin, SIGNAL(store(const SignOn::SessionData&)),
 
301
                     this,  SLOT(store(const SignOn::SessionData&)),
 
302
                     Qt::QueuedConnection);
274
303
    QTimer::singleShot(10*1000, &m_loop, SLOT(quit()));
275
304
 
276
305
    m_testPlugin->process(data, QString("user_agent"));
302
331
    OAuth2PluginTokenData *result = (OAuth2PluginTokenData*)&m_response;
303
332
    QCOMPARE(result->AccessToken(), QString("testtoken."));
304
333
    QCOMPARE(result->ExpiresIn(), 4776);
 
334
    QVariantMap storedTokenData = m_stored.data<OAuth2TokenData>().Tokens();
 
335
    QVariantMap storedClientData =
 
336
        storedTokenData.value(data.ClientId()).toMap();
 
337
    QVERIFY(!storedClientData.isEmpty());
 
338
    QCOMPARE(storedClientData["Scopes"].toStringList(), scopes);
305
339
 
306
340
    //valid data
307
341
    info.setUrlResponse(QString("http://www.facebook.com/connect/login_success.html#access_token=testtoken."));