Skip to content

Commit

Permalink
Add cases for single URL with(out) angle brackets
Browse files Browse the repository at this point in the history
Extend coverage for URLs with and without angle brackets.
This is less important for the GUI app (which is already
tested against this scenario) but should help with
future CLI app support for angle bracket enclosed input.

refs GH-251
  • Loading branch information
atc0005 committed Apr 8, 2024
1 parent 9cafbb0 commit 0fdd779
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 35 deletions.
133 changes: 98 additions & 35 deletions internal/safelinks/exported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ var (
//go:embed testdata/output/standalone/decoded-list-of-urls-with-lf-eol.txt
outputDecodedListOfURLsWithLFEol string

//go:embed testdata/output/standalone/decoded-single-url-with-crlf-eol.txt
outputDecodedSingleURLWithCRLFEol string
//go:embed testdata/output/standalone/decoded-single-url-with-angle-brackets-with-crlf-eol.txt
outputDecodedSingleURLWithAngleBracketsWithCRLFEol string

//go:embed testdata/output/standalone/decoded-single-url-with-lf-eol.txt
outputDecodedSingleURLWithLFEol string
//go:embed testdata/output/standalone/decoded-single-url-with-angle-brackets-with-lf-eol.txt
outputDecodedSingleURLWithAngleBracketsWithLFEol string

//go:embed testdata/output/standalone/decoded-single-url-without-angle-brackets-with-crlf-eol.txt
outputDecodedSingleURLWithoutAngleBracketsWithCRLFEol string

//go:embed testdata/output/standalone/decoded-single-url-without-angle-brackets-with-lf-eol.txt
outputDecodedSingleURLWithoutAngleBracketsWithLFEol string
)

// The format used by the test files is VERY specific; trailing space plus
Expand All @@ -106,17 +112,23 @@ var (
//go:embed testdata/input/encoded-all/email-without-angle-brackets-with-lf-eol.txt
inputEncodedAllEmailWithoutAngleBracketsWithLFEol string

//go:embed testdata/input/encoded-all/single-safelinks-url-with-crlf-eol.txt
inputEncodedSingleSafelinksURLWithCRLFEol string
//go:embed testdata/input/encoded-all/single-safelinks-url-with-angle-brackets-with-crlf-eol.txt
inputEncodedSingleSafelinksURLWithAngleBracketsWithCRLFEol string

//go:embed testdata/input/encoded-all/single-safelinks-url-with-angle-brackets-with-lf-eol.txt
inputEncodedSingleSafelinksURLWithAngleBracketsWithLFEol string

//go:embed testdata/input/encoded-all/single-safelinks-url-without-angle-brackets-with-crlf-eol.txt
inputEncodedSingleSafelinksURLWithoutAngleBracketsWithCRLFEol string

//go:embed testdata/input/encoded-all/single-safelinks-url-without-angle-brackets-with-lf-eol.txt
inputEncodedSingleSafelinksURLWithoutAngleBracketsWithLFEol string

//go:embed testdata/input/encoded-all/list-of-urls-with-crlf-eol.txt
inputEncodedAllListOfURLsWithCRLFEol string

//go:embed testdata/input/encoded-all/list-of-urls-with-lf-eol.txt
inputEncodedAllListOfURLsWithLFEol string

//go:embed testdata/input/encoded-all/single-safelinks-url-with-lf-eol.txt
inputEncodedSingleSafelinksURLWithLFEol string
)

// The format used by the test files is VERY specific; trailing space plus
Expand Down Expand Up @@ -236,12 +248,20 @@ func TestURLsFindsAllValidURLs(t *testing.T) {
input: inputEncodedAllListOfURLsWithCRLFEol,
foundURLsCount: 17,
},
"Encoded single URL with LF EOL": {
input: inputEncodedSingleSafelinksURLWithLFEol,
"Encoded single URL with angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithLFEol,
foundURLsCount: 1,
},
"Encoded single URL with angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithCRLFEol,
foundURLsCount: 1,
},
"Encoded single URL with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithCRLFEol,
"Encoded single URL without angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithLFEol,
foundURLsCount: 1,
},
"Encoded single URL without angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithCRLFEol,
foundURLsCount: 1,
},
"Encoded email with angle brackets with CRLF EOL": {
Expand Down Expand Up @@ -469,13 +489,23 @@ func TestFilterURLsCorrectlyFiltersByType(t *testing.T) {
foundEncodedLinksURLsCount: 17,
foundUnencodedURLsCount: 0,
},
"Encoded single URL with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithCRLFEol,
"Encoded single URL with angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithLFEol,
foundEncodedLinksURLsCount: 1,
foundUnencodedURLsCount: 0,
},
"Encoded single URL with angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithCRLFEol,
foundEncodedLinksURLsCount: 1,
foundUnencodedURLsCount: 0,
},
"Encoded single URL without angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithLFEol,
foundEncodedLinksURLsCount: 1,
foundUnencodedURLsCount: 0,
},
"Encoded single URL with LF EOL": {
input: inputEncodedSingleSafelinksURLWithLFEol,
"Encoded single URL without angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithCRLFEol,
foundEncodedLinksURLsCount: 1,
foundUnencodedURLsCount: 0,
},
Expand All @@ -490,13 +520,23 @@ func TestFilterURLsCorrectlyFiltersByType(t *testing.T) {
foundEncodedLinksURLsCount: 0,
foundUnencodedURLsCount: 17,
},
"Unencoded single URL with LF EOL": {
input: outputDecodedSingleURLWithLFEol,
"Unencoded single URL with angle brackets with LF EOL": {
input: outputDecodedSingleURLWithAngleBracketsWithLFEol,
foundEncodedLinksURLsCount: 0,
foundUnencodedURLsCount: 1,
},
"Unencoded single URL with CRLF EOL": {
input: outputDecodedSingleURLWithCRLFEol,
"Unencoded single URL with angle brackets with CRLF EOL": {
input: outputDecodedSingleURLWithAngleBracketsWithCRLFEol,
foundEncodedLinksURLsCount: 0,
foundUnencodedURLsCount: 1,
},
"Unencoded single URL without angle brackets with LF EOL": {
input: outputDecodedSingleURLWithoutAngleBracketsWithLFEol,
foundEncodedLinksURLsCount: 0,
foundUnencodedURLsCount: 1,
},
"Unencoded single URL without angle brackets with CRLF EOL": {
input: outputDecodedSingleURLWithoutAngleBracketsWithCRLFEol,
foundEncodedLinksURLsCount: 0,
foundUnencodedURLsCount: 1,
},
Expand Down Expand Up @@ -618,12 +658,20 @@ func TestSafeLinkURLsFindsAllValidSafeLinks(t *testing.T) {
input: inputEncodedAllListOfURLsWithLFEol,
foundEncodedURLsCount: 17,
},
"Encoded single URL with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithCRLFEol,
"Encoded single URL with angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithLFEol,
foundEncodedURLsCount: 1,
},
"Encoded single URL with angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithCRLFEol,
foundEncodedURLsCount: 1,
},
"Encoded single URL with LF EOL": {
input: inputEncodedSingleSafelinksURLWithLFEol,
"Encoded single URL without angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithLFEol,
foundEncodedURLsCount: 1,
},
"Encoded single URL without angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithCRLFEol,
foundEncodedURLsCount: 1,
},

