File: test-auth.R

package info (click to toggle)
r-cran-crul 1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: sh: 13; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (2)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
context("authenticate")

test_that("auth construction works", {
  skip_on_cran()

  basic <- auth(user = "foo", pwd = "bar", auth = "basic")
  digest <- auth(user = "foo", pwd = "bar", auth = "digest")
  ntlm <- auth(user = "foo", pwd = "bar", auth = "ntlm")
  any <- auth(user = "foo", pwd = "bar", auth = "any")

  expect_is(basic, "auth")
  expect_is(digest, "auth")
  expect_is(ntlm, "auth")
  expect_is(any, "auth")

  expect_named(basic, c('userpwd', 'httpauth'))
  expect_named(digest, c('userpwd', 'httpauth'))
  expect_named(ntlm, c('userpwd', 'httpauth'))
  expect_named(any, c('userpwd', 'httpauth'))

  expect_equal(attr(basic, "type"), "basic")
  expect_equal(attr(digest, "type"), "digest")
  expect_equal(attr(ntlm, "type"), "ntlm")
  expect_equal(attr(any, "type"), "any")
})

test_that("auth works with HttpClient", {
  skip_on_cran()

  aa <- HttpClient$new(
    url = hb("/basic-auth/user/passwd"),
    auth = auth(user = "foo", pwd = "bar")
  )

  expect_is(aa, "HttpClient")
  expect_is(aa$auth, "auth")
  expect_equal(aa$auth$userpwd, "foo:bar")
  expect_equal(aa$auth$httpauth, 1)
})

test_that("auth works with HttpRequest", {
  skip_on_cran()

  aa <- HttpRequest$new(
    url = hb("/basic-auth/user/passwd"),
    auth = auth(user = "foo", pwd = "bar")
  )

  expect_is(aa, "HttpRequest")
  expect_is(aa$auth, "auth")
  expect_equal(aa$auth$userpwd, "foo:bar")
  expect_equal(aa$auth$httpauth, 1)
})

test_that("auth fails well", {
  skip_on_cran()
  
  expect_error(auth(), "argument \"user\" is missing")
  expect_error(auth(user = "asdf"), "argument \"pwd\" is missing")
  expect_error(auth(5, 5), "user must be of class character")
  expect_error(auth("adsf", 5), "pwd must be of class character")
  expect_error(
    auth("asdf", "asdf", 5), "inherits\\(x, \"character\"\\) is not TRUE")
})