Changeset 739:11bdf1dc2e4b in hatta-dev


Ignore:
Timestamp:
01/24/10 13:16:02 (2 years ago)
Author:
sheep@…
Branch:
default
Message:

add more tests for directories and symlinks, fix some related errors in Hatta

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • hatta.py

    r732 r739  
    410410        repo_file = self._title_to_file(title) 
    411411        file_path = self._file_path(title) 
    412         if os.path.islink(file_path): 
    413             raise werkzeug.exceptions.Forbidden(_(u"Can't edit symbolic links")) 
     412        if os.path.islink(file_path) or os.path.isdir(file_path): 
     413            raise werkzeug.exceptions.Forbidden(_(u"Can't edit symbolic links or directories")) 
    414414        mercurial.util.rename(file_name, file_path) 
    415415        changectx = self._changectx() 
     
    481481        repo_file = self._title_to_file(title) 
    482482        file_path = self._file_path(title) 
    483         if os.path.islink(file_path): 
    484             raise werkzeug.exceptions.Forbidden(_(u"Can't edit symbolic links")) 
     483        if os.path.islink(file_path) or os.path.isdir(file_path): 
     484            raise werkzeug.exceptions.Forbidden(_(u"Can't edit symbolic links or directories")) 
    485485        try: 
    486486            os.unlink(file_path) 
     
    494494 
    495495        file_path = self._file_path(title) 
    496         if os.path.islink(file_path): 
    497             raise werkzeug.exceptions.Forbidden(_(u"Can't read symbolic links")) 
     496        if os.path.islink(file_path) or os.path.isdir(file_path): 
     497            raise werkzeug.exceptions.Forbidden(_(u"Can't read symbolic links or directories")) 
    498498        try: 
    499499            return open(file_path, "rb") 
     
    19131913        except werkzeug.exceptions.Forbidden: 
    19141914            yield werkzeug.html.p( 
    1915                 werkzeug.html(_(u"Can't edit symbolic links"))) 
     1915                werkzeug.html(_(u"Can't edit symbolic links or directories"))) 
    19161916            return 
    19171917        if preview: 
  • tests/test_repo.py

    r738 r739  
    101101        assert self.title not in repo 
    102102 
     103    def test_directory_read(self, repo): 
     104        """ 
     105        What happens when you try to read a directory as page. 
     106        """ 
     107 
     108        path = os.path.join(repo.path, self.filename) 
     109        os.mkdir(path) 
     110        py.test.raises(werkzeug.exceptions.Forbidden, repo.open_page, 
     111                       self.title) 
     112 
     113    def test_directory_write(self, repo): 
     114        """ 
     115        What happens when you try to write a directory as page. 
     116        """ 
     117 
     118        path = os.path.join(repo.path, self.filename) 
     119        os.mkdir(path) 
     120        py.test.raises(werkzeug.exceptions.Forbidden, repo.save_text, 
     121                       self.title, self.text, self.author, self.comment, 
     122                       parent=-1) 
     123 
     124    def test_directory_delete(self, repo): 
     125        """ 
     126        What happens when you try to delete a directory as page. 
     127        """ 
     128 
     129        path = os.path.join(repo.path, self.filename) 
     130        os.mkdir(path) 
     131        py.test.raises(werkzeug.exceptions.Forbidden, repo.delete_page, 
     132                       self.title, self.author, self.comment) 
     133 
     134    def test_symlink_delete(self, repo): 
     135        """ 
     136        What happens when you try to delete a symlink as page. 
     137        """ 
     138 
     139        path = os.path.join(repo.path, self.filename) 
     140        os.symlink('/', path) 
     141        py.test.raises(werkzeug.exceptions.Forbidden, repo.delete_page, 
     142                       self.title, self.author, self.comment) 
     143 
    103144class TestStorage(object): 
    104145    """ 
Note: See TracChangeset for help on using the changeset viewer.