|
21 | 21 | from pytest_mock import mocker # noqa pylint: disable=unused-import |
22 | 22 |
|
23 | 23 | import aws_encryption_sdk_cli |
24 | | -from aws_encryption_sdk_cli.exceptions import BadUserArgumentError, ParameterParseError |
| 24 | +from aws_encryption_sdk_cli.exceptions import ParameterParseError |
25 | 25 | from aws_encryption_sdk_cli.internal import arg_parsing, identifiers, metadata |
26 | | -from .unit_test_utils import is_windows |
27 | 26 |
|
28 | 27 | pytestmark = [pytest.mark.unit, pytest.mark.local] |
29 | 28 |
|
@@ -121,24 +120,64 @@ def test_comment_ignoring_argument_parser_convert_filename(patch_platform_win32_ |
121 | 120 | parser = arg_parsing.CommentIgnoringArgumentParser() |
122 | 121 |
|
123 | 122 | if any(win32_version): |
124 | | - assert not parser._CommentIgnoringArgumentParser__is_posix |
| 123 | + assert parser._CommentIgnoringArgumentParser__is_windows |
125 | 124 | else: |
126 | | - assert parser._CommentIgnoringArgumentParser__is_posix |
| 125 | + assert not parser._CommentIgnoringArgumentParser__is_windows |
127 | 126 |
|
128 | 127 | parsed_line = [arg for arg in parser.convert_arg_line_to_args(expected_transform[0])] |
129 | 128 | assert expected_transform[1] == parsed_line |
130 | 129 |
|
131 | 130 |
|
| 131 | +def build_convert_special_cases(): |
| 132 | + test_cases = [] |
| 133 | + escape_chars = { |
| 134 | + False: '\\', |
| 135 | + True: '`' |
| 136 | + } |
| 137 | + for plat_is_windows in (True, False): |
| 138 | + test_cases.append(( |
| 139 | + '-o "example file with spaces surrounded by double quotes"', |
| 140 | + ['-o', 'example file with spaces surrounded by double quotes'], |
| 141 | + plat_is_windows |
| 142 | + )) |
| 143 | + test_cases.append(( |
| 144 | + "-o 'example file with spaces surrounded by single quotes'", |
| 145 | + ['-o', 'example file with spaces surrounded by single quotes'], |
| 146 | + plat_is_windows |
| 147 | + )) |
| 148 | + test_cases.append(( |
| 149 | + '-o "example with an inner {}" double quote"'.format(escape_chars[plat_is_windows]), |
| 150 | + ['-o', 'example with an inner " double quote'], |
| 151 | + plat_is_windows |
| 152 | + )) |
| 153 | + test_cases.append(( |
| 154 | + "-o 'example with an inner {}' single quote'".format(escape_chars[plat_is_windows]), |
| 155 | + ['-o', "example with an inner ' single quote"], |
| 156 | + plat_is_windows |
| 157 | + )) |
| 158 | + return test_cases |
| 159 | + |
| 160 | + |
| 161 | +@pytest.mark.parametrize('arg_line, expected_args, plat_is_windows', build_convert_special_cases()) |
| 162 | +def test_comment_ignoring_argument_parser_convert_special_cases(arg_line, expected_args, plat_is_windows): |
| 163 | + parser = arg_parsing.CommentIgnoringArgumentParser() |
| 164 | + parser._CommentIgnoringArgumentParser__is_windows = plat_is_windows |
| 165 | + |
| 166 | + actual_args = parser.convert_arg_line_to_args(arg_line) |
| 167 | + |
| 168 | + assert actual_args == expected_args |
| 169 | + |
| 170 | + |
132 | 171 | @pytest.mark.functional |
133 | 172 | def test_f_comment_ignoring_argument_parser_convert_filename(): |
134 | 173 | # Actually checks against the current local system |
135 | 174 | parser = arg_parsing.CommentIgnoringArgumentParser() |
136 | 175 |
|
137 | 176 | if any(platform.win32_ver()): |
138 | | - assert not parser._CommentIgnoringArgumentParser__is_posix |
| 177 | + assert parser._CommentIgnoringArgumentParser__is_windows |
139 | 178 | expected_transform = NON_POSIX_FILEPATH |
140 | 179 | else: |
141 | | - assert parser._CommentIgnoringArgumentParser__is_posix |
| 180 | + assert not parser._CommentIgnoringArgumentParser__is_windows |
142 | 181 | expected_transform = POSIX_FILEPATH |
143 | 182 |
|
144 | 183 | parsed_line = [arg for arg in parser.convert_arg_line_to_args(expected_transform[0])] |
@@ -218,15 +257,10 @@ def build_expected_good_args(from_file=False): # pylint: disable=too-many-local |
218 | 257 | {'some': 'data', 'not': 'secret'} |
219 | 258 | )) |
220 | 259 | if from_file: |
221 | | - good_args.append(pytest.param( |
| 260 | + good_args.append(( |
222 | 261 | default_encrypt + ' -c "key with a space=value with a space"', |
223 | 262 | 'encryption_context', |
224 | | - {'key with a space': 'value with a space'}, |
225 | | - marks=pytest.mark.xfail( |
226 | | - is_windows(), |
227 | | - reason='https://github.com/awslabs/aws-encryption-sdk-cli/issues/110', |
228 | | - strict=True |
229 | | - ) |
| 263 | + {'key with a space': 'value with a space'} |
230 | 264 | )) |
231 | 265 | else: |
232 | 266 | good_args.append(( |
@@ -660,17 +694,3 @@ def test_process_encryption_context_encrypt_required_key_fail(): |
660 | 694 | raw_encryption_context=['encryption=context', 'with=values', 'key_3'], |
661 | 695 | raw_required_encryption_context_keys=['key_1', 'key_2'] |
662 | 696 | ) |
663 | | - |
664 | | - |
665 | | -@pytest.mark.parametrize('arg_line', ( |
666 | | - 'single-quote \' line', |
667 | | - 'double-quote " line' |
668 | | -)) |
669 | | -def test_line_contains_problematic_characters(arg_line): |
670 | | - parser = arg_parsing.CommentIgnoringArgumentParser() |
671 | | - parser._CommentIgnoringArgumentParser__is_posix = False |
672 | | - |
673 | | - with pytest.raises(BadUserArgumentError) as excinfo: |
674 | | - parser.convert_arg_line_to_args(arg_line) |
675 | | - |
676 | | - excinfo.match(r'Config files containing characters *') |
|
0 commit comments