diff --git a/pkg/scanning/entity_test.go b/pkg/scanning/entity_test.go new file mode 100644 index 00000000..731c59a4 --- /dev/null +++ b/pkg/scanning/entity_test.go @@ -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) +} diff --git a/pkg/scanning/ignore_test.go b/pkg/scanning/ignore_test.go new file mode 100644 index 00000000..f6addde7 --- /dev/null +++ b/pkg/scanning/ignore_test.go @@ -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) + } + }) + } +} diff --git a/pkg/scanning/multicast_test.go b/pkg/scanning/multicast_test.go new file mode 100644 index 00000000..b709c61f --- /dev/null +++ b/pkg/scanning/multicast_test.go @@ -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) + } + }) + } +}