-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2105 from AtlasOfLivingAustralia/hotfix/issue750
Fix for ala-infrastructure#750
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package au.org.ala.merit | ||
|
||
import grails.test.mixin.TestFor | ||
import org.apache.commons.io.IOUtils | ||
import org.apache.http.HttpStatus | ||
import spock.lang.Specification | ||
|
||
@TestFor(ImageController) | ||
class ImageControllerSpec extends Specification { | ||
|
||
File uploadPath | ||
File temp | ||
|
||
void setup() { | ||
|
||
controller.imageService = new ImageService() // to use the fullPath method without needing to mock it | ||
controller.imageService.grailsApplication = controller.grailsApplication | ||
temp = File.createTempDir("tmp", "") | ||
uploadPath = new File(temp, "upload") | ||
uploadPath.mkdir() | ||
|
||
controller.grailsApplication.config.upload.images.path = uploadPath.getAbsolutePath() | ||
|
||
// Setup two files, one that should be accessible, and one that should not. | ||
File validFile = new File(uploadPath, "validFile.png") | ||
validFile.createNewFile() | ||
|
||
File privateFile = new File(temp, "privateFile.png") | ||
privateFile.createNewFile() | ||
} | ||
|
||
void "Files can be retrieved from the temporary upload directory by filename"() { | ||
when: | ||
params.id = "validFile.png" | ||
controller.get() | ||
|
||
then: | ||
response.contentType == "image/png" | ||
response.status == HttpStatus.SC_OK | ||
} | ||
|
||
void "If a file doesn't exist, a 404 will be returned"() { | ||
when: | ||
params.id = "missingFile.png" | ||
controller.get() | ||
|
||
then: | ||
response.status == HttpStatus.SC_NOT_FOUND | ||
} | ||
|
||
void "A file cannot be retrieved from outside the designated uploads directory"() { | ||
when: | ||
params.id = "../privateFile.png" | ||
controller.get() | ||
|
||
then: | ||
new File(uploadPath, params.id).exists() | ||
response.status == HttpStatus.SC_NOT_FOUND | ||
} | ||
} |