MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / TestIpToRange

Function TestIpToRange

pkg/exprhelpers/exprlib_test.go:548–632  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func TestIpToRange(t *testing.T) {
549 err := Init(nil)
550 require.NoError(t, err)
551
552 tests := []struct {
553 name string
554 env map[string]any
555 code string
556 want string
557 wantCompileErr string
558 wantRunErr string
559 wantLog string
560 }{
561 {
562 name: "IpToRange() test: IPv4",
563 env: map[string]any{
564 "ip": "192.168.1.1",
565 "netmask": "16",
566 },
567 code: "IpToRange(ip, netmask)",
568 want: "192.168.0.0/16",
569 },
570 {
571 name: "IpToRange() test: IPv6",
572 env: map[string]any{
573 "ip": "2001:db8::1",
574 "netmask": "/64",
575 },
576 code: "IpToRange(ip, netmask)",
577 want: "2001:db8::/64",
578 },
579 {
580 name: "IpToRange() test: malformed netmask",
581 env: map[string]any{
582 "ip": "192.168.0.1",
583 "netmask": "test",
584 },
585 code: "IpToRange(ip, netmask)",
586 want: "",
587 },
588 {
589 name: "IpToRange() test: malformed IP",
590 env: map[string]any{
591 "ip": "a.b.c.d",
592 "netmask": "24",
593 },
594 code: "IpToRange(ip, netmask)",
595 },
596 {
597 name: "IpToRange() test: too high netmask",
598 env: map[string]any{
599 "ip": "192.168.1.1",
600 "netmask": "35",
601 },
602 code: "IpToRange(ip, netmask)",
603 wantLog: "can't create prefix from IP address '192.168.1.1' and mask '35': prefix length 35 too large for IPv4",
604 },
605 }

Callers

nothing calls this directly

Calls 5

InitFunction · 0.85
GetExprOptionsFunction · 0.85
RunMethod · 0.65
CompileMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…