2
* Copyright (C) 2016 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: James Henstridge <james.henstridge@canonical.com>
19
#include <unity/storage/provider/ProviderBase.h>
20
#include <unity/storage/provider/internal/AccountData.h>
21
#include <unity/storage/provider/internal/DBusPeerCache.h>
23
#include <utils/DBusEnvironment.h>
25
#include <gtest/gtest.h>
26
#include <OnlineAccounts/Account>
27
#include <OnlineAccounts/Manager>
28
#include <QCoreApplication>
34
using namespace unity::storage::provider;
36
class AccountDataTest : public ::testing::Test
39
QDBusConnection const& connection()
41
return dbus_->connection();
47
dbus_.reset(new DBusEnvironment);
48
dbus_->start_services();
51
void TearDown() override
57
unique_ptr<DBusEnvironment> dbus_;
60
TEST_F(AccountDataTest, oauth1_credentials)
62
OnlineAccounts::Manager manager("", connection());
63
manager.waitForReady();
64
ASSERT_TRUE(manager.isReady());
66
auto accounts = manager.availableAccounts("oauth1-service");
67
ASSERT_EQ(1, accounts.size());
69
internal::AccountData account(unique_ptr<ProviderBase>(),
70
shared_ptr<internal::DBusPeerCache>(),
74
QSignalSpy spy(&account, &internal::AccountData::authenticated);
75
account.authenticate(true);
76
ASSERT_TRUE(spy.wait());
78
ASSERT_TRUE(account.has_credentials());
79
auto creds = boost::get<OAuth1Credentials>(account.credentials());
81
EXPECT_EQ("consumer_key", creds.consumer_key);
82
EXPECT_EQ("consumer_secret", creds.consumer_secret);
83
EXPECT_EQ("token", creds.token);
84
EXPECT_EQ("token_secret", creds.token_secret);
87
TEST_F(AccountDataTest, oauth2_credentials)
89
OnlineAccounts::Manager manager("", connection());
90
manager.waitForReady();
91
ASSERT_TRUE(manager.isReady());
93
auto accounts = manager.availableAccounts("oauth2-service");
94
ASSERT_EQ(1, accounts.size());
96
internal::AccountData account(unique_ptr<ProviderBase>(),
97
shared_ptr<internal::DBusPeerCache>(),
101
QSignalSpy spy(&account, &internal::AccountData::authenticated);
102
account.authenticate(true);
103
ASSERT_TRUE(spy.wait());
105
ASSERT_TRUE(account.has_credentials());
106
auto creds = boost::get<OAuth2Credentials>(account.credentials());
108
EXPECT_EQ("access_token", creds.access_token);
111
TEST_F(AccountDataTest, password_credentials)
113
OnlineAccounts::Manager manager("", connection());
114
manager.waitForReady();
115
ASSERT_TRUE(manager.isReady());
117
auto accounts = manager.availableAccounts("password-service");
118
ASSERT_EQ(1, accounts.size());
120
internal::AccountData account(unique_ptr<ProviderBase>(),
121
shared_ptr<internal::DBusPeerCache>(),
125
QSignalSpy spy(&account, &internal::AccountData::authenticated);
126
account.authenticate(true);
127
ASSERT_TRUE(spy.wait());
129
ASSERT_TRUE(account.has_credentials());
130
auto creds = boost::get<PasswordCredentials>(account.credentials());
132
EXPECT_EQ("user", creds.username);
133
EXPECT_EQ("pass", creds.password);
136
int main(int argc, char **argv)
138
QCoreApplication app(argc, argv);
139
::testing::InitGoogleTest(&argc, argv);
140
return RUN_ALL_TESTS();