-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmock_firewall.h
More file actions
78 lines (60 loc) · 2.38 KB
/
mock_firewall.h
File metadata and controls
78 lines (60 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PERMISSION_BROKER_MOCK_FIREWALL_H_
#define PERMISSION_BROKER_MOCK_FIREWALL_H_
#include <string>
#include <vector>
#include <base/macros.h>
#include <gmock/gmock.h>
#include "permission_broker/firewall.h"
namespace permission_broker {
class MockFirewall : public Firewall {
public:
MockFirewall() = default;
~MockFirewall() = default;
int SetRunInMinijailFailCriterion(
const std::vector<std::string>& keywords, bool repeat, bool omit_failure);
int GetRunInMinijailCriterionMatchCount(int id);
bool CheckCommandsUndone();
int CountActiveCommands();
void ResetStoredCommands();
// Check if the current command matches a failure rule,
// if the failure rule is not a repeat rule, remove it
// from the match criteria.
bool MatchAndUpdate(const std::vector<std::string>& argv);
// Returns all commands issued with RunInMinijail during the test.
std::vector<std::string> GetAllCommands();
private:
struct Criterion {
std::vector<std::string> keywords;
// If false, remove the criterion after it's matched.
bool repeat;
// If false, treat matching commands as failures, otherwise,
// omit failing.
bool omit_failure;
// Count the number of times the criterion is matched.
int match_count;
// Don't take into account match_count.
bool operator==(const Criterion& c) const {
return (std::equal(keywords.begin(), keywords.end(),
c.keywords.begin()) &&
(repeat == c.repeat) &&
(c.omit_failure == omit_failure));
}
};
// A list of collections of keywords that a command
// must have in order for it to fail.
std::vector<Criterion> match_criteria_;
// A log of commands issued with RunInMinijail during the test.
std::vector<std::vector<std::string>> commands_;
// The mock's implementation simply logs the command issued if
// successful.
int RunInMinijail(const std::vector<std::string>& argv) override;
// Given an ip/iptables command, return the command that undoes its effect.
std::vector<std::string> GetInverseCommand(
const std::vector<std::string>& command);
DISALLOW_COPY_AND_ASSIGN(MockFirewall);
};
} // namespace permission_broker
#endif // PERMISSION_BROKER_MOCK_FIREWALL_H_