Improve profile tests

This commit is contained in:
Daniel 2019-10-25 13:34:25 +02:00
parent fdb5f6fcf7
commit eeef53e01e
3 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package profile
import (
"context"
"fmt"
"net"
"strconv"
@ -91,7 +92,7 @@ func (e Endpoints) CheckIP(domain string, ip net.IP, protocol uint8, port uint16
// setup caching wrapper
cachedGetDomainOfIP = func() string {
if !ipResolved {
result, err := intel.ResolveIPAndValidate(ip.String(), securityLevel)
result, err := intel.ResolveIPAndValidate(context.TODO(), ip.String(), securityLevel)
if err != nil {
// log.Debug()
ipName = result

View file

@ -3,8 +3,6 @@ package profile
import (
"net"
"testing"
"github.com/safing/portbase/utils/testutils"
)
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 {
t.Errorf(
"line %d: unexpected result for endpoint domain match %s: result=%s, expected=%s",
testutils.GetLineNumberOfCaller(1),
getLineNumberOfCaller(1),
domain,
result,
expectedResult,
@ -27,7 +25,7 @@ func testEndpointIPMatch(t *testing.T, ep *EndpointPermission, domain string, ip
if result != expectedResult {
t.Errorf(
"line %d: unexpected result for endpoint %s/%s/%d/%d: result=%s, expected=%s",
testutils.GetLineNumberOfCaller(1),
getLineNumberOfCaller(1),
domain,
ip,
protocol,

View file

@ -3,10 +3,10 @@ package profile
import (
"context"
"net"
"runtime"
"testing"
"time"
"github.com/safing/portbase/utils/testutils"
"github.com/safing/portmaster/status"
)
@ -113,7 +113,7 @@ func testEndpointDomain(t *testing.T, set *Set, domain string, expectedResult EP
if result != expectedResult {
t.Errorf(
"line %d: unexpected result for endpoint domain %s: result=%s, expected=%s",
testutils.GetLineNumberOfCaller(1),
getLineNumberOfCaller(1),
domain,
result,
expectedResult,
@ -127,7 +127,7 @@ func testEndpointIP(t *testing.T, set *Set, domain string, ip net.IP, protocol u
if result != expectedResult {
t.Errorf(
"line %d: unexpected result for endpoint %s/%s/%d/%d/%v: result=%s, expected=%s",
testutils.GetLineNumberOfCaller(1),
getLineNumberOfCaller(1),
domain,
ip,
protocol,
@ -171,3 +171,8 @@ func TestProfileSet(t *testing.T) {
testEndpointIP(t, set, "", net.ParseIP("10.2.3.4"), 6, 80, false, NoMatch)
testEndpointDomain(t, set, "bad2.example.com.", Undeterminable)
}
func getLineNumberOfCaller(levels int) int {
_, _, line, _ := runtime.Caller(levels + 1)
return line
}