throw exception if username, password is not set in http auth in r client (#13035)

This commit is contained in:
William Cheng
2022-07-28 17:06:52 +08:00
committed by GitHub
parent c905760898
commit e5e4e8fc07
3 changed files with 20 additions and 2 deletions

View File

@@ -308,6 +308,17 @@
{{#isBasic}}
{{#isBasicBasic}}
# HTTP basic auth
if (is.null(self$api_client$username) || is.null(self$api_client$password)) {
{{#useDefaultExceptionHandling}}
stop("username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.")
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`.",
.subclass = "ApiException",
ApiException = ApiException$new(status = 0,
reason = "username, password in `api_client` must be set for authentication in the endpoint `{{{operationId}}}`."))
{{/useRlangExceptionHandling}}
}
header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
{{/isBasicBasic}}
{{#isBasicBearer}}

View File

@@ -586,6 +586,12 @@ PetApi <- R6::R6Class(
local_var_url_path <- "/pet"
# HTTP basic auth
if (is.null(self$api_client$username) || is.null(self$api_client$password)) {
rlang::abort(message = "username, password in `api_client` must be set for authentication in the endpoint `AddPet`.",
.subclass = "ApiException",
ApiException = ApiException$new(status = 0,
reason = "username, password in `api_client` must be set for authentication in the endpoint `AddPet`."))
}
header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
# The Accept request HTTP header

View File

@@ -11,8 +11,9 @@ pet <- Pet$new("name_test",
),
status = "available"
)
pet_api$api_client$username <- "username123"
pet_api$api_client$password <- "password123"
pet_api$api_client$username <- ""
pet_api$api_client$password <- ""
result <- pet_api$AddPet(pet)
test_that("Test toJSONString", {