зеркало из https://github.com/Azure/AzureAuth.git
testing work
This commit is contained in:
Родитель
513168a286
Коммит
2a469be416
14
R/classes.R
14
R/classes.R
|
@ -301,16 +301,11 @@ AzureTokenCLI <- R6::R6Class("AzureTokenCLI",
|
|||
{
|
||||
tryCatch(
|
||||
{
|
||||
result <- system2(
|
||||
"az",
|
||||
args = c(
|
||||
"account", "get-access-token", "--output json",
|
||||
paste0("--resource ", self$resource)
|
||||
),
|
||||
stdout = TRUE
|
||||
)
|
||||
cmd <- build_access_token_cmd(resource = self$resource,
|
||||
tenant = self$tenant)
|
||||
result <- do.call(system2, append(cmd, list(stdout = TRUE)))
|
||||
# result is a multi-line JSON string, concatenate together
|
||||
paste(result, collapse = "")
|
||||
paste0(result)
|
||||
},
|
||||
warning = function(cond)
|
||||
{
|
||||
|
@ -334,6 +329,7 @@ AzureTokenCLI <- R6::R6Class("AzureTokenCLI",
|
|||
process_response = function(res)
|
||||
{
|
||||
# Parse the JSON from the CLI and fix the names to snake_case
|
||||
message(res)
|
||||
ret <- jsonlite::parse_json(res)
|
||||
list(
|
||||
token_type = ret$tokenType,
|
||||
|
|
14
R/utils.R
14
R/utils.R
|
@ -147,3 +147,17 @@ in_shiny <- function()
|
|||
{
|
||||
("shiny" %in% loadedNamespaces()) && shiny::isRunning()
|
||||
}
|
||||
|
||||
build_access_token_cmd <- function(command="az", resource, tenant)
|
||||
{
|
||||
if (Sys.which(command) == "")
|
||||
{
|
||||
stop(paste(command, "is not installed."))
|
||||
}
|
||||
args <- c(
|
||||
"account", "get-access-token", "--output json",
|
||||
paste("--resource", resource),
|
||||
paste("--tenant", tenant)
|
||||
)
|
||||
list(command = command, args = args)
|
||||
}
|
|
@ -4,32 +4,62 @@ test_that("cli auth_type can be selected",
|
|||
expect_equal(auth_type, "cli")
|
||||
})
|
||||
|
||||
test_that("token is successfully retrieved if user is logged in",
|
||||
{
|
||||
fail("TODO")
|
||||
})
|
||||
|
||||
test_that("az login is called if the user is not already logged in",
|
||||
{
|
||||
fail("TODO")
|
||||
})
|
||||
|
||||
test_that("the output of az login is handled appropriately",
|
||||
{
|
||||
fail("TODO")
|
||||
res <- paste(
|
||||
'{ "accessToken": "eyJ0",',
|
||||
'"expiresOn": "2022-09-23 23:35:16.000000",',
|
||||
'"tenant": "microsoft.com", "tokenType": "Bearer"}'
|
||||
)
|
||||
TestClass <- R6::R6Class(inherit = AzureTokenCLI,
|
||||
public = list(
|
||||
initialize = function() { self$resource <- "foo" },
|
||||
run_test = function() {
|
||||
private$process_response(res)
|
||||
}
|
||||
)
|
||||
)
|
||||
expected <- list(token_type = "Bearer",
|
||||
access_token = "eyJ0",
|
||||
expires_on = 1664001316,
|
||||
resource = "foo")
|
||||
tc <- TestClass$new()
|
||||
expect_equal(expected, tc$run_test())
|
||||
})
|
||||
|
||||
test_that("the appropriate error is thrown when az is not installed",
|
||||
{
|
||||
fail("TODO")
|
||||
expect_error(build_access_token_cmd("bnrwfq", resource = "foo", tenant = "bar"),
|
||||
regexp = "bnrwfq is not installed.")
|
||||
})
|
||||
|
||||
if (Sys.which("az") == "")
|
||||
skip("az not installed, skipping tests.")
|
||||
|
||||
# cond <- system2("az", args = c("account show"), stdout = TRUE)
|
||||
# not_loggedin <- grepl("az login", cond, fixed = TRUE) |
|
||||
# grepl("az account set", cond, fixed = TRUE)
|
||||
# if (not_loggedin)
|
||||
# skip("az not logged in, skipping tests.")
|
||||
|
||||
test_that("the appropriate error is thrown when the resource is invalid",
|
||||
{
|
||||
|
||||
fail("TODO")
|
||||
})
|
||||
|
||||
test_that("the appropriate error is thrown when az login fails",
|
||||
{
|
||||
fail("TODO")
|
||||
})
|
||||
|
||||
|
||||
test_that("az login is called if the user is not already logged in",
|
||||
{
|
||||
fail("TODO")
|
||||
})
|
||||
|
||||
test_that("token is successfully retrieved if user is logged in",
|
||||
{
|
||||
fail("TODO")
|
||||
})
|
Загрузка…
Ссылка в новой задаче