зеркало из https://github.com/Azure/AzureKeyVault.git
add host header, test char token
This commit is contained in:
Родитель
59bf9a4ae5
Коммит
070bbf65e6
|
@ -3,8 +3,6 @@ call_vault_url <- function(token, url, ..., body=NULL, encode="json",
|
|||
http_verb=c("GET", "DELETE", "PUT", "POST", "HEAD", "PATCH"),
|
||||
http_status_handler=c("stop", "warn", "message", "pass"))
|
||||
{
|
||||
headers <- process_headers(token, ...)
|
||||
|
||||
if(!inherits(url, "url"))
|
||||
url <- httr::parse_url(url)
|
||||
|
||||
|
@ -12,6 +10,7 @@ call_vault_url <- function(token, url, ..., body=NULL, encode="json",
|
|||
url$query <- list()
|
||||
|
||||
url$query <- utils::modifyList(url$query, list(`api-version`=api_version))
|
||||
headers <- process_headers(token, url)
|
||||
|
||||
# if content-type is json, serialize it manually to ensure proper handling of nulls
|
||||
if(encode == "json")
|
||||
|
@ -26,9 +25,10 @@ call_vault_url <- function(token, url, ..., body=NULL, encode="json",
|
|||
}
|
||||
|
||||
|
||||
process_headers <- function(token, ...)
|
||||
process_headers <- function(token, url)
|
||||
{
|
||||
headers <- c(
|
||||
Host=url$hostname,
|
||||
Authorization=paste("Bearer", validate_token(token)),
|
||||
`Content-type`="application/json"
|
||||
)
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
context("Character string token")
|
||||
|
||||
tenant <- Sys.getenv("AZ_TEST_TENANT_ID")
|
||||
app <- Sys.getenv("AZ_TEST_APP_ID")
|
||||
password <- Sys.getenv("AZ_TEST_PASSWORD")
|
||||
vaultname <- Sys.getenv("AZ_TEST_KEYVAULT")
|
||||
|
||||
if(tenant == "" || app == "" || password == "" || vaultname == "")
|
||||
skip("Key tests skipped: vault credentials not set")
|
||||
|
||||
vault0 <- key_vault(vaultname, tenant=tenant, app=app, password=password)
|
||||
|
||||
try({
|
||||
vault0$keys$delete("chartokkey", confirm=FALSE)
|
||||
vault0$secrets$delete("chartoksecret", confirm=FALSE)
|
||||
vault0$certificates$delete("chartokcert", confirm=FALSE)
|
||||
}, silent=TRUE)
|
||||
|
||||
|
||||
test_that("Token as character string works",
|
||||
{
|
||||
token <- vault0$token$credentials$access_token
|
||||
expect_is(token, "character")
|
||||
|
||||
vault <- key_vault(vaultname, token=token)
|
||||
expect_is(vault, "AzureKeyVault")
|
||||
|
||||
key <- vault$keys$create("chartokkey")
|
||||
expect_true(inherits(key, "stored_key"))
|
||||
|
||||
secret <- vault$secrets$create("chartoksecret", "mysecretvalue")
|
||||
expect_true(inherits(secret, "stored_secret"))
|
||||
|
||||
cert <- vault$certificates$create("chartokcert",
|
||||
subject="CN=example.com",
|
||||
x509=cert_x509_properties(dns_names="example.com"))
|
||||
expect_true(inherits(cert, "stored_cert") && is.character(cert$cer))
|
||||
})
|
||||
|
||||
|
||||
vault0$keys$delete("chartokkey", confirm=FALSE)
|
||||
vault0$secrets$delete("chartoksecret", confirm=FALSE)
|
||||
vault0$certificates$delete("chartokcert", confirm=FALSE)
|
Загрузка…
Ссылка в новой задаче