Expand Down Expand Up @@ -705,14 +753,23 @@ func TestDecodeInputSucceedsForValidInput(t *testing.T) {
input: inputEncodedAllListOfURLsWithCRLFEol,
result: outputDecodedListOfURLsWithCRLFEol,
},
"Encoded single URL with LF EOL": {
input: inputEncodedSingleSafelinksURLWithLFEol,
result: outputDecodedSingleURLWithLFEol,
"Encoded single URL with angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithLFEol,
result: outputDecodedSingleURLWithAngleBracketsWithLFEol,
},
"Encoded single URL with angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithAngleBracketsWithCRLFEol,
result: outputDecodedSingleURLWithAngleBracketsWithCRLFEol,
},
"Encoded single URL without angle brackets with LF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithLFEol,
result: outputDecodedSingleURLWithoutAngleBracketsWithLFEol,
},
"Encoded single URL with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithCRLFEol,
result: outputDecodedSingleURLWithCRLFEol,
"Encoded single URL without angle brackets with CRLF EOL": {
input: inputEncodedSingleSafelinksURLWithoutAngleBracketsWithCRLFEol,
result: outputDecodedSingleURLWithoutAngleBracketsWithCRLFEol,
},

"Encoded email with angle brackets with CRLF EOL": {
input: inputEncodedAllEmailWithAngleBracketsWithCRLFEol,
result: outputDecodedEmailWithAngleBracketsWithCRLFEol,
Expand Down Expand Up @@ -791,11 +848,17 @@ func TestDecodeInputFailsForInvalidInput(t *testing.T) {
"Unencoded list of URLs with CRLF EOL": {
input: outputDecodedListOfURLsWithCRLFEol,
},
"Unencoded single URL with LF EOL": {
input: outputDecodedSingleURLWithLFEol,
"Unencoded single URL with angle brackets with LF EOL": {
input: outputDecodedSingleURLWithAngleBracketsWithLFEol,
},
"Unencoded single URL with angle brackets with CRLF EOL": {
input: outputDecodedSingleURLWithAngleBracketsWithCRLFEol,
},
"Unencoded single URL without angle brackets with LF EOL": {
input: outputDecodedSingleURLWithoutAngleBracketsWithLFEol,
},
"Unencoded single URL with CRLF EOL": {
input: outputDecodedSingleURLWithCRLFEol,
"Unencoded single URL without angle brackets CRLF EOL": {
input: outputDecodedSingleURLWithoutAngleBracketsWithCRLFEol,
},
"Unencoded email with angle brackets with LF EOL": {
input: outputDecodedEmailWithAngleBracketsWithLFEol,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwilliamlam.com%2F2022%2F12%2Fhigh-end-dell-precision-7770-7670-laptops-with-128gb-memory-for-esxi.html&amp;data=data_placeholder&amp;sdata=sdata_placeholder&amp;reserved=0>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwilliamlam.com%2F2022%2F12%2Fhigh-end-dell-precision-7770-7670-laptops-with-128gb-memory-for-esxi.html&amp;data=data_placeholder&amp;sdata=sdata_placeholder&amp;reserved=0>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://williamlam.com/2022/12/high-end-dell-precision-7770-7670-laptops-with-128gb-memory-for-esxi.html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://williamlam.com/2022/12/high-end-dell-precision-7770-7670-laptops-with-128gb-memory-for-esxi.html>

0 comments on commit 0fdd779

Please sign in to comment.