mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Improve profile tests
This commit is contained in:
parent
fdb5f6fcf7
commit
eeef53e01e
3 changed files with 12 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
package profile
|
package profile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -91,7 +92,7 @@ func (e Endpoints) CheckIP(domain string, ip net.IP, protocol uint8, port uint16
|
||||||
// setup caching wrapper
|
// setup caching wrapper
|
||||||
cachedGetDomainOfIP = func() string {
|
cachedGetDomainOfIP = func() string {
|
||||||
if !ipResolved {
|
if !ipResolved {
|
||||||
result, err := intel.ResolveIPAndValidate(ip.String(), securityLevel)
|
result, err := intel.ResolveIPAndValidate(context.TODO(), ip.String(), securityLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.Debug()
|
// log.Debug()
|
||||||
ipName = result
|
ipName = result
|
||||||
|
|
|
@ -3,8 +3,6 @@ package profile
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/safing/portbase/utils/testutils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func testEndpointDomainMatch(t *testing.T, ep *EndpointPermission, domain string, expectedResult EPResult) {
|
func testEndpointDomainMatch(t *testing.T, ep *EndpointPermission, domain string, expectedResult EPResult) {
|
||||||
|
@ -13,7 +11,7 @@ func testEndpointDomainMatch(t *testing.T, ep *EndpointPermission, domain string
|
||||||
if result != expectedResult {
|
if result != expectedResult {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"line %d: unexpected result for endpoint domain match %s: result=%s, expected=%s",
|
"line %d: unexpected result for endpoint domain match %s: result=%s, expected=%s",
|
||||||
testutils.GetLineNumberOfCaller(1),
|
getLineNumberOfCaller(1),
|
||||||
domain,
|
domain,
|
||||||
result,
|
result,
|
||||||
expectedResult,
|
expectedResult,
|
||||||
|
@ -27,7 +25,7 @@ func testEndpointIPMatch(t *testing.T, ep *EndpointPermission, domain string, ip
|
||||||
if result != expectedResult {
|
if result != expectedResult {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"line %d: unexpected result for endpoint %s/%s/%d/%d: result=%s, expected=%s",
|
"line %d: unexpected result for endpoint %s/%s/%d/%d: result=%s, expected=%s",
|
||||||
testutils.GetLineNumberOfCaller(1),
|
getLineNumberOfCaller(1),
|
||||||
domain,
|
domain,
|
||||||
ip,
|
ip,
|
||||||
protocol,
|
protocol,
|
||||||
|
|
|
@ -3,10 +3,10 @@ package profile
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/safing/portbase/utils/testutils"
|
|
||||||
"github.com/safing/portmaster/status"
|
"github.com/safing/portmaster/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ func testEndpointDomain(t *testing.T, set *Set, domain string, expectedResult EP
|
||||||
if result != expectedResult {
|
if result != expectedResult {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"line %d: unexpected result for endpoint domain %s: result=%s, expected=%s",
|
"line %d: unexpected result for endpoint domain %s: result=%s, expected=%s",
|
||||||
testutils.GetLineNumberOfCaller(1),
|
getLineNumberOfCaller(1),
|
||||||
domain,
|
domain,
|
||||||
result,
|
result,
|
||||||
expectedResult,
|
expectedResult,
|
||||||
|
@ -127,7 +127,7 @@ func testEndpointIP(t *testing.T, set *Set, domain string, ip net.IP, protocol u
|
||||||
if result != expectedResult {
|
if result != expectedResult {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"line %d: unexpected result for endpoint %s/%s/%d/%d/%v: result=%s, expected=%s",
|
"line %d: unexpected result for endpoint %s/%s/%d/%d/%v: result=%s, expected=%s",
|
||||||
testutils.GetLineNumberOfCaller(1),
|
getLineNumberOfCaller(1),
|
||||||
domain,
|
domain,
|
||||||
ip,
|
ip,
|
||||||
protocol,
|
protocol,
|
||||||
|
@ -171,3 +171,8 @@ func TestProfileSet(t *testing.T) {
|
||||||
testEndpointIP(t, set, "", net.ParseIP("10.2.3.4"), 6, 80, false, NoMatch)
|
testEndpointIP(t, set, "", net.ParseIP("10.2.3.4"), 6, 80, false, NoMatch)
|
||||||
testEndpointDomain(t, set, "bad2.example.com.", Undeterminable)
|
testEndpointDomain(t, set, "bad2.example.com.", Undeterminable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLineNumberOfCaller(levels int) int {
|
||||||
|
_, _, line, _ := runtime.Caller(levels + 1)
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue