| 1 |
# Some of these unit tests fail if you reuse the handle. Don't know why. Maybe cache related. |
| 2 |
|
| 3 |
test_that("Permission denied", { |
| 4 |
h <- new_handle() |
| 5 |
expect_equal(curl_fetch_memory(httpbin("basic-auth/jerry/secret"), handle = h)$status, 401) |
| 6 |
expect_equal(curl_fetch_memory(httpbin("hidden-basic-auth/jerry/secret"), handle = h)$status, 404) |
| 7 |
expect_equal(curl_fetch_memory(httpbin("digest-auth/auth/jerry/secret"), handle = h)$status, 401) |
| 8 |
}) |
| 9 |
|
| 10 |
test_that("Auth userpwd", { |
| 11 |
h <- new_handle() |
| 12 |
handle_setopt(h, userpwd = "jerry:secret") |
| 13 |
expect_equal(curl_fetch_memory(httpbin("basic-auth/jerry/secret"), handle = h)$status, 200) |
| 14 |
expect_equal(curl_fetch_memory(httpbin("hidden-basic-auth/jerry/secret"), handle = h)$status, 200) |
| 15 |
expect_equal(curl_fetch_memory(httpbin("digest-auth/auth/jerry/secret"), handle = h)$status, 200) |
| 16 |
}) |
| 17 |
|
| 18 |
test_that("Auth username and password", { |
| 19 |
h <- new_handle() |
| 20 |
handle_setopt(h, username = "jerry", password = "secret") |
| 21 |
expect_equal(curl_fetch_memory(httpbin("basic-auth/jerry/secret"), handle = h)$status, 200) |
| 22 |
expect_equal(curl_fetch_memory(httpbin("hidden-basic-auth/jerry/secret"), handle = h)$status, 200) |
| 23 |
expect_equal(curl_fetch_memory(httpbin("digest-auth/auth/jerry/secret"), handle = h)$status, 200) |
| 24 |
}) |
| 25 |
|
| 26 |
test_that("NetRC file works",{ |
| 27 |
skip_on_cran() |
| 28 |
expect_equal(curl_fetch_memory(httpbin("basic-auth/user/yes"))$status, 401) |
| 29 |
netrc <- tempfile(fileext = '.rc') |
| 30 |
writeLines(c('default', ' login user', ' password yes'), netrc) |
| 31 |
h <- new_handle(netrc = 1L, netrc_file = netrc) |
| 32 |
expect_equal(curl_fetch_memory(httpbin("basic-auth/user/yes"), handle = h)$status, 200) |
| 33 |
}) |
| 34 |
|
| 35 |
test_that("GC works", { |
| 36 |
gc() |
| 37 |
expect_equal(total_handles(), 0L) |
| 38 |
}) |