File: test_credentials.R

package info (click to toggle)
r-cran-urltools 1.7.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 516 kB
  • sloc: cpp: 1,234; ansic: 303; sh: 13; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,590 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
testthat::context("Test credential extraction and getting")

testthat::test_that("Credentials can be stripped", {
  testthat::expect_identical(strip_credentials("http://foo:bar@97.77.104.22:3128"), "http://97.77.104.22:3128")
})

testthat::test_that("Strings with invalidly-placed credentials are left alone", {
  testthat::expect_identical(strip_credentials("htt@p://foo:bar97.77.104.22:3128"), "htt@p://foo:bar97.77.104.22:3128")
})

testthat::test_that("Invalid URLs are left alone", {
  testthat::expect_identical(strip_credentials("foo:bar@97.77.104.22:3128"), "foo:bar@97.77.104.22:3128")
})

testthat::test_that("Non-objects are left alone", {
  testthat::expect_true(is.na(strip_credentials(NA_character_)))
})

testthat::test_that("Credentials can be retrieved", {
  data <- get_credentials("http://foo:bar@97.43.5421")
  testthat::expect_identical(data$username, "foo")
  testthat::expect_identical(data$authentication, "bar")
})

testthat::test_that("Strings with invalidly-placed credentials are left alone", {
  data <- get_credentials("htt@p://foo:bar97.77.104.22:3128")
  testthat::expect_true(is.na(data$username))
  testthat::expect_true(is.na(data$authentication))
})

testthat::test_that("Invalid URLs are left alone", {
  data <- get_credentials("foo:bar@97.77.104.22:3128")
  testthat::expect_true(is.na(data$username))
  testthat::expect_true(is.na(data$authentication))
})

testthat::test_that("Non-objects are left alone", {
  data <- get_credentials(NA_character_)
  testthat::expect_true(is.na(data$username))
  testthat::expect_true(is.na(data$authentication))
})