Skip to content

Commit

Permalink
Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpvgoncalves committed Oct 15, 2023
1 parent c244176 commit 483701a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/testthat/test-envelope_read.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("Envelope reading works", {

key <- keygen_kyber()
secret_message <- "Hello world!!"
env <- envelope_create(secret_message, key$public)
fn <- write_envelope(env)

retrieved_envelope <- read_envelope(fn)
expect_identical(env, retrieved_envelope)

expect_error(read_envelope("/not_a_valid/file"), "Invalid 'file_name'")
})
28 changes: 28 additions & 0 deletions tests/testthat/test-envelope_write.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("Envelope writing works", {

key <- keygen_kyber()
secret_message <- "Hello world!!"
env <- envelope_create(secret_message, key$public)
dest <- tempfile()

fn <- write_envelope(env, dest)
expect_equal(fn, dest)
expect_true(file.exists(fn))

fn <- write_envelope(env)
expect_true(file.exists(fn))

expect_error(write_envelope("envelope"),
"'envelope' parameter does not have the expected class")
expect_error(write_envelope(key),
"'envelope' parameter does not have the expected class")

if (Sys.info()[1] == "Linux") {
dest <- "/home/file.env" # Shouldn't be able to write into root's home dir
} else if ((Sys.info()[1] == "Windows")) {
dest <- "c:/Windows/system32/file.env" # Shouldn't be able to write into system dir
} else {
skip("Unknown OS")
}
expect_error(write_envelope(env, dest), "Permission denied")
})

0 comments on commit 483701a

Please sign in to comment.