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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use std::collections::{HashMap, HashSet};
use std::time::Duration;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
pub fn readable_password_from_random() -> String {
let mut trng = thread_rng();
format!(
"{}-{}-{}-{}",
(&mut trng)
.sample_iter(&Alphanumeric)
.take(4)
.map(|v| v as char)
.collect::<String>(),
(&mut trng)
.sample_iter(&Alphanumeric)
.take(4)
.map(|v| v as char)
.collect::<String>(),
(&mut trng)
.sample_iter(&Alphanumeric)
.take(4)
.map(|v| v as char)
.collect::<String>(),
(&mut trng)
.sample_iter(&Alphanumeric)
.take(4)
.map(|v| v as char)
.collect::<String>(),
)
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Account {
pub name: String,
pub display_name: String,
pub password: String,
pub uuid: Uuid,
}
impl Account {
pub fn get_ds_ldap_dn(&self, basedn: &str) -> String {
format!("uid={},ou=people,{}", self.name.as_str(), basedn)
}
pub fn get_ipa_ldap_dn(&self, basedn: &str) -> String {
format!("uid={},cn=users,cn=accounts,{}", self.name.as_str(), basedn)
}
pub fn generate(uuid: Uuid) -> Self {
let mut rng = rand::thread_rng();
let id: u64 = rng.gen();
let name = format!("account_{}", id);
let display_name = format!("Account {}", id);
Account {
name,
display_name,
password: readable_password_from_random(),
uuid,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Group {
pub name: String,
pub uuid: Uuid,
pub members: Vec<Uuid>,
}
impl Group {
pub fn get_ds_ldap_dn(&self, basedn: &str) -> String {
format!("cn={},ou=groups,{}", self.name.as_str(), basedn)
}
pub fn get_ipa_ldap_dn(&self, basedn: &str) -> String {
format!("cn={},cn=groups,cn=accounts,{}", self.name.as_str(), basedn)
}
pub fn generate(uuid: Uuid, members: Vec<Uuid>) -> Self {
let mut rng = rand::thread_rng();
let id: u64 = rng.gen();
let name = format!("group_{}", id);
Group {
name,
uuid,
members,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Entity {
Account(Account),
Group(Group),
}
impl Entity {
pub fn get_uuid(&self) -> Uuid {
match self {
Entity::Account(a) => a.uuid,
Entity::Group(g) => g.uuid,
}
}
pub fn get_name(&self) -> &str {
match self {
Entity::Account(a) => a.name.as_str(),
Entity::Group(g) => g.name.as_str(),
}
}
pub fn get_ds_ldap_dn(&self, basedn: &str) -> String {
match self {
Entity::Account(a) => a.get_ds_ldap_dn(basedn),
Entity::Group(g) => g.get_ds_ldap_dn(basedn),
}
}
pub fn get_ipa_ldap_dn(&self, basedn: &str) -> String {
match self {
Entity::Account(a) => a.get_ipa_ldap_dn(basedn),
Entity::Group(g) => g.get_ipa_ldap_dn(basedn),
}
}
pub fn get_entity_type(&self) -> EntityType {
match self {
Entity::Account(a) => EntityType::Account(a.uuid),
Entity::Group(g) => EntityType::Group(g.uuid),
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum EntityType {
Account(Uuid),
Group(Uuid),
}
#[derive(Debug, Serialize, Deserialize)]
pub enum Change {
Account,
Group(Vec<Uuid>),
}
#[derive(Debug, Serialize, Deserialize)]
pub enum OpType {
Bind(Uuid),
Add(Vec<Uuid>),
Mod(Vec<(Uuid, Change)>),
Delete(Vec<Uuid>),
Search(Vec<Uuid>),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Op {
pub orig_etime: Duration,
pub rtime: Duration,
pub op_type: OpType,
}
impl Op {
pub fn require_reset<'a>(&'a self) -> Option<Box<dyn Iterator<Item = Uuid> + 'a>> {
match &self.op_type {
OpType::Add(ids) => Some(Box::new(ids.iter().copied())),
OpType::Mod(changes) => Some(Box::new(changes.iter().map(|v| v.0))),
_ => None,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Conn {
pub id: i32,
pub ops: Vec<Op>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TestData {
pub all_entities: HashMap<Uuid, Entity>,
pub access: HashMap<Uuid, Vec<EntityType>>,
pub accounts: HashSet<Uuid>,
pub precreate: HashSet<Uuid>,
pub connections: Vec<Conn>,
}