summaryrefslogtreecommitdiff
path: root/internal/platforms
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-23 11:05:49 +0300
committerPaul Buetow <paul@buetow.org>2024-10-23 11:05:49 +0300
commitfcd9fe70899c2e30ea467d80c576b950f5f62be6 (patch)
tree8f1df76aebaff67b9e368fa1cd1d9d04cf9eec10 /internal/platforms
parent772cf965f15bf06c7cf91095629f6b7f26848f83 (diff)
initial fuzztesting
Diffstat (limited to 'internal/platforms')
-rw-r--r--internal/platforms/linkedin/escapes.go2
-rw-r--r--internal/platforms/linkedin/escapes_test.go34
2 files changed, 34 insertions, 2 deletions
diff --git a/internal/platforms/linkedin/escapes.go b/internal/platforms/linkedin/escapes.go
index 21b4c56..31110a0 100644
--- a/internal/platforms/linkedin/escapes.go
+++ b/internal/platforms/linkedin/escapes.go
@@ -42,7 +42,7 @@ func escapeLinkedInText(input string) string {
// extractURLs finds all occurrences of URLs starting with "http://" or "https://" in a given string.
func extractURLs(input string) []string {
// Regular expression pattern to match URLs starting with http:// or https://
- urlPattern := `(http://|https://)[^\s]+`
+ urlPattern := `(http://|https://|ftp://)[^\s]+`
// Compile the regular expression
re := regexp.MustCompile(urlPattern)
diff --git a/internal/platforms/linkedin/escapes_test.go b/internal/platforms/linkedin/escapes_test.go
index 2074312..c95ddc9 100644
--- a/internal/platforms/linkedin/escapes_test.go
+++ b/internal/platforms/linkedin/escapes_test.go
@@ -3,6 +3,7 @@ package linkedin
import (
"fmt"
"slices"
+ "strings"
"testing"
)
@@ -33,7 +34,6 @@ func TestLinkedInTwoURLsExtract(t *testing.T) {
}
}
-// TODO: Use Fuzzing here!
func TestLinkedInURLExtract(t *testing.T) {
urls := []string{
"http://foo.zone",
@@ -56,3 +56,35 @@ func TestLinkedInURLExtract(t *testing.T) {
}
}
}
+
+func FuzzLinkedInURLExtract(f *testing.F) {
+ f.Add("/path?myjfa=lwsr4imj&dgqeg=m3uwwsak")
+ f.Add("/?amfbm=bwzqu46m&xheuh=nv588d98")
+ f.Add("?tuupm=reng2p1y&cbjot=0g5qvpty")
+ f.Add("/path?qmcok=f%20w4tfp7g&awsnq=sjizuore&owdix=8s2dmqsv")
+ f.Add("?zwilf=868o24x1&fiwmp=1d5aqbvo&irhhr=xar7qbq7&eetpy=scmi9s8i")
+ f.Add("/path?mwhbm=psinstn6&nsjic=pfu0wnk9&lbmrz=5bixkhdt")
+ f.Add("/path?owbwo=67mkjiz2")
+ f.Add("/path?ohvxi=esy5qvml&zlvzt=2yi4q4ef&cnich=sgc8sahs")
+ f.Add("/path?codsl=fpwfto6j")
+ f.Add("tvdus=fhlhlh1y")
+ f.Add("/foo.txt")
+
+ f.Fuzz(func(t *testing.T, urlPath string) {
+ urlPath = strings.TrimSpace(urlPath)
+ baseURLs := []string{"https://foo.zone", "http://foo.zone", "ftp://foo.zone"}
+ for _, baseURL := range baseURLs {
+ fullURL := fmt.Sprintf("%s%s", baseURL, urlPath)
+ text := fmt.Sprintf("Hello world %s Hello World", fullURL)
+ found := extractURLs(text)
+ if len(found) != 1 {
+ t.Errorf("expected 1 URL '%s', but got %d for text '%s'",
+ fullURL, len(found), text)
+ }
+ if found[0] != fullURL {
+ t.Errorf("expected URL '%s', but got '%s' for text '%s'",
+ fullURL, found[0], text)
+ }
+ }
+ })
+}