11require 'spec_helper'
22
33describe 'check_unsafe_interpolations' do
4- let ( :msg ) { "unsafe interpolation of variable 'foo' in exec command" }
4+ let ( :msg ) { "unsafe interpolation of variable 'foo' in exec command" }
5+
56 context 'with fix disabled' do
6- context 'code with unsafe interpolation' do
7+ context 'exec with unsafe interpolation in command ' do
78 let ( :code ) do
89 <<-PUPPET
910 class foo {
@@ -20,12 +21,55 @@ class foo {
2021 expect ( problems ) . to have ( 1 ) . problems
2122 end
2223
23- it 'should create a warning' do
24+ it 'creates one warning' do
25+ expect ( problems ) . to contain_warning ( msg )
26+ end
27+ end
28+
29+ context 'exec with multiple unsafe interpolations in command' do
30+ let ( :code ) do
31+ <<-PUPPET
32+ class foo {
33+
34+ exec { 'bar':
35+ command => "echo ${foo} ${bar}",
36+ }
37+
38+ }
39+ PUPPET
40+ end
41+
42+ it 'detects multiple unsafe exec command arguments' do
43+ expect ( problems ) . to have ( 2 ) . problems
44+ end
45+
46+ it 'creates two warnings' do
47+ expect ( problems ) . to contain_warning ( msg )
48+ expect ( problems ) . to contain_warning ( msg )
49+ end
50+ end
51+
52+ context 'code that uses title with unsafe string as command' do
53+ let ( :code ) do
54+ <<-PUPPET
55+ class foo {
56+
57+ exec { "echo ${foo}": }
58+
59+ }
60+ PUPPET
61+ end
62+
63+ it 'detects one problem' do
64+ expect ( problems ) . to have ( 1 ) . problems
65+ end
66+
67+ it 'creates one warning' do
2468 expect ( problems ) . to contain_warning ( msg )
2569 end
2670 end
2771
28- context 'code with no problems ' do
72+ context 'exec with a safe string in command ' do
2973 let ( :code ) do
3074 <<-PUPPET
3175 class foo {
@@ -38,7 +82,25 @@ class foo {
3882 PUPPET
3983 end
4084
41- it 'should not detect any problems' do
85+ it 'detects zero problems' do
86+ expect ( problems ) . to have ( 0 ) . problems
87+ end
88+ end
89+
90+ context 'exec that has an array of args in command' do
91+ let ( :code ) do
92+ <<-PUPPET
93+ class foo {
94+
95+ exec { 'bar':
96+ command => ['echo', $foo],
97+ }
98+
99+ }
100+ PUPPET
101+ end
102+
103+ it 'detects zero problems' do
42104 expect ( problems ) . to have ( 0 ) . problems
43105 end
44106 end
0 commit comments