This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
input_test.go
66 lines (59 loc) · 2.14 KB
/
input_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"testing"
)
func TestSanitizeInput(t *testing.T) {
// Remove proto
r := sanitizeInput("https://www.google.com:443")
if r != "www.google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("http://google.com:443")
if r != "google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("smtp://mail.google.com:25")
if r != "mail.google.com:25" {
t.Errorf("Input sanitization tests failed")
}
// Do nothing
r = sanitizeInput("www.google.com:443")
if r != "www.google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("mail.google.com:25")
if r != "mail.google.com:25" {
t.Errorf("Input sanitization tests failed")
}
// Remove path
r = sanitizeInput("google.com:443/frontpage/index.html")
if r != "google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("mail.google.com:25/")
if r != "mail.google.com:25" {
t.Errorf("Input sanitization tests failed")
}
// Append default port
r = sanitizeInput("https://google.com")
if r != "google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("mail.google.com")
if r != "mail.google.com:443" {
t.Errorf("Input sanitization tests failed")
}
// All together
r = sanitizeInput("https://stackoverflow.com/questions/12968093/regex-to-validate-port-number")
if r != "stackoverflow.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("https://www.google.com/search?sxsrf=ALeKk02rpH0l0fpZEl1FWQ3KrqZw2jCWyA%3A1590595850808&source=hp&ei=CpHOXtmSL4GWaq36gfgL&q=trololol&oq=trololol&gs_lcp=CgZwc3ktYWIQAzIECCMQJzICCAAyAggAMgQIABAKMgIIADIECAAQCjIECAAQCjIECAAQCjIECAAQCjIECAAQCjoHCCMQ6gIQJzoGCCMQJxATOgUIABCDAVCbQ1iYTGCXTWgCcAB4AIABZogB7wWSAQM3LjGYAQCgAQGqAQdnd3Mtd2l6sAEK&sclient=psy-ab&ved=0ahUKEwjZv6qlt9TpAhUBixoKHS19AL8Q4dUDCAk&uact=5%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B")
if r != "www.google.com:443" {
t.Errorf("Input sanitization tests failed")
}
r = sanitizeInput("https://en.wikipedia.org:8080/wiki/SQL_injection")
if r != "en.wikipedia.org:8080" {
t.Errorf("Input sanitization tests failed")
}
}