2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as 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
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include <core/trust/store.h>
21
#include <gtest/gtest.h>
25
static const std::string service_name{"52EB2494-76F2-4ABB-A188-20B2D5B3CC94"};
28
// See https://bugs.launchpad.net/ubuntu-rtm/+source/trust-store/+bug/1387734
29
TEST(TrustStore, cached_user_replies_are_sorted_by_age_in_descending_order)
31
auto store = core::trust::create_default_store(service_name);
34
const std::string app1{"com.does.not.exist.app1"};
36
// This is the older reply, the user answered granted.
37
core::trust::Request r1
40
core::trust::Feature{0},
41
std::chrono::system_clock::time_point(std::chrono::seconds{0}),
42
core::trust::Request::Answer::granted
45
// This is the newer reply, the user revoked the trust.
46
core::trust::Request r2
49
core::trust::Feature{0},
50
std::chrono::system_clock::time_point(std::chrono::seconds{500}),
51
core::trust::Request::Answer::denied
57
auto query = store->query();
60
EXPECT_EQ(core::trust::Store::Query::Status::has_more_results, query->status());
61
// We expect the more recent query to be enumerated first.
62
EXPECT_EQ(r2, query->current()); query->next();
63
// We expect the older query to be enumerated second.
64
EXPECT_EQ(r1, query->current()); query->next();
65
EXPECT_EQ(core::trust::Store::Query::Status::eor, query->status());