Skip to content

Commit

Permalink
#6524 fix required permissions add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Feb 6, 2020
1 parent 8ed63c5 commit 9478caa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Long execute(CommandContext ctxt) throws CommandException {
public Map<String, Set<Permission>> getRequiredPermissions() {
// for data file check permission on owning dataset
return Collections.singletonMap("",
mode != null && mode.equals("storage") ? Collections.singleton(Permission.ViewUnpublishedDataset)
mode != null && mode.equals(Mode.STORAGE) ? Collections.singleton(Permission.ViewUnpublishedDataset)
: version !=null && version.isDraft() ? Collections.singleton(Permission.ViewUnpublishedDataset) : Collections.<Permission>emptySet());
}

Expand Down
14 changes: 13 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
import static junit.framework.Assert.assertEquals;
import org.hamcrest.CoreMatchers;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -1325,7 +1326,11 @@ public void testDataSizeInDataverse() throws InterruptedException {
Response publishDataversetResp = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
publishDataversetResp.then().assertThat()
.statusCode(OK.getStatusCode());
String apiTokenRando = createUserGetToken();

Response datasetStorageSizeResponseDraft = UtilIT.findDatasetDownloadSize(datasetId.toString(), ":draft", apiTokenRando);
datasetStorageSizeResponseDraft.prettyPrint();
assertEquals(UNAUTHORIZED.getStatusCode(), datasetStorageSizeResponseDraft.getStatusCode());
Response publishDatasetResp = UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken);
//msg(publishDatasetResp.body().asString());
publishDatasetResp.then().assertThat()
Expand All @@ -1345,9 +1350,16 @@ public void testDataSizeInDataverse() throws InterruptedException {

magicControlString = MessageFormat.format(BundleUtil.getStringFromBundle("datasets.api.datasize.storage"), magicSizeNumber);

Response datasetStorageSizeResponse = UtilIT.findDatasetStorageSize(datasetId.toString(), apiToken);
//no perms

Response datasetStorageSizeResponse = UtilIT.findDatasetStorageSize(datasetId.toString(), apiTokenRando);
datasetStorageSizeResponse.prettyPrint();
assertEquals(UNAUTHORIZED.getStatusCode(), datasetStorageSizeResponse.getStatusCode());

//has perms
datasetStorageSizeResponse = UtilIT.findDatasetStorageSize(datasetId.toString(), apiToken);
datasetStorageSizeResponse.prettyPrint();

assertEquals(magicControlString, JsonPath.from(datasetStorageSizeResponse.body().asString()).getString("data.message"));

magicControlString = MessageFormat.format(BundleUtil.getStringFromBundle("datasets.api.datasize.download"), magicSizeNumber);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2315,4 +2315,10 @@ static Response findDatasetDownloadSize(String datasetId) {
.get("/api/datasets/" + datasetId + "/versions/:latest/downloadsize");
}

static Response findDatasetDownloadSize(String datasetId, String version, String apiToken) {
return given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
.get("/api/datasets/" + datasetId + "/versions/" + version + "/downloadsize");
}

}

0 comments on commit 9478caa

Please sign in to comment.