tests/testthat/test-Auth.R

# Tests for the Auth.R file

# I don't think Auth.R can be tested with mocks

testBaseUrl <- Sys.getenv("WEBAPI_TEST_SECURE_WEBAPI_URL") 
testOhdsiUser <- Sys.getenv("WEBAPI_TEST_ADMIN_USER_NAME") 
testOhdsiPassword <- Sys.getenv("WEBAPI_TEST_ADMIN_USER_PASSWORD") 

test_that("Database authorization works", {
  skip("Skipping authentication unit test until test server is back up")
  skip_if(testBaseUrl == "")
  setAuthHeader(testBaseUrl, "blah")
  expect_error(getPriorityVocabularyKey(testBaseUrl), "Unauthorized")
  authorizeWebApi(testBaseUrl, "db", testOhdsiUser, testOhdsiPassword)
  expect_type(getPriorityVocabularyKey(testBaseUrl), "character")
})

test_that("Active Directory Authorization", {
  skip("Skipping authentication unit test until test server is back up")
  skip_if(testBaseUrl == "")
  expect_error(authorizeWebApi(testBaseUrl, "ad", testOhdsiUser, testOhdsiPassword), "fail")
})
OHDSI/ROhdsiWebApi documentation built on March 15, 2023, 1:23 p.m.