-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
322 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ branches: | |
only: | ||
- master | ||
- dev | ||
- develop | ||
- /^feature\/.*$/ | ||
- /^hotfix\/.*$/ | ||
before_cache: | ||
|
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
src/test/groovy/au/org/ala/biocollect/DownloadControllerSpec.groovy
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,84 @@ | ||
package au.org.ala.biocollect | ||
|
||
import grails.test.mixin.TestFor | ||
import org.apache.http.HttpStatus | ||
import spock.lang.Specification | ||
|
||
@TestFor(DownloadController) | ||
class DownloadControllerSpec extends Specification { | ||
|
||
File scriptsPath | ||
File temp | ||
File hubPath | ||
File modelPath | ||
|
||
void setup() { | ||
|
||
temp = File.createTempDir("tmp", "") | ||
scriptsPath = new File(temp, "scripts") | ||
scriptsPath.mkdir() | ||
hubPath = new File(scriptsPath, "tempHub") | ||
hubPath.mkdir() | ||
modelPath = new File(hubPath, "tempModel") | ||
modelPath.mkdir() | ||
|
||
controller.grailsApplication.config.app.file.script.path = scriptsPath.getAbsolutePath() | ||
|
||
// Setup three files, one that should be accessible, and others that should not | ||
File validFile = new File(modelPath, "validFile.js") | ||
validFile.createNewFile() | ||
|
||
File jsonFile = new File(modelPath, "validFile.json") | ||
jsonFile.createNewFile() | ||
|
||
File privateFile = new File(temp, "privateFile.js") | ||
privateFile.createNewFile() | ||
} | ||
|
||
void "Files can be retrieved from the temporary scripts directory by filename"() { | ||
when: | ||
params.hub = "tempHub" | ||
params.filename = "validFile.js" | ||
params.model = "tempModel" | ||
controller.getScriptFile() | ||
|
||
then: | ||
response.contentType == "text/javascript" | ||
response.status == HttpStatus.SC_OK | ||
} | ||
|
||
void "If a file doesn't exist, a 404 will be returned"() { | ||
when: | ||
params.hub = "tempHub" | ||
params.filename = "missingFile.js" | ||
params.model = "tempModel" | ||
controller.getScriptFile() | ||
|
||
then: | ||
response.status == HttpStatus.SC_NOT_FOUND | ||
} | ||
|
||
void "A file cannot be retrieved from outside the designated scripts directory"() { | ||
when: | ||
params.hub = "tempHub" | ||
params.filename = "../../../privateFile.js" | ||
params.model = "tempModel" | ||
controller.getScriptFile() | ||
|
||
then: | ||
new File(modelPath, params.filename).exists() | ||
response.status == HttpStatus.SC_NOT_FOUND | ||
} | ||
|
||
void "Tyring to read a file with extension which are not allowed to read"() { | ||
when: | ||
params.hub = "tempHub" | ||
params.filename = "validFile.json" | ||
params.model = "tempModel" | ||
controller.getScriptFile() | ||
|
||
then: | ||
new File(modelPath, params.filename).exists() | ||
response.status == HttpStatus.SC_NOT_FOUND | ||
} | ||
} |
Oops, something went wrong.