1313 (java.nio.file.attribute FileAttribute)
1414 (java.net URL)
1515 (java.util HashMap)
16+ (java.util.zip ZipEntry ZipOutputStream ZipInputStream)
1617 (java.util.zip ZipFile ZipInputStream)
1718 (org.apache.commons.io FilenameUtils)
1819 (org.geotools.data DataStoreFinder FileDataStoreFinder Query)
108109
109110 " UTM ZONE 11N"
110111 " EPSG:2955" false [-121.48866759617566 2.8851809782082726E-4 ]))))
112+
113+ (defn create-single-entry-zip [filename entry-name content]
114+ (let [file-obj (io/file filename)]
115+ (with-open [zos (ZipOutputStream. (io/output-stream file-obj))]
116+ (let [entry (ZipEntry. entry-name)]
117+ (.putNextEntry zos entry)
118+ (.write zos (.getBytes content " UTF-8" ))
119+ (.closeEntry zos)))
120+ file-obj))
121+
122+ (deftest unzip-file-test
123+ (testing " invalid file path in the source throws error"
124+ (let [invalid-zip (create-single-entry-zip " invalid.zip" " ../somewhere_else.txt" " something" )]
125+ (try
126+ (is (thrown-with-msg? Exception #"Given zip content is not allowed" (shapefile/unzip-file invalid-zip)))
127+ (finally
128+ (io/delete-file invalid-zip true )))))
129+ (testing " invalid file path within the tar dir throws error"
130+ (let [invalid-zip (create-single-entry-zip " wrong-dir.zip" " /BLAH/somewhere_else.txt" " something" )]
131+ (try
132+ (is (thrown-with-msg? Exception #"Error while uncompressing zip file.*No such file or directory" (shapefile/unzip-file invalid-zip)))
133+ (finally
134+ (io/delete-file invalid-zip true )))))
135+ (testing " valid zip file returns file obj"
136+ (let [valid-zip (create-single-entry-zip " valid.zip" " somewhere_else.txt" " something" )
137+ result (shapefile/unzip-file valid-zip)]
138+ (try
139+ (is (some? result))
140+ (finally
141+ (io/delete-file valid-zip true ))))))
0 commit comments