@@ -59,7 +59,7 @@ def get_env_vars(runner):
59
59
60
60
ps = subprocess .run (
61
61
['docker' , 'exec' , 'test-container' , '/bin/sh' ,
62
- '-c' , 'echo $TESTALLOWED ' ],
62
+ '-c' , 'env ' ],
63
63
check = True ,
64
64
stderr = subprocess .PIPE ,
65
65
stdout = subprocess .PIPE ,
@@ -70,23 +70,54 @@ def get_env_vars(runner):
70
70
Tests .cleanup (runner )
71
71
return env_var_output
72
72
73
- def test_env_variable_no_skip_or_allow ():
74
- runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed .yml' )
73
+ def test_env_variable_with_incorrect_envs_no_flags_backtick ():
74
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed_backtick .yml' , dry_run = True )
75
75
with pytest .raises (RuntimeError ) as e :
76
76
get_env_vars (runner )
77
77
expected_exception = 'Docker container setup environment var value had wrong format.'
78
78
assert expected_exception in str (e .value ), \
79
79
Tests .assertion_info (f"Exception: { expected_exception } " , str (e .value ))
80
80
81
+ def test_env_variable_with_incorrect_envs_no_flags_dollar ():
82
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed_dollar.yml' , dry_run = True )
83
+ with pytest .raises (RuntimeError ) as e :
84
+ get_env_vars (runner )
85
+ expected_exception = 'Docker container setup environment var value had wrong format.'
86
+ assert expected_exception in str (e .value ), \
87
+ Tests .assertion_info (f"Exception: { expected_exception } " , str (e .value ))
88
+
89
+ def test_env_variable_with_incorrect_envs_no_flags_paren ():
90
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed_paren.yml' , dry_run = True )
91
+ with pytest .raises (RuntimeError ) as e :
92
+ get_env_vars (runner )
93
+ expected_exception = 'Docker container setup environment var value had wrong format.'
94
+ assert expected_exception in str (e .value ), \
95
+ Tests .assertion_info (f"Exception: { expected_exception } " , str (e .value ))
96
+
97
+ def test_env_variable_unsafe_false ():
98
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress.yml' , skip_unsafe = False , dry_run = True )
99
+ env_var_output = get_env_vars (runner )
100
+ print ("Env var output is " , env_var_output )
101
+ assert 'TESTALLOWED=alpha-num123_' in env_var_output , Tests .assertion_info ('TESTALLOWED=alpha-num123_' , env_var_output )
102
+ assert 'TEST1_ALLOWED=alpha-key-num123_' in env_var_output , Tests .assertion_info ('TEST1_ALLOWED=alpha-key-num123_' , env_var_output )
103
+
81
104
def test_env_variable_skip_unsafe_true ():
82
- runner = Tests .setup_runner (usage_scenario = 'env_vars_stress .yml' , skip_unsafe = True )
105
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed .yml' , skip_unsafe = True , dry_run = True )
83
106
env_var_output = get_env_vars (runner )
84
- assert env_var_output == 'alpha-num123_\n ' , Tests .assertion_info ('alpha-num123_' , env_var_output )
107
+ assert 'TESTALLOWED=alpha-num123_' in env_var_output , Tests .assertion_info ('TESTALLOWED=alpha-num123_' , env_var_output )
108
+ assert 'TEST1_ALLOWED=alpha-key-num123_' in env_var_output , Tests .assertion_info ('TEST1_ALLOWED=alpha-key-num123_' , env_var_output )
109
+ assert 'TESTBACKTICK' not in env_var_output , Tests .assertion_info ('TESTBACKTICK' , env_var_output )
110
+ assert 'TESTDOLLAR' not in env_var_output , Tests .assertion_info ('TESTDOLLAR' , env_var_output )
111
+ assert 'TESTPARENTHESIS' not in env_var_output , Tests .assertion_info ('TESTPARENTHESIS' , env_var_output )
85
112
86
113
def test_env_variable_allow_unsafe_true ():
87
- runner = Tests .setup_runner (usage_scenario = 'env_vars_stress .yml' , allow_unsafe = True )
114
+ runner = Tests .setup_runner (usage_scenario = 'env_vars_stress_unallowed .yml' , allow_unsafe = True , dry_run = True )
88
115
env_var_output = get_env_vars (runner )
89
- assert env_var_output == 'alpha-num123_\n ' , Tests .assertion_info ('alpha-num123_' , env_var_output )
116
+ assert 'TESTALLOWED=alpha-num123_' in env_var_output , Tests .assertion_info ('TESTALLOWED=alpha-num123_' , env_var_output )
117
+ assert 'TEST1_ALLOWED=alpha-key-num123_' in env_var_output , Tests .assertion_info ('TEST1_ALLOWED=alpha-key-num123_' , env_var_output )
118
+ assert 'TESTBACKTICK' in env_var_output , Tests .assertion_info ('TESTBACKTICK' , env_var_output )
119
+ assert 'TESTDOLLAR' in env_var_output , Tests .assertion_info ('TESTDOLLAR' , env_var_output )
120
+ assert 'TESTPARENTHESIS' in env_var_output , Tests .assertion_info ('TESTPARENTHESIS' , env_var_output )
90
121
91
122
# ports: [int:int] (optional)
92
123
# Docker container portmapping on host OS to be used with --allow-unsafe flag.
0 commit comments