File: test_ssl_ctx.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
test_that("ssl-ctx integration works", {
  skip_if_not_installed('curl')
  skip_if(packageVersion('curl') < '4.3.3')
  skip_if_not(ssl_ctx_curl_version_match())

  test <- download_ssl_cert('cran.r-project.org')[[1]]

  cb1 <- function(cert){
    identical(test, cert)
  }

  cb2 <- function(cert){
    #print("Rejecting cert...")
    FALSE
  }

  h1 <- curl::new_handle(forbid_reuse = TRUE, ssl_ctx_function = function(ssl_ctx){
    ssl_ctx_set_verify_callback(ssl_ctx, cb1)
  })
  req1 <- curl::curl_fetch_memory('https://cran.r-project.org', handle = h1)
  expect_equal(req1$status_code, 200)

  h2 <- curl::new_handle(forbid_reuse = TRUE, ssl_ctx_function = function(ssl_ctx){
    ssl_ctx_set_verify_callback(ssl_ctx, cb2)
  })

  expect_error(curl::curl_fetch_memory('https://cran.r-project.org', handle = h2), "certificate")
})