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
/// Copyright © 2024 Don Isaac
///
/// This file is part of KeyHunter.
///
/// KeyHunter is free software: you can redistribute it and/or modify it
/// under the terms of the GNU General Public License as published by the Free
/// Software Foundation, either version 3 of the License, or (at your option)
/// any later version.
///
/// KeyHunter is distributed in the hope that it will be useful, but WITHOUT
/// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
/// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
/// more details.
///
/// You should have received a copy of the GNU General Public License along with
/// KeyHunter. If not, see <https://www.gnu.org/licenses/>.
use ;
// #[cfg(test)]
// mod test {
// use super::*;
// use regex::Regex;
// #[derive(Debug)]
// struct Tester {
// pub rule: RuleOld,
// }
// impl<P> From<P> for Tester
// where
// Pattern: From<P>,
// {
// fn from(pattern: P) -> Self {
// Self {
// rule: RuleOld {
// pattern: pattern.into(),
// ..Default::default()
// },
// }
// }
// }
// impl Tester {
// pub fn test_captures<'s, T>(&self, test_cases: T)
// where
// T: IntoIterator<Item = (&'s str, Vec<(usize, &'s str)>)>,
// {
// for (input, expected) in test_cases {
// let actual = self.rule.captures(input);
// assert_eq!(actual, Some(expected), "'{}'", input);
// }
// }
// }
// #[test]
// fn test_string_capture() {
// let tester: Tester = "api-key".into();
// tester.test_captures([
// // TODO: should be "x-api-key"
// ("x-api-key", vec![(2, "api-key")]),
// ("api-key-header", vec![(0, "api-key-header")]),
// ("api-key header", vec![(0, "api-key")]),
// ("some api-key header", vec![(5, "api-key")]),
// ]);
// }
// #[test]
// fn test_regex_capture() {
// // FIXME: gitleak's regex patterns check for variable names
// let pat = r#"(?i)(?:key|api|token|secret|client|passwd|password|auth|access)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}([0-9a-z\-_.=]{10,150})(?:['|\"|\n|\r|\s|\x60|;]|$)"#;
// let tester: Tester = Regex::new(pat).unwrap().into();
// tester.test_captures([
// (
// "const Discord_api_key = e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5",
// vec![
// (14, "api_key = e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5"),
// (
// 24,
// "e7322523fb86ed64c836a979cf8465fbd436378c653c1db38f9ae87bc62a6fd5",
// )],
// ),
// ]);
// }
// #[test]
// fn test_contains_digit() {
// let yes = vec![
// "1",
// "abcde1",
// "0abcdefg",
// "asdfvoapsdhfoaisdhf9apoisdhoiashdfp",
// ];
// let no = vec!["", "abc", "apisodhfapiosdhfoasihdfoiahsgdiophasdg"];
// for y in yes {
// assert!(y.contains_digit());
// }
// for n in no {
// assert!(!n.contains_digit());
// }
// }
// }