Skip to content

Commit

Permalink
Merge pull request #57 from mrc-ide/mrc-4712
Browse files Browse the repository at this point in the history
Log in again after expiry
  • Loading branch information
weshinsley authored Jan 9, 2024
2 parents 5fadeae + 5515bf3 commit f925bef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
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

0 comments on commit f925bef

Please sign in to comment.