diff --git a/NEWS.md b/NEWS.md index 87ee727e..261c5ac4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # httr (development version) +* An internal helper that checks for an interactive session in the OOB flow now + honors the `"rlang_interactive"` global option, in case it's necessary to + declare the session to be interactive (enough) for OOB (@jennybc, #734). + # httr 1.4.4 * Fix intermittent failing test. diff --git a/R/oauth-init.R b/R/oauth-init.R index c44477d7..0cdf0762 100644 --- a/R/oauth-init.R +++ b/R/oauth-init.R @@ -211,8 +211,12 @@ check_scope <- function(x) { paste(x, collapse = " ") } -# Wrap base::interactive in a non-primitive function so that the call can be mocked for testing -is_interactive <- function() interactive() +# gargle needs to access (pseudo-)OOB flow from Google Colab, so we need to +# be able to use the "rlang_interactive" option to signal that we are in +# an environment that is interactive (enough) to complete this flow. +is_interactive <- function() { + getOption("rlang_interactive") %||% interactive() +} check_oob <- function(use_oob, oob_value = NULL) { if (!is.logical(use_oob) || length(use_oob) != 1) { diff --git a/tests/testthat/test-oauth.R b/tests/testthat/test-oauth.R index 563c51f2..fdd24643 100644 --- a/tests/testthat/test-oauth.R +++ b/tests/testthat/test-oauth.R @@ -111,13 +111,19 @@ test_that("oob must be a flag", { }) test_that("can not use oob in non-interactive session", { + old <- options() + on.exit(options(old)) + options(rlang_interactive = FALSE) + expect_error(check_oob(TRUE), "interactive") }) test_that("can not use custom oob value without enabling oob", { testthat::skip_if_not_installed("httpuv") - with_mock( - `httr:::is_interactive` = function() TRUE, - expect_error(check_oob(FALSE, "custom_value"), "custom oob value") - ) + + old <- options() + on.exit(options(old)) + options(rlang_interactive = TRUE) + + expect_error(check_oob(FALSE, "custom_value"), "custom oob value") })