-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for scanning package functions
Signed-off-by: HAHWUL <[email protected]>
- Loading branch information
Showing
3 changed files
with
203 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package scanning | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInterfaceGetGfXSS(t *testing.T) { | ||
list, length := InterfaceGetGfXSS() | ||
assert.NotNil(t, list) | ||
assert.Greater(t, length, 0) | ||
} | ||
|
||
func TestInterfaceGetEventHandlers(t *testing.T) { | ||
list, length := InterfaceGetEventHandlers() | ||
assert.NotNil(t, list) | ||
assert.Greater(t, length, 0) | ||
} | ||
|
||
func TestInterfaceGetTags(t *testing.T) { | ||
list, length := InterfaceGetTags() | ||
assert.NotNil(t, list) | ||
assert.Greater(t, length, 0) | ||
} | ||
|
||
func TestInterfaceGetSpecialChar(t *testing.T) { | ||
list, length := InterfaceGetSpecialChar() | ||
assert.NotNil(t, list) | ||
assert.Greater(t, length, 0) | ||
} | ||
|
||
func TestInterfaceGetUsefulCode(t *testing.T) { | ||
list, length := InterfaceGetUsefulCode() | ||
assert.NotNil(t, list) | ||
assert.Greater(t, length, 0) | ||
} |
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,106 @@ | ||
package scanning | ||
|
||
import "testing" | ||
|
||
func Test_isAllowType(t *testing.T) { | ||
type args struct { | ||
contentType string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "Allowed type - text/html", | ||
args: args{ | ||
contentType: "text/html", | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Not allowed type - application/json", | ||
args: args{ | ||
contentType: "application/json", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Not allowed type - text/javascript", | ||
args: args{ | ||
contentType: "text/javascript", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Allowed type with charset - text/html; charset=UTF-8", | ||
args: args{ | ||
contentType: "text/html; charset=UTF-8", | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Not allowed type with charset - application/json; charset=UTF-8", | ||
args: args{ | ||
contentType: "application/json; charset=UTF-8", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Allowed type - application/xml", | ||
args: args{ | ||
contentType: "application/xml", | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Not allowed type - image/jpeg", | ||
args: args{ | ||
contentType: "image/jpeg", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Not allowed type - image/png", | ||
args: args{ | ||
contentType: "image/png", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Not allowed type - text/plain", | ||
args: args{ | ||
contentType: "text/plain", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Not allowed type - text/css", | ||
args: args{ | ||
contentType: "text/css", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Not allowed type - application/rss+xml", | ||
args: args{ | ||
contentType: "application/rss+xml", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Allowed type - text/xml", | ||
args: args{ | ||
contentType: "text/xml", | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := isAllowType(tt.args.contentType); got != tt.want { | ||
t.Errorf("isAllowType() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,60 @@ | ||
package scanning | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestMakeTargetSlice(t *testing.T) { | ||
type args struct { | ||
targets []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string][]string | ||
}{ | ||
{ | ||
name: "Single target", | ||
args: args{ | ||
targets: []string{"http://example.com"}, | ||
}, | ||
want: map[string][]string{ | ||
"example.com": {"http://example.com"}, | ||
}, | ||
}, | ||
{ | ||
name: "Multiple targets with same hostname", | ||
args: args{ | ||
targets: []string{"http://example.com", "https://example.com/path"}, | ||
}, | ||
want: map[string][]string{ | ||
"example.com": {"http://example.com", "https://example.com/path"}, | ||
}, | ||
}, | ||
{ | ||
name: "Multiple targets with different hostnames", | ||
args: args{ | ||
targets: []string{"http://example.com", "https://another.com"}, | ||
}, | ||
want: map[string][]string{ | ||
"example.com": {"http://example.com"}, | ||
"another.com": {"https://another.com"}, | ||
}, | ||
}, | ||
{ | ||
name: "Empty targets", | ||
args: args{ | ||
targets: []string{}, | ||
}, | ||
want: map[string][]string{}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := MakeTargetSlice(tt.args.targets); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("MakeTargetSlice() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |