This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steph Locke
committed
Mar 18, 2016
1 parent
164d295
commit 5419a30
Showing
6 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Get all (nonsensitive) breached sites in HIBP | ||
#' | ||
#' @param domain Search a specific domain | ||
#' @param ... Optional passthrough to HIBP_headers() | ||
#' | ||
#' @return Data.frame containing breach details | ||
#' @export | ||
#' | ||
#' @examples | ||
#' breached_sites() | ||
breached_sites<-function(domain=NULL,...){ | ||
if(!is.null(domain)&( | ||
length(domain)!=1 |!inherits(domain,"character")) ) stop("Problematic domain") | ||
URLS<-"https://haveibeenpwned.com/api/breaches" | ||
if(!is.null(domain)) URLS<- urltools::param_set(URLS,"domain",urltools::url_encode(domain)) | ||
|
||
res<- GETcontent(URLS, HIBP_headers(...)) | ||
if(identical(res,list())) res<-data.frame(Title=NA,Name=NA,Domain=domain, | ||
BreachDate=NA,AddedDate=NA,PwnCount=NA, | ||
Description=NA,DataClasses=NA,IsVerified=NA, | ||
IsSensitive=NA,LogoType=NA ) | ||
return(res) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
context("breached-sites") | ||
|
||
test_that("breached_sites works",{ | ||
|
||
# Simplest usage scenario | ||
res<-breached_sites() | ||
|
||
expect_is(res, "data.frame") | ||
expect_gt(ncol(res),1) | ||
expect_gt(nrow(res),1) | ||
|
||
# With domain (known breach) | ||
res<-breached_sites(domain = "adobe.com") | ||
|
||
expect_is(res, "data.frame") | ||
expect_gt(ncol(res),1) | ||
expect_equal(nrow(res),1) | ||
|
||
# With domain (no breach) | ||
res<-breached_sites(domain = "xyz.com") | ||
|
||
expect_is(res, "data.frame") | ||
expect_gt(ncol(res),1) | ||
expect_equal(nrow(res),1) | ||
|
||
# With header passthrough | ||
expect_error(breached_sites(agent="blah"),NA) | ||
|
||
}) | ||
|
||
|
||
test_that("handles incorrect values",{ | ||
errors<-"Problematic domain" | ||
|
||
expect_error(breached_sites(TRUE),errors) | ||
expect_error(breached_sites(as.character(c())),errors) | ||
expect_error(breached_sites(rep(errors,2)),errors) | ||
|
||
}) |