~ci-train-bot/signon-plugin-oauth2/signon-plugin-oauth2-ubuntu-yakkety-landing-060

« back to all changes in this revision

Viewing changes to tests/oauth2plugintest.cpp

  • Committer: Bileto Bot
  • Date: 2016-08-18 18:17:15 UTC
  • mfrom: (83.1.3 packaging)
  • Revision ID: ci-train-bot@canonical.com-20160818181715-t2o1i2tenqe8vtsh
* New upstream release
  - OAuth2: allow token URL to be on a different host (LP: #1588210)
  - OAuth2: accept replies carrying text/html content type (LP: #1438393)
  - Enable CI on gitlab.com
* debian/control, debian/rules:
  - Don't run tests in dbus-test-runner
  - Update link to project homepage

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * This file is part of oauth2 plugin
3
3
 *
4
4
 * Copyright (C) 2010 Nokia Corporation.
5
 
 * Copyright (C) 2012 Canonical Ltd.
 
5
 * Copyright (C) 2012-2016 Canonical Ltd.
6
6
 *
7
7
 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8
8
 *
1686
1686
    delete nam;
1687
1687
}
1688
1688
 
 
1689
void OAuth2PluginTest::testTokenPath_data()
 
1690
{
 
1691
    QTest::addColumn<QString>("host");
 
1692
    QTest::addColumn<QString>("tokenPath");
 
1693
    QTest::addColumn<QString>("expectedTokenUrl");
 
1694
 
 
1695
    QTest::newRow("relative") <<
 
1696
        "localhost" <<
 
1697
        "access_token" <<
 
1698
        "https://localhost/access_token";
 
1699
 
 
1700
    QTest::newRow("relative with slashes") <<
 
1701
        "localhost" <<
 
1702
        "path/to/access_token" <<
 
1703
        "https://localhost/path/to/access_token";
 
1704
 
 
1705
    QTest::newRow("absolute") <<
 
1706
        "localhost" <<
 
1707
        "https://another.host/and/a/path" <<
 
1708
        "https://another.host/and/a/path";
 
1709
}
 
1710
 
 
1711
void OAuth2PluginTest::testTokenPath()
 
1712
{
 
1713
    QFETCH(QString, host);
 
1714
    QFETCH(QString, tokenPath);
 
1715
    QFETCH(QString, expectedTokenUrl);
 
1716
 
 
1717
    SignOn::UiSessionData info;
 
1718
    OAuth2PluginData data;
 
1719
    data.setHost(host);
 
1720
    data.setAuthPath("authorize");
 
1721
    data.setTokenPath(tokenPath);
 
1722
    data.setClientId("104660106251471");
 
1723
    data.setRedirectUri("http://localhost/resp.html");
 
1724
 
 
1725
    QSignalSpy result(m_testPlugin, SIGNAL(result(const SignOn::SessionData&)));
 
1726
    QSignalSpy error(m_testPlugin, SIGNAL(error(const SignOn::Error &)));
 
1727
    QSignalSpy userActionRequired(m_testPlugin,
 
1728
                                  SIGNAL(userActionRequired(const SignOn::UiSessionData&)));
 
1729
 
 
1730
    TestNetworkAccessManager *nam = new TestNetworkAccessManager;
 
1731
    m_testPlugin->m_networkAccessManager = nam;
 
1732
    TestNetworkReply *reply = new TestNetworkReply(this);
 
1733
    reply->setStatusCode(200);
 
1734
    reply->setContentType("application/json");
 
1735
    reply->setContent("{ \"access_token\":\"t0k3n\", \"expires_in\": 3600 }");
 
1736
    nam->setNextReply(reply);
 
1737
 
 
1738
    m_testPlugin->process(data, QString("web_server"));
 
1739
    QTRY_COMPARE(userActionRequired.count(), 1);
 
1740
    QString state = parseState(userActionRequired);
 
1741
 
 
1742
    info.setUrlResponse("http://localhost/resp.html?code=c0d3&state=" + state);
 
1743
    m_testPlugin->userActionFinished(info);
 
1744
 
 
1745
    QTRY_COMPARE(result.count(), 1);
 
1746
    QCOMPARE(error.count(), 0);
 
1747
    QCOMPARE(nam->m_lastRequest.url(), QUrl(expectedTokenUrl));
 
1748
 
 
1749
    delete nam;
 
1750
}
 
1751
 
1689
1752
//end test cases
1690
1753
 
1691
1754
QTEST_MAIN(OAuth2PluginTest)