Skip to content

Commit

Permalink
Use 'SHA-256' checksum for sysmeta/object uploads (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
gothub committed Aug 26, 2020
1 parent ac7b6c4 commit e51224f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions R/D1Node.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ setMethod("D1Node", signature("XMLInternalElementNode"), function(xml) {
#' newid <- paste("urn:uuid:", UUIDgenerate(), sep="")
#' format <- "text/csv"
#' size <- file.info(csvfile)$size
#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1)
#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256)
#' sysmeta <- addAccessRule(sysmeta, "public", "read")
#' # Create (upload) the object to DataONE (requires authentication)
#' \dontrun{
Expand Down
12 changes: 6 additions & 6 deletions R/MNode.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
#' write.csv(testdf, csvfile, row.names=FALSE)
#' f <- "text/csv"
#' size <- file.info(csvfile)$size
#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=f, size=size,
#' checksum=sha1, originMemberNode=mnid, authoritativeMemberNode=mnid)
#' checksum=sha256, originMemberNode=mnid, authoritativeMemberNode=mnid)
#' # Upload data to DataONE (requires authentication)
#' \dontrun{
#' response <- createObject(mn, newid, csvfile, sysmeta)
Expand Down Expand Up @@ -280,9 +280,9 @@ setMethod("getSystemMetadata", signature("MNode"), function(x, pid) {
})

#' @rdname getChecksum
#' @param checksumAlgorithm The algorithm used to calculate the checksum. Default="SHA-1"
#' @param checksumAlgorithm The algorithm used to calculate the checksum. Default="SHA-256"
#' @export
setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm="SHA-1") {
setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm="SHA-256") {
stopifnot(is.character(pid))
url <- paste(x@endpoint, "checksum", URLencode(pid, reserved=T), sep="/")
response<-GET(url, query=list(checksumAlgorithm=checksumAlgorithm), user_agent(get_user_agent()))
Expand Down Expand Up @@ -346,8 +346,8 @@ setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm=
#' write.csv(testdf, csvfile, row.names=FALSE)
#' format <- "text/csv"
#' size <- file.info(csvfile)$size
#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1)
#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256)
#' sysmeta <- addAccessRule(sysmeta, "public", "read")
#' # Upload the data to DataONE (requires authentication)
#' \dontrun{
Expand Down
4 changes: 2 additions & 2 deletions man/MNode-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/archive.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/createObject.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/getChecksum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test.D1Client.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ test_that("D1Client getDataObject", {
expect_match(getIdentifier(obj), pid)
expect_match(getFormatId(obj), "text/csv")
data <- getData(obj)
sha1 <- digest(data, algo="md5", serialize=FALSE, file=FALSE)
expect_match(sha1, obj@sysmeta@checksum)
sha256 <- digest(data, algo="md5", serialize=FALSE, file=FALSE)
expect_match(sha256, obj@sysmeta@checksum)
})

test_that("D1Client uploadDataObject with raw data works", {
Expand Down
26 changes: 13 additions & 13 deletions tests/testthat/test.MNode.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ test_that("MNode describeObject() with authentication", {
# Create SystemMetadata for the object
format <- "text/csv"
size <- file.info(csvfile)$size
sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
# specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1,
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256,
originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier)
# sysmeta <- addAccessRule(sysmeta, "public", "read")
# Upload the data to the MN using createObject(), checking for success and a returned identifier
Expand Down Expand Up @@ -186,13 +186,13 @@ test_that("MNode createObject(), updateObject(), archive()", {
# Create SystemMetadata for the object
format <- "text/csv"
size <- file.info(csvfile)$size
sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
# specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node
seriesId <- UUIDgenerate()
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1,
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256,
originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier, seriesId=seriesId)
sysmeta <- addAccessRule(sysmeta, "public", "read")
expect_that(sysmeta@checksum, equals(sha1))
expect_that(sysmeta@checksum, equals(sha256))
expect_that(sysmeta@originMemberNode, equals(mnTest@identifier))
expect_that(sysmeta@authoritativeMemberNode, equals(mnTest@identifier))

Expand All @@ -207,10 +207,10 @@ test_that("MNode createObject(), updateObject(), archive()", {
csvfile <- paste(tempfile(), ".csv", sep="")
write.csv(testdf, csvfile, row.names=FALSE)
size <- file.info(csvfile)$size
sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
sysmeta@identifier <- updateid
sysmeta@size <- size
sysmeta@checksum <- sha1
sysmeta@checksum <- sha256
sysmeta@obsoletes <- newid
newId <- updateObject(mnTest, newid, csvfile, updateid, sysmeta)
expect_false(is.null(newId))
Expand Down Expand Up @@ -270,12 +270,12 @@ test_that("MNode createObject() with in-memory object", {
# Create SystemMetadata for the object
format <- "text/csv"
size <- length(csvdata)
sha1 <- digest(csvdata, algo="sha1", serialize=FALSE, file=FALSE)
sha256 <- digest(csvdata, algo="sha256", serialize=FALSE, file=FALSE)
# specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node

sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1)
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256)
sysmeta <- addAccessRule(sysmeta, "public", "read")
expect_that(sysmeta@checksum, equals(sha1))
expect_that(sysmeta@checksum, equals(sha256))

# Upload the data to the MN using createObject(), checking for success and a returned identifier
createdId <- createObject(mnTest, newid, sysmeta = sysmeta, dataobj=csvdata)
Expand Down Expand Up @@ -322,10 +322,10 @@ test_that("MNode createObject() works for large files", {
# Create SystemMetadata for the object
format <- "text/csv"
size <- file.info(csvfile)$size
sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE)
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier)
sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE)
sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier)
sysmeta <- addAccessRule(sysmeta, "public", "read")
expect_that(sysmeta@checksum, equals(sha1))
expect_that(sysmeta@checksum, equals(sha256))
expect_that(sysmeta@originMemberNode, equals(mnTest@identifier))
expect_that(sysmeta@authoritativeMemberNode, equals(mnTest@identifier))

Expand Down

0 comments on commit e51224f

Please sign in to comment.