

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 = backend.build_command(deployment.stage.project, deployment, {
        
    })
    (fabfile_path, active_loc) = backend.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 = backend.build_command(deployment.stage.project, 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 = backend.build_command(deployment.stage.project, 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 = backend.build_command(deployment.stage.project, 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 = backend.build_command(deployment.stage.project, deployment, {
        
    })
    self.assertEqual(command, 'fab test_env --set "dummy_key\\=blah\\,x=dummy_value" --abort-on-prompts --fabfile={}'.format(fabfile_path))
    deployment.stage.configuration_set.clear()
    configuration = mommy.make(models.Configuration, key='key_filename', value='my_ssh_key')
    deployment.stage.configuration_set.add(configuration)
    command = backend.build_command(deployment.stage.project, deployment, {
        
    })
    self.assertEqual(command, 'fab test_env -i my_ssh_key --abort-on-prompts --fabfile={}'.format(fabfile_path))

dataset/ETHPy150Open fabric-bolt/fabric-bolt/fabric_bolt/task_runners/tests.py BackendTests.test_build_command_injection/original