#NEWLINE# def testLinkFile( self ) : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# 'parentType' : 'folder' , #NEWLINE# 'parentId' : self . privateFolder [ '_id' ] , #NEWLINE# 'name' : 'My Link Item' , #NEWLINE# 'linkUrl' : 'javascript:alert("x");' , #NEWLINE# #UNINDENT# } #NEWLINE# resp = self . request ( path = '/file' , method = 'POST' , user = self . user , params = params ) #NEWLINE# self . assertValidationError ( resp , 'linkUrl' ) #NEWLINE# params [ 'linkUrl' ] = ' http://www.google.com  ' #NEWLINE# resp = self . request ( path = '/file' , method = 'POST' , user = self . user , params = params ) #NEWLINE# self . assertStatusOk ( resp ) #NEWLINE# file = resp . json #NEWLINE# self . assertEqual ( file [ 'assetstoreId' ] , None ) #NEWLINE# self . assertEqual ( file [ 'name' ] , 'My Link Item' ) #NEWLINE# self . assertEqual ( params [ 'linkUrl' ] , params [ 'linkUrl' ] . strip ( ) ) #NEWLINE# resp = self . request ( path = ( '/file/%s/download' % file [ '_id' ] ) , method = 'GET' , isJson = False , user = self . user ) #NEWLINE# self . assertStatus ( resp , 303 ) #NEWLINE# self . assertEqual ( resp . headers [ 'Location' ] , params [ 'linkUrl' ] . strip ( ) ) #NEWLINE# resp = self . request ( path = ( '/folder/%s/download' % self . privateFolder [ '_id' ] ) , method = 'GET' , user = self . user , isJson = False ) #NEWLINE# self . assertEqual ( resp . headers [ 'Content-Type' ] , 'application/zip' ) #NEWLINE# body = self . getBody ( resp , text = False ) #NEWLINE# zip = zipfile . ZipFile ( io . BytesIO ( body ) , 'r' ) #NEWLINE# self . assertTrue ( ( zip . testzip ( ) is None ) ) #NEWLINE# extracted = zip . read ( 'Private/My Link Item' ) . decode ( 'utf8' ) #NEWLINE# self . assertEqual ( extracted , params [ 'linkUrl' ] . strip ( ) )