def test_build_command_with_args(self): deployment = mommy.make(models.Deployment, task__name='test_env') configuration = mommy.make(models.Configuration, key='arg', value='arg_value', task_argument=True) deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) fabfile_path, active_loc = get_fabfile_path(deployment.stage.project) self.assertEqual( command, 'fab test_env:arg="arg_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) )
def test_build_command_with_args(self): deployment = mommy.make(models.Deployment, task__name='test_env') configuration = mommy.make(models.Configuration, key='arg', value='arg_value', task_argument=True, task_name='test_env') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) fabfile_path, active_loc = get_fabfile_path(deployment.stage.project) self.assertEqual( command, 'fab test_env:arg="arg_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) )
def test_build_command_injection(self): deployment = mommy.make(models.Deployment, task__name='test_env') configuration = mommy.make(models.Configuration, key='foo=bar -i /path/to/keyfile --set foo2', value='bar') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) fabfile_path, active_loc = get_fabfile_path(deployment.stage.project) self.assertEqual( command, 'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value,x=y') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key=dummy_value\,x\=y" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key=blah,x', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=blah\,x=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) )
def test_build_command_injection(self): deployment = mommy.make(models.Deployment, task__name='test_env') cache.delete_many(['project_{}_fabfile_tasks'.format(deployment.stage.project_id), 'project_{}_fabfile_path'.format(deployment.stage.project_id)]) configuration = mommy.make(models.Configuration, key='foo=bar -i /path/to/keyfile --set foo2', value='bar') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) fabfile_path, active_loc = get_fabfile_path(deployment.stage.project) self.assertEqual( command, 'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key', value='dummy_value,x=y') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key=dummy_value\,x\=y" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key=blah,x', value='dummy_value') deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=blah\,x=dummy_value" ' '--abort-on-prompts --fabfile={}'.format(fabfile_path) )
def test_build_command_injection(self): deployment = mommy.make(models.Deployment, task__name="test_env") cache.delete_many( [ "project_{}_fabfile_tasks".format(deployment.stage.project_id), "project_{}_fabfile_path".format(deployment.stage.project_id), ] ) configuration = mommy.make(models.Configuration, key="foo=bar -i /path/to/keyfile --set foo2", value="bar") deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) fabfile_path, active_loc = get_fabfile_path(deployment.stage.project) self.assertEqual( command, 'fab test_env --set "foo\\=bar -i /path/to/keyfile --set foo2=bar" ' "--abort-on-prompts --fabfile={}".format(fabfile_path), ) configuration = mommy.make(models.Configuration, key="dummy_key", value="dummy_value") deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "foo\=bar -i /path/to/keyfile --set foo2=bar,dummy_key=dummy_value" ' "--abort-on-prompts --fabfile={}".format(fabfile_path), ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key='dummy_key=test" | ls #', value="dummy_value") deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=test\\" | ls #=dummy_value" ' "--abort-on-prompts --fabfile={}".format(fabfile_path), ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key="dummy_key", value="dummy_value,x=y") deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key=dummy_value\,x\=y" ' "--abort-on-prompts --fabfile={}".format(fabfile_path), ) deployment.stage.configuration_set.clear() configuration = mommy.make(models.Configuration, key="dummy_key=blah,x", value="dummy_value") deployment.stage.configuration_set.add(configuration) command = build_command(deployment, {}) self.assertEqual( command, 'fab test_env --set "dummy_key\=blah\,x=dummy_value" ' "--abort-on-prompts --fabfile={}".format(fabfile_path), )