File: target_group.rs

package info (click to toggle)
rust-pleaser 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: makefile: 10
file content (165 lines) | stat: -rw-r--r-- 4,863 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use std::collections::HashMap;
mod basic_ro;

#[cfg(test)]
mod test {
    use super::*;
    use basic_ro::*;
    use pleaser::*;

    #[test]
    fn test_target_group_rule() {
        let config = "[ed]
exact_name=ed
exact_target=root
exact_rule = /bin/bash
target_group = potato
"
        .to_string();

        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut ro = basic_ro("ed", "root");
        ro.target_group = Some("potato".to_string());

        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        basic_cmd(&mut ro, &"/bin/bash".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), true);

        ro.target_group = Some("potatoes".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);

        ro.target_group = None;
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);
    }

    #[test]
    fn test_exact_target_group_rule() {
        let config = "[ed]
exact_name=ed
exact_target=root
exact_rule = /bin/bash
exact_target_group = potato
"
        .to_string();

        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut ro = basic_ro("ed", "root");
        ro.target_group = Some("potato".to_string());

        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        basic_cmd(&mut ro, &"/bin/bash".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), true);

        ro.target_group = Some("potatoes".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);

        ro.target_group = None;
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);
    }

    #[test]
    fn test_target_group_edit() {
        let config = "
[please_ini]
name = ed
group = false
regex = /etc/please.ini
type = edit
target_group = oracle
"
        .to_string();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut ro = basic_ro("ed", "root");
        basic_cmd(&mut ro, &"/etc/please.ini".to_string());
        ro.target_group = Some("oracle".to_string());
        ro.acl_type = Acltype::Edit;
        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        assert_eq!(can(&vec_eo, &mut ro).permit(), true);

        basic_cmd(&mut ro, &"".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);
    }

    #[test]
    fn test_target_group_run() {
        let config = "
[please_ini]
name = ed
group = false
regex = /etc/missing
type = run
target_group = oracle
"
        .to_string();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut ro = basic_ro("ed", "root");
        basic_cmd(&mut ro, &"/etc/missing".to_string());
        ro.target_group = Some("oracle".to_string());
        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        assert_eq!(can(&vec_eo, &mut ro).permit(), false);

        ro.command = "".to_string();
        basic_cmd(&mut ro, &"".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), false);
    }

    // group has no effect in list context
    #[test]
    fn test_target_group_list() {
        let config = "
[please_ini]
name = ed
group = false
regex = /etc/please.ini
type = list
target_group = oracle
"
        .to_string();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut ro = basic_ro("ed", "root");
        basic_cmd(&mut ro, &"/etc/please.ini".to_string());
        ro.target_group = Some("oracle".to_string());
        ro.acl_type = Acltype::List;
        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        assert_eq!(can(&vec_eo, &mut ro).permit(), true);

        basic_cmd(&mut ro, &"".to_string());
        assert_eq!(can(&vec_eo, &mut ro).permit(), true);
    }

    #[test]
    fn test_target_group_run_given_but_not_configured() {
        let config = "
[please_ini]
name = ed
group = false
regex = /etc/please.ini
type = edit
"
        .to_string();
        let mut vec_eo: Vec<EnvOptions> = vec![];
        let mut bytes = 0;
        let mut ini_list: HashMap<String, bool> = HashMap::new();
        let mut ro = basic_ro("ed", "root");
        basic_cmd(&mut ro, &"/etc/please.ini".to_string());
        ro.target_group = Some("oracle".to_string());
        read_ini_config_str(&config, &mut vec_eo, &ro, false, &mut bytes, &mut ini_list);

        assert_eq!(can(&vec_eo, &mut ro).permit(), false);
    }
}