Skip to content

Commit

Permalink
switch more credential checking to dev-2
Browse files Browse the repository at this point in the history
ref #539
  • Loading branch information
wibeasley committed Oct 13, 2024
1 parent 3158d03 commit 28dc850
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
5 changes: 2 additions & 3 deletions R/helpers-testing.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
retrieve_credential_testing <- function(project_tag = "simple", server_instance = "bbmc", username = NA_character_) {
retrieve_credential_testing <- function(project_tag = "simple", server_instance = "dev-2", username = NA_character_) {
checkmate::assert_character(project_tag , any.missing = FALSE, min.chars = 2, max.chars = 50)
checkmate::assert_character(server_instance , any.missing = FALSE, min.chars = 2, max.chars = 50)
checkmate::assert_character(username , any.missing = TRUE , min.chars = 2, max.chars = 50)
Expand All @@ -12,7 +12,6 @@ retrieve_credential_testing <- function(project_tag = "simple", server_instance
call. = FALSE
)
}

d_map <-
system.file("misc/project-redirection.yml", package = "REDCapR") |>
yaml::yaml.load_file(
Expand Down Expand Up @@ -44,7 +43,7 @@ retrieve_credential_testing <- function(project_tag = "simple", server_instance
)
}

REDCapR::retrieve_credential_local(
retrieve_credential_local(
path_credential = path_credential, # "misc/example.credentials"
project_id = d_map$project_id,
username = username
Expand Down
4 changes: 2 additions & 2 deletions inst/misc/bad.credentials
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# are stored securely.
#
redcap_uri,username,project_id,token,comment
"http://bbmc.ouhsc.edu/redcap/api/","myusername","153","9A81268476645C4E5F03428B8A","simple static (read-only) test project"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","212","D70F9ACD1EDD6F151C6EA78683944E98","simple write data"
"http://bbmc.ouhsc.edu/redcap/api/","myusername","33","9A81268476645C4E5F03428B8A","simple static (read-only) test project"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","34","D70F9ACD1EDD6F151C6EA78683944E98","simple write data"
2 changes: 1 addition & 1 deletion inst/misc/project-redirection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- vignette-repeating: 3181
-
instance: dev-2
credential_file: "misc/example.credentials"
credential_file: "misc/dev-2.credentials"
projects:
- simple: 33
- longitudinal: 34
Expand Down
51 changes: 21 additions & 30 deletions tests/testthat/test-retrieve-credential-local.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
library(testthat)

path <- system.file("misc/example.credentials", package="REDCapR")
pid_read <- 153L # This project is for testing only reading from the server.
# pid_longitudinal <- 212L # This project is for testing reading longitudinal projects.
# pid_write <- 213L # This project is for testing reading & writing.
# pid_dag <- 2545L #This project is for testing DAGs.
path <- system.file("misc/dev-2.credentials", package="REDCapR")
pid_read <- 33L # This project is for testing only reading from the server.
# pid_longitudinal <- 34L # This project is for testing reading longitudinal projects.
# pid_write <- 35L # This project is for testing reading & writing.
# pid_dag <- 49L #This project is for testing DAGs.

test_that("Good Credentials", {
expected_read_redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
expected_read_redcap_uri <- "https://redcap-dev-2.ouhsc.edu/redcap/api/"
expected_read_username <- "myusername"
# expected_read_project_id <- pid_read
expected_read_token <- "9A81268476645C4E5F03428B8AC3AA7B"
expected_read_comment <- "simple static (read-only) test project"
expected_read_token <- "9A068C425B1341D69E83064A2D273A70"
expected_read_comment <- "simple"

expected_longitudinal_redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
expected_longitudinal_redcap_uri <- "https://redcap-dev-2.ouhsc.edu/redcap/api/"
expected_longitudinal_username <- "myusername"
# expected_longitudinal_project_id <- pid_longitudinal
expected_longitudinal_token <- "0434F0E9CF53ED0587847AB6E51DE762"
expected_longitudinal_comment <- "longitudinal (read-only) ARM test project"
expected_longitudinal_token <- "DA6F2BB23146BD5A7EA3408C1A44A556"
expected_longitudinal_comment <- "longitudinal"

expected_write_redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
expected_write_redcap_uri <- "https://redcap-dev-2.ouhsc.edu/redcap/api/"
expected_write_username <- "myusername"
# expected_write_project_id <- pid_write
expected_write_token <- "D70F9ACD1EDD6F151C6EA78683944E98"
expected_write_comment <- "simple write data"
expected_write_token <- "F9CBFFF78C3D78F641BAE9623F6B7E6A"
expected_write_comment <- "simple-write"

credential_read <- retrieve_credential_testing() # This project is for testing only reading from the server.
credential_longitudinal <- retrieve_credential_testing("longitudinal") # This project is for testing reading longitudinal projects.
Expand All @@ -48,17 +48,17 @@ test_that("Good Credentials", {
expect_equal(credential_write$comment , expected_write_comment)
})
test_that("Multiple users", {
expected_admin_redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
expected_admin_redcap_uri <- "https://redcap-dev-2.ouhsc.edu/redcap/api/"
expected_admin_username <- "admin"
# expected_admin_project_id <- pid_dag
expected_admin_token <- "0BF11B9CB01F0B8F8EE203B7E07DEFD9"
expected_admin_comment <- "DAG Write -admin"
expected_admin_token <- "F6F871FE0322EEE8D23F56DBBE23B756"
expected_admin_comment <- "dag-write --admin"

expected_user_redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
expected_user_redcap_uri <- "https://redcap-dev-2.ouhsc.edu/redcap/api/"
expected_user_username <- "user-dag1"
# expected_user_project_id <- pid_dag
expected_user_token <- "C79DB3836373478986928303B52E74DF"
expected_user_comment <- "DAG Write -group A"
expected_user_token <- "8092B2302CAA359C4F5641AEC1CE72ED"
expected_user_comment <- "dag-write --group A"

credential_admin <- retrieve_credential_testing(username = expected_admin_username)
credential_user <- retrieve_credential_testing(username = expected_user_username)
Expand All @@ -75,7 +75,6 @@ test_that("Multiple users", {
expect_equal(credential_user$token , expected_user_token)
expect_equal(credential_user$comment , expected_user_comment)
})

test_that("Missing file", {
expected_message <- "Assertion on 'path_credential' failed: File does not exist: 'misc/missing.credentials'."

Expand All @@ -98,7 +97,6 @@ test_that("Malformed file", {
)
)
})

test_that("Zero rows", {
expected_message <- "The project_id was not found in the csv credential file."

Expand All @@ -110,7 +108,6 @@ test_that("Zero rows", {
)
)
})

test_that("Zero matching rows", {
expected_message <- "The project_id was not found in the csv credential file."

Expand All @@ -122,7 +119,6 @@ test_that("Zero matching rows", {
)
)
})

test_that("Conflicting rows", {
expected_message <- "More than one matching project_id was found in the csv credential file. There should be only one."

Expand All @@ -134,7 +130,6 @@ test_that("Conflicting rows", {
)
)
})

test_that("Bad URI", {
expected_message <- "The REDCap URL does not reference an https address\\."

Expand All @@ -149,7 +144,6 @@ test_that("Bad URI", {
)
)
})

test_that("Bad Username", {
expected_message <- "doesn't match the username in the credentials file."

Expand All @@ -164,7 +158,6 @@ test_that("Bad Username", {
)
)
})

test_that("Bad URI", {
expected_message <- "A REDCap token should be a string of 32 digits and uppercase characters. The retrieved value was not. Set the `check_token_pattern` parameter to FALSE if you're sure you have the correct file & file contents."

Expand All @@ -180,6 +173,4 @@ test_that("Bad URI", {
)
})

# rm(credential_read )
# rm(credential_longitudinal )
# rm(credential_write )
rm(path, pid_read)

0 comments on commit 28dc850

Please sign in to comment.