-
Notifications
You must be signed in to change notification settings - Fork 3
/
timeservice_test.go
72 lines (59 loc) · 1.61 KB
/
timeservice_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"crypto/tls"
"log/slog"
"net"
"os"
"testing"
"github.com/scionproto/scion/pkg/snet"
"example.com/scion-time/core/client"
"example.com/scion-time/core/timebase"
"example.com/scion-time/driver/clocks"
)
func TestTimeserviceNTSChrony(t *testing.T) {
hasChrony := os.Getenv("HAS_CHRONY")
if hasChrony == "" {
t.Skip("set up and start chrony to run this integration test")
}
initLogger(true /* verbose */)
remoteAddr := "0-0,127.0.0.1:4460"
localAddr := "0-0,0.0.0.0:0"
ntskeServer := "127.0.0.1:4460"
remoteAddrSnet := snet.UDPAddr{}
err := remoteAddrSnet.Set(remoteAddr)
if err != nil {
t.Fatalf("failed to parse remote address %v", err)
}
localAddrSnet := snet.UDPAddr{}
err = localAddrSnet.Set(localAddr)
if err != nil {
t.Fatalf("failed to parse local address %v", err)
}
ctx := context.Background()
log := slog.Default()
lclk := clocks.NewSystemClock(log, clocks.UnknownDrift)
timebase.RegisterClock(lclk)
laddr := localAddrSnet.Host
raddr := remoteAddrSnet.Host
c := &client.IPClient{
Log: log,
InterleavedMode: true,
}
ntskeHost, ntskePort, err := net.SplitHostPort(ntskeServer)
if err != nil {
t.Fatalf("failed to split NTS-KE host and port %v", err)
}
c.Auth.Enabled = true
c.Auth.NTSKEFetcher.TLSConfig = tls.Config{
InsecureSkipVerify: true,
ServerName: ntskeHost,
MinVersion: tls.VersionTLS13,
}
c.Auth.NTSKEFetcher.Port = ntskePort
c.Auth.NTSKEFetcher.Log = log
_, _, err = client.MeasureClockOffsetIP(ctx, log, c, laddr, raddr)
if err != nil {
t.Fatalf("failed to measure clock offset %v", err)
}
}