Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# gargle (development version)

* Fixed a bug in an internal helper that validates input specifying a service
account. The helper targets a common mistake where the JSON for an OAuth
client is provided to an argument that is meant for a service account (#270).

# gargle 1.5.1

* Completed some overlooked, unfinished work around the OAuth "app" to "client"
Expand Down
8 changes: 4 additions & 4 deletions R/credentials_service_account.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ check_is_service_account <- function(path, hint, call = caller_env()) {
return(invisible())
}

tryCatch(
info <- jsonlite::fromJSON(path, simplifyVector = FALSE),
error = NULL
info <- tryCatch(
jsonlite::fromJSON(path, simplifyVector = FALSE),
error = function(e) NULL
)

if (!is.null(info) && !identical(info[["type"]], "service_account")) {
if (is.null(info) || !identical(info[["type"]], "service_account")) {
cli::cli_abort(c(
"{.arg path} does not represent a service account.",
"Did you provide the JSON for an OAuth client instead of for a \\
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/credentials_service_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@
Did you provide the JSON for an OAuth client instead of for a service account?
Use `PKG_auth_configure()` to configure the OAuth client.

# check_is_service_account() errors for invalid input

Code
PKG_auth("wut")
Condition
Error in `PKG_auth()`:
! `path` does not represent a service account.
Did you provide the JSON for an OAuth client instead of for a service account?
Use `PKG_auth_configure()` to configure the OAuth client.

11 changes: 11 additions & 0 deletions tests/testthat/test-credentials_service_account.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ test_that("check_is_service_account() errors for OAuth client", {
)
)
})

test_that("check_is_service_account() errors for invalid input", {
# call indirectly, so we can also check the caller is reported
PKG_auth <- function(path) {
check_is_service_account(path, hint = "PKG_auth_configure")
}
expect_snapshot(
error = TRUE,
PKG_auth("wut")
)
})