syncable_cli/analyzer/hadolint/rules/
dl3025.rs1use crate::analyzer::hadolint::parser::instruction::Instruction;
7use crate::analyzer::hadolint::rules::{SimpleRule, simple_rule};
8use crate::analyzer::hadolint::shell::ParsedShell;
9use crate::analyzer::hadolint::types::Severity;
10
11pub fn rule() -> SimpleRule<impl Fn(&Instruction, Option<&ParsedShell>) -> bool + Send + Sync> {
12 simple_rule(
13 "DL3025",
14 Severity::Warning,
15 "Use arguments JSON notation for CMD and ENTRYPOINT arguments",
16 |instr, _shell| match instr {
17 Instruction::Cmd(args) | Instruction::Entrypoint(args) => args.is_exec_form(),
18 _ => true,
19 },
20 )
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26 use crate::analyzer::hadolint::parser::instruction::Arguments;
27 use crate::analyzer::hadolint::rules::{Rule, RuleState};
28
29 #[test]
30 fn test_exec_form() {
31 let rule = rule();
32 let mut state = RuleState::new();
33
34 let args = Arguments::List(vec!["node".to_string(), "app.js".to_string()]);
35 let instr = Instruction::Cmd(args);
36 rule.check(&mut state, 1, &instr, None);
37 assert!(state.failures.is_empty());
38 }
39
40 #[test]
41 fn test_shell_form() {
42 let rule = rule();
43 let mut state = RuleState::new();
44
45 let args = Arguments::Text("node app.js".to_string());
46 let instr = Instruction::Cmd(args);
47 rule.check(&mut state, 1, &instr, None);
48 assert_eq!(state.failures.len(), 1);
49 assert_eq!(state.failures[0].code.as_str(), "DL3025");
50 }
51
52 #[test]
53 fn test_entrypoint_exec() {
54 let rule = rule();
55 let mut state = RuleState::new();
56
57 let args = Arguments::List(vec!["./entrypoint.sh".to_string()]);
58 let instr = Instruction::Entrypoint(args);
59 rule.check(&mut state, 1, &instr, None);
60 assert!(state.failures.is_empty());
61 }
62
63 #[test]
64 fn test_entrypoint_shell() {
65 let rule = rule();
66 let mut state = RuleState::new();
67
68 let args = Arguments::Text("./entrypoint.sh".to_string());
69 let instr = Instruction::Entrypoint(args);
70 rule.check(&mut state, 1, &instr, None);
71 assert_eq!(state.failures.len(), 1);
72 }
73}