@@ -795,6 +795,27 @@ def test_realpath_resolve_first(self, kwargs):
795795 safe_rmdir (ABSTFN + "/k" )
796796 safe_rmdir (ABSTFN )
797797
798+ @os_helper .skip_unless_symlink
799+ @skip_if_ABSTFN_contains_backslash
800+ @unittest .skipIf (os .chmod not in os .supports_follow_symlinks , "Can't set symlink permissions" )
801+ @unittest .skipIf (sys .platform != "darwin" , "only macOS requires read permission to readlink()" )
802+ @_parameterize ({'strict' : True }, {'strict' : ALLOW_MISSING })
803+ def test_realpath_unreadable_symlink_strict (self , kwargs ):
804+ try :
805+ os .symlink (ABSTFN + "1" , ABSTFN )
806+ os .chmod (ABSTFN , 0o000 , follow_symlinks = False )
807+ with self .assertRaises (PermissionError ):
808+ realpath (ABSTFN , ** kwargs )
809+ with self .assertRaises (PermissionError ):
810+ realpath (ABSTFN + '/foo' , ** kwargs ),
811+ with self .assertRaises (PermissionError ):
812+ realpath (ABSTFN + '/../foo' , ** kwargs )
813+ with self .assertRaises (PermissionError ):
814+ realpath (ABSTFN + '/foo/..' , ** kwargs )
815+ finally :
816+ os .chmod (ABSTFN , 0o755 , follow_symlinks = False )
817+ os .unlink (ABSTFN )
818+
798819 @skip_if_ABSTFN_contains_backslash
799820 @os_helper .skip_unless_symlink
800821 def test_realpath_unreadable_directory (self ):
0 commit comments