a =`=@srddlZddlmmZddlmZddlm Z ddl m Z ddl Z ddZ ddZddZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Z d+d,Z!d-d.Z"d/d0Z#d1d2Z$d3d4Z%d5d6Z&d7d8Z'd9d:Z(d;d<Z)d=d>Z*d?d@Z+dAdBZ,dCdDZ-dEdFZ.dGdHZ/dIdJZ0dKdLZ1dMdNZ2dOdPZ3dQdRZ4dSdTZ5dUdVZ6dWdXZ7dYdZZ8d[d\Z9d]d^Z:d_d`Z;dadbZdgdhZ?didjZ@dkdlZAdmdnZBdodpZCdqdrZDdsdtZEdudvZFdwdxZGdydzZHd{d|ZId}d~ZJddZKddZLddZMddZNddZOddZPddZQdS)N) load_yamlc Csntdddiddigi}tdddiddigi}tdddiddigi}tdddiddigi}tdddiddigi}tj}|||}|sdd tvsttrttnd t|d tvst|rt|nd d tvst|rt|nd t|d }tt |d}}tj}|||}| }|sd d tvs\ttrfttnd t|dtvst|rt|ndd tvst|rt|nd t|d } tt | d}}}tj}|||}| }|sd d tvsttr(ttnd t|dtvsLt|rVt|ndd tvsrt|r|t|nd t|d } tt | d}}}tj}|||}| }|s^d d tvsttrttnd t|dtvst|rt|ndd tvs4t|r>t|nd t|d } tt | d}}}dS)Ncommand2commandacwdbc.*zfassert %(py6)s {%(py6)s = %(py2)s {%(py2)s = %(py0)s.dict_matches_allowlist_dict }(%(py3)s, %(py4)s) } validator input_dict_1allowlist_dictpy0py2py3py4py6zjassert not %(py6)s {%(py6)s = %(py2)s {%(py2)s = %(py0)s.dict_matches_allowlist_dict }(%(py3)s, %(py4)s) } input_dict_2 input_dict_3 input_dict_4) dictr dict_matches_allowlist_dict @py_builtinslocals @pytest_ar_should_repr_global_name _safereprAssertionError_format_explanation) r rrrr @py_assert1 @py_assert5 @py_format7 @py_assert7 @py_format8r$n/Users/fuellbie/tools/aws-elastic-beanstalk-deployment-workflow/ebextensions-validator/tests/test_validator.py%test_unit_dict_matches_allowlist_dict sr&cCsgd}gd}tddddi}tj}|||}|sddtvsNttrXttndt|d tvsxt|rt|nd d tvst|rt|nd t|d }tt |d}}tj}|||}| }|sd dtvsttrttndt|d tvs2t|rttrHttnd t|dtvslt|rvt|ndd tvst|rt|nd t|d}tt |d}}dS)Nr'rrrrrrr(r zZassert %(py6)s {%(py6)s = %(py2)s {%(py2)s = %(py0)s.dict_is_allowed }(%(py3)s, %(py4)s) }r r allowlist_dict_listr r rr dict_is_allowedrrrrrrr)r rr.rr r!r$r$r%test_unit_dict_is_allowed_valids 0r1cCstdddiddigi}tdddiddigi}td ddd itd ddd ig}tj}|||}| }|sd d tvsttrttnd t|d tvst|rt|nd dtvst|rt|ndt|d}tt |d}}}tj}|||}| }|sd d tvs@ttrJttnd t|dtvsnt|rxt|nddtvst|rt|ndt|d}tt |d}}}dS)Nr'rrrrrrr(r r)z^assert not %(py6)s {%(py6)s = %(py2)s {%(py2)s = %(py0)s.dict_is_allowed }(%(py3)s, %(py4)s) }r r allowlist_dict_list_swappedr rr/)r rr2rr r"r#r$r$r%#test_unit_dict_is_allowed_not_valid&s $r3cCsVdg}ddg}tj}|||}| }|sddtvs@ttrJttndt|dtvsjt|rtt|nddtvst|rt|ndt|d}tt|d}}}dd g}ddg}tj}|||}|sd dtvsttrttndt|dtvs2t|rttrHttndt|dtvsht|rrt|ndt|t|d}tt |d}}}q dS)N test_files/config_files/*.configz-test_files/allowlist_files/allowlist_all.listzSassert %(py7)s {%(py7)s = %(py2)s {%(py2)s = %(py0)s.validate }(%(py3)s, %(py5)s) }r pathrrrpy5py7 globr validaterrrrrrr)r9r @py_assert4 @py_assert6r#r$r$r% test_allowlist_all_allowed_valid<srBc CstdD]}tj}d}|||}| }|sddtvsDttrNttndt|dtvsnt|rxt|ndt|t|d}tt |d}}}}q dS)Nr8z%test_files/allowlist_files/empty.listzWassert not %(py7)s {%(py7)s = %(py2)s {%(py2)s = %(py0)s.validate }(%(py3)s, %(py5)s) }r r9r:r=)r9rr@rAZ @py_assert8 @py_format9r$r$r%test_allowlist_empty_not_valid@srDcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N'test_files/config_files/packages.configz.test_files/allowlist_files/packages_valid.listSassert %(py8)s {%(py8)s = %(py2)s {%(py2)s = %(py0)s.validate }(%(py4)s, %(py6)s) }r rrrrpy8 r r?rrrrrrrr @py_assert3r r"rCr$r$r%test_allowlist_packages_validDsrLcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrEz7test_files/allowlist_files/packages_multiple_regex.listrFr rGrIrJr$r$r%,test_allowlist_packages_multiple_regex_validGsrMcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrEz@test_files/allowlist_files/packages_multiple_regex_no_match.listWassert not %(py8)s {%(py8)s = %(py2)s {%(py2)s = %(py0)s.validate }(%(py4)s, %(py6)s) }r rGrIrrKr r" @py_assert9 @py_format10r$r$r%0test_allowlist_packages_multiple_regex_not_validJsrRcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrEz9test_files/allowlist_files/packages_valid_not_sorted.listrFr rGrIrJr$r$r%(test_allowlist_packages_not_sorted_validMsrScCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrEz8test_files/allowlist_files/packages_not_valid_value.listrNr rGrIrOr$r$r%'test_allowlist_packages_not_valid_valuePsrTcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrEz6test_files/allowlist_files/packages_not_valid_key.listrNr rGrIrOr$r$r%%test_allowlist_packages_not_valid_keySsrUcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrEz4test_files/allowlist_files/packages_regex_valid.listrFr rGrIrJr$r$r%#test_allowlist_packages_regex_validVsrVcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrEz8test_files/allowlist_files/packages_allow_all_valid.listrFr rGrIrJr$r$r%'test_allowlist_packages_allow_all_validYsrWcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz0test_files/config_files/packages_only_yum.config1test_files/allowlist_files/packages_only_yum.listrFr rGrIrJr$r$r%&test_allowlist_packages_only_yum_valid\srYcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrErXrNr rGrIrOr$r$r%*test_allowlist_packages_only_yum_not_valid_srZcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nttndt|t|t|t|d}tt|d}}}}dS)Nz=test_files/config_files/option_settings_shorthand_long.configr\rFr rGrIrJr$r$r%ttndt|t|t|t|d}tt|d}}}}dS)Nz7test_files/config_files/option_settings_standard.configr_rFr rGrIrJr$r$r%3test_allowlist_option_settings_standard_short_validksracCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N%test_files/config_files/imdsv1.configz,test_files/allowlist_files/imdsv1_valid.listrFr rGrIrJr$r$r%>test_allowlist_option_settings_shorthand_shorthand_regex_validnsrccCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nrbz&test_files/allowlist_files/imdsv1.listrFr rGrIrJr$r$r%,test_allowlist_option_settings_boolean_validqsrdcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N%test_files/config_files/groups.config&test_files/allowlist_files/groups.listrFr rGrIrJr$r$r%test_allowlist_groups_validtsrgcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nrez4test_files/allowlist_files/groups_only_groupOne.listrNr rGrIrOr$r$r%test_allowlist_groups_non_validwsrhcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N3test_files/config_files/groups_only_groupOne.configrfrFr rGrIrJr$r$r%$test_allowlist_groups_groupOne_validzsrjcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nre5test_files/allowlist_files/groups_multiple_regex.listrFr rGrIrJr$r$r%:test_allowlist_groups_multiple_regex_multiple_groups_valid}srlcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nz5test_files/config_files/groups_wrong_attribute.configrkrNr rGrIrOr$r$r%>test_allowlist_groups_multiple_regex_multiple_groups_not_validsrmcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrirkrFr rGrIrJr$r$r%3test_allowlist_groups_multiple_regex_groupOne_validsrncCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N$test_files/config_files/users.configz%test_files/allowlist_files/users.listrFr rGrIrJr$r$r%test_allowlist_users_validsrpcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nroz4test_files/allowlist_files/users_multiple_regex.listrFr rGrIrJr$r$r%)test_allowlist_users_multiple_regex_validsrqcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrozEtest_files/allowlist_files/users_multiple_regex_wrong_attributes.listrNr rGrIrOr$r$r%-test_allowlist_users_multiple_regex_not_validsrrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nroz1test_files/allowlist_files/users_only_groups.listrNr rGrIrOr$r$r%*test_allowlist_users_only_groups_non_validsrscCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nroz0test_files/allowlist_files/users_not_sorted.listrFr rGrIrJr$r$r%%test_allowlist_users_not_sorted_validsrtcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N&test_files/config_files/sources.configz'test_files/allowlist_files/sources.listrFr rGrIrJr$r$r%test_allowlist_sources_validsrvcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nruz6test_files/allowlist_files/sources_multiple_regex.listrFr rGrIrJr$r$r%+test_allowlist_sources_multiple_regex_validsrwcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nruz@test_files/allowlist_files/sources_multiple_regex_wrong_url.listrNr rGrIrOr$r$r%/test_allowlist_sources_multiple_regex_not_validsrxcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N$test_files/config_files/files.configz%test_files/allowlist_files/files.listrFr rGrIrJr$r$r%test_allowlist_files_validsrzcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz1test_files/config_files/files_only_content.configz2test_files/allowlist_files/files_only_content.listrFr rGrIrJr$r$r%'test_allowlist_files_only_content_validsr{cCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nryz4test_files/allowlist_files/files_multiple_regex.listrFr rGrIrJr$r$r%)test_allowlist_files_multiple_regex_validsr|cCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nryz@test_files/allowlist_files/files_multiple_regex_one_missing.listrNr rGrIrOr$r$r%-test_allowlist_files_multiple_regex_not_validsr}cCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N&test_files/config_files/command.configz'test_files/allowlist_files/command.listrFr rGrIrJr$r$r%test_allowlist_command_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz0test_files/config_files/command_only_list.config2test_files/allowlist_files/command_only_regex.listrFr rGrIrJr$r$r%!test_allowlist_command_list_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz1test_files/config_files/command_only_block.configrrFr rGrIrJr$r$r%"test_allowlist_command_block_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N8test_files/config_files/command_multiple_commands.configzttndt|t|t|t|d}tt|d}}}}tj}d}d}|||}| }|sddtvsttrttndt|t|t|t|d}tt|d}}}}}tj}d}d}|||}| }|sddtvsXttrbttndt|t|t|t|d}tt|d}}}}}tj}d}d }|||}| }|s0ddtvsttrttndt|t|t|t|d}tt|d}}}}}dS) Nz-test_files/config_files/command_single.configz9test_files/allowlist_files/command_single_both_match.listrFr rGz:test_files/allowlist_files/command_single_first_match.listrNz9test_files/allowlist_files/command_single_last_match.listz9test_files/allowlist_files/command_single_none_match.listrI)rrKr r"rCrPrQr$r$r%test_allowlist_command_singlesrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N'test_files/config_files/services.configz(test_files/allowlist_files/services.listrFr rGrIrJr$r$r%test_allowlist_services_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N;test_files/config_files/services_only_multiple_files.configz8test_files/allowlist_files/services_only_file_regex.listrFr rGrIrJr$r$r%?test_allowlist_services_match_multiple_files_to_one_regex_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrzAtest_files/allowlist_files/services_only_file_regex_no_match.listrNr rGrIrOr$r$r%Ctest_allowlist_services_match_multiple_files_to_one_regex_not_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrzAtest_files/allowlist_files/services_multiple_files_one_match.listrNr rGrIrOr$r$r%@test_allowlist_services_match_multiple_files_one_match_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz=test_files/config_files/services_only_multiple_sources.configz;test_files/allowlist_files/services_only_sources_regex.listrFr rGrIrJr$r$r%Atest_allowlist_services_match_multiple_sources_to_one_regex_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)Nz>test_files/config_files/services_only_multiple_commands.configzttndt|t|t|t|d}tt|d}}}}dS)Nrz7test_files/allowlist_files/services_multiple_regex.listrFr rGrIrJr$r$r%,test_allowlist_services_multiple_regex_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nrz@test_files/allowlist_files/services_multiple_regex_no_match.listrNr rGrIrOr$r$r%0test_allowlist_services_multiple_regex_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N1test_files/config_files/container_commands.configz2test_files/allowlist_files/container_commands.listrFr rGrIrJr$r$r%'test_allowlist_container_commands_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dSNDtest_files/config_files/container_commands_only_command_array.configEtest_files/allowlist_files/container_commands_only_command_array.listrFr rGrIrJr$r$r%Ctest_allowlist_container_commands_only_command_array_to_array_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrrrNr rGrIrOr$r$r%Jtest_allowlist_container_commands_normal_command_and_array_allowlist_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dSrrIrJr$r$r%Ntest_allowlist_container_commands_normal_command_and_array_allowlist_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrzEtest_files/allowlist_files/container_commands_only_command_regex.listrFr rGrIrJr$r$r%Ctest_allowlist_container_commands_only_command_array_to_regex_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrzNtest_files/allowlist_files/container_commands_only_command_regex_no_match.listrNr rGrIrOr$r$r%Gtest_allowlist_container_commands_only_command_array_to_regex_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)NrzAtest_files/allowlist_files/container_commands_multiple_regex.listrFr rGrIrJr$r$r%6test_allowlist_container_commands_multiple_regex_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)NrzMtest_files/allowlist_files/container_commands_multiple_regex_one_missing.listrNr rGrIrOr$r$r%:test_allowlist_container_commands_multiple_regex_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N(test_files/config_files/resources.config)test_files/allowlist_files/resources.listrFr rGrIrJr$r$r%test_allowlist_resources_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nrz?test_files/allowlist_files/resources_missing_SecurityGroup.listrNr rGrIrOr$r$r%8test_allowlist_resources_missing_SecurityGroup_not_validsrcCstj}d}d}|||}|svddtvs4ttr>ttndt|t|t|t|d}tt|d}}}}dS)N8test_files/config_files/resources_with_properties.configrrFr rGrIrJr$r$r%.test_allowlist_resources_with_properties_validsrcCstj}d}d}|||}| }|s|ddtvs:ttrDttndt|t|t|t|d}tt|d}}}}}dS)Nrzr&r-r1r3r7rBrDrLrMrRrSrTrUrVrWrYrZr]r^r`rarcrdrgrhrjrlrmrnrprqrrrsrtrvrwrxrzr{r|r}rrrrrrrrrrrrrrrrrrrrrrrrrrrrr$r$r$r%s&