Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log in again after expiry #57

Merged
merged 1 commit into from
Jan 9, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow
Title: High Performance Computing
Version: 0.2.7
Version: 0.2.8
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow.windows
Title: DIDE HPC Support for Windows
Version: 0.2.7
Version: 0.2.8
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
5 changes: 4 additions & 1 deletion drivers/windows/R/web.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ api_client <- R6::R6Class(
r <- verb(url, ...)
status <- httr::status_code(r)
if (status %in% c(401, 403)) {
stop("Please login first")
cli::cli_alert_warning(
"Trying to login again, previous session likely expired")
self$login(public, refresh = TRUE)
r <- verb(url, ...)
}
httr::stop_for_status(r)
r
Expand Down
30 changes: 24 additions & 6 deletions drivers/windows/tests/testthat/test-web.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,42 @@ test_that("logout uses correct endpoint", {

test_that("request handles http requests", {
verb <- mockery::mock(mock_response(200),
mock_response(403),
mock_response(400))
credentials <- example_credentials()
cl <- api_client$new(credentials)
data <- list(a = 1, b = 2)
cl$request(verb, "/path/to", data = data, public = TRUE)
expect_error(
cl$request(verb, "/path/to", data = data, public = TRUE),
"Please login first")
expect_error(
cl$request(verb, "/path/to", data = data, public = TRUE),
"400")

mockery::expect_called(verb, 3)
mockery::expect_called(verb, 2)
expect_equal(
mockery::mock_args(verb),
rep(list(list("https://mrcdata.dide.ic.ac.uk/hpc/path/to",
data = data)), 2))
})


test_that("request logs back in after expiry", {
verb <- mockery::mock(mock_response(403),
mock_response(200))
credentials <- example_credentials()
cl <- api_client$new(credentials)

mock_login <- mockery::mock()
mockery::stub(cl$request, "self$login", mock_login)

expect_message(
r <- cl$request(verb, "/path/to", data = data, public = FALSE),
"Trying to login again, previous session likely expired")
expect_equal(r, mock_response(200))

mockery::expect_called(verb, 2)
expect_equal(
mockery::mock_args(verb),
rep(list(list("https://mrcdata.dide.ic.ac.uk/hpc/path/to",
data = data)), 3))
data = data)), 2))
})


Expand Down