'Check that safety measure work.
This includes:
\'tarbombs\' which include files or symlinks with paths
outside or directly in the working directory,
\'special files\' (character device, block device or FIFOs),
all raise exceptions/400s.'

def test_unsafe_tar(self):

    def try_tar(tarpath):
        '    Attempt    to    tar    an    unacceptable    file    '
        with open(tarpath) as tar:
            args = {'name': tarpath, 'course-data': [tar]}
            resp = self.client.post(self.url, args)
        self.assertEquals(resp.status_code, 200)
        resp = self.client.get(reverse_course_url('import_status_handler', self.course.id, kwargs={'filename': os.path.split(tarpath)[1]}))
        status = json.loads(resp.content)['ImportStatus']
        self.assertEqual(status, (-1))
    try_tar(self._fifo_tar())
    try_tar(self._symlink_tar())
    try_tar(self._outside_tar())
    try_tar(self._outside_tar2())
    try_tar(self._edx_platform_tar())
    with self.settings(DATA_DIR='/not/the/data/dir'):
        try_tar(self._edx_platform_tar())
    resp_status = self.client.get(reverse_course_url('import_status_handler', self.course.id, kwargs={'filename': os.path.split(self.good_tar)[1]}))
    import_status = json.loads(resp_status.content)['ImportStatus']
    self.assertIn(import_status, (0, 3))
