~mandel/trust-store/handle-exceptions

« back to all changes in this revision

Viewing changes to tests/bug_1387734.cpp

  • Committer: CI Train Bot
  • Author(s): thomas-voss
  • Date: 2015-01-23 09:55:48 UTC
  • mfrom: (76.1.1 fix-1387734)
  • Revision ID: ci-train-bot@canonical.com-20150123095548-7gvet20omv3zmex0
Make sure that cached trust requests are sorted by their timestamp in descending order.
Add regression test case. Fixes: #1387734
Approved by: Seth Arnold, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2014 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
17
 */
 
18
 
 
19
#include <core/trust/store.h>
 
20
 
 
21
#include <gtest/gtest.h>
 
22
 
 
23
namespace
 
24
{
 
25
static const std::string service_name{"52EB2494-76F2-4ABB-A188-20B2D5B3CC94"};
 
26
}
 
27
 
 
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)
 
30
{
 
31
    auto store = core::trust::create_default_store(service_name);
 
32
    store->reset();
 
33
 
 
34
    const std::string app1{"com.does.not.exist.app1"};
 
35
 
 
36
    // This is the older reply, the user answered granted.
 
37
    core::trust::Request r1
 
38
    {
 
39
        app1,
 
40
        core::trust::Feature{0},
 
41
        std::chrono::system_clock::time_point(std::chrono::seconds{0}),
 
42
        core::trust::Request::Answer::granted
 
43
    };
 
44
 
 
45
    // This is the newer reply, the user revoked the trust.
 
46
    core::trust::Request r2
 
47
    {
 
48
        app1,
 
49
        core::trust::Feature{0},
 
50
        std::chrono::system_clock::time_point(std::chrono::seconds{500}),
 
51
        core::trust::Request::Answer::denied
 
52
    };
 
53
 
 
54
    store->add(r1);
 
55
    store->add(r2);
 
56
 
 
57
    auto query = store->query();
 
58
    query->execute();
 
59
 
 
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());
 
66
}