Skip to content

Commit

Permalink
add IgnoreHTTPS option
Browse files Browse the repository at this point in the history
  • Loading branch information
kylrth committed May 26, 2022
1 parent 30c65fa commit 05eb4e5
Show file tree
Hide file tree
Showing 6 changed files with 4,812 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ htmltest uses a YAML configuration file. Put `.htmltest.yml` in the same directo
| `EnforceHTTPS` | Fails when encountering an `http://` link. Useful to prevent mixed content errors when serving over HTTPS. | `false` |
| `IgnoreURLs` | Array of regexs of URLs to ignore. | empty |
| `IgnoreInternalURLs` | Array of strings of internal URLs to ignore. Exact matches only. ⚠ Likely to be deprecated, use `IgnoreURLs` instead. | empty |
| `IgnoreHTTPS` | Array of regexs of URLs to ignore for `EnforceHTTPS`. These URLs are still tested, unless also present in `IgnoreURLs`. | empty |
| `IgnoreDirs` | Array of regexs of directories to ignore when scanning for HTML files. | empty |
| `IgnoreInternalEmptyHash` | When true prevents raising an error for links with `href="#"`. | `false` |
| `IgnoreEmptyHref` | When true prevents raising an error for links with `href=""`. | `false` |
Expand Down
4 changes: 3 additions & 1 deletion htmltest/check-generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ func (hT *HTMLTest) checkGenericRef(ref *htmldoc.Reference) {
}

func (hT *HTMLTest) enforceHTTPS(ref *htmldoc.Reference) {
urlStr := ref.URLString()

// Does this url match an url ignore rule?
if hT.opts.isURLIgnored(ref.URLString()) {
if hT.opts.isURLIgnored(urlStr) || hT.opts.isInsecureURLIgnored(urlStr) {
return
}
issueLevel := issues.LevelError
Expand Down
13 changes: 13 additions & 0 deletions htmltest/check-link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ func TestAnchorExternalInsecureOptionIgnored(t *testing.T) {
tExpectIssueCount(t, hT, 0)
}

func TestAnchorExternalInsecureOptionIgnoredInsecure(t *testing.T) {
// checks non-HTTPS links when they're in the IgnoreHTTPS list
hT := tTestFileOpts("fixtures/links/non_https_ignore.html",
map[string]interface{}{
"EnforceHTTPS": true,
"IgnoreHTTPS": []interface{}{`ben\.balter\.com`, `doesntexist\.io`},
"VCREnable": true,
})
tExpectIssueCount(t, hT, 2)
tExpectIssue(t, hT, "is not an HTTPS target", 1)
tExpectIssue(t, hT, "Non-OK status", 1)
}

func TestAnchorExternalHrefIP(t *testing.T) {
// fails for broken IP address links
hT := tTestFileOpts("fixtures/links/ip_href.html",
Expand Down
12 changes: 12 additions & 0 deletions htmltest/fixtures/links/non_https_ignore.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>

<body>

<a href="http://ben.balter.com">insecure, valid, ignored</a>
<a href="https://example.com">secure, valid</a>
<a href="http://kylrth.com">insecure, valid</a>
<a href="http://doesntexist.io">insecure, invalid, ignored</a>

</body>

</html>
Loading

0 comments on commit 05eb4e5

Please sign in to comment.