@@ -41,97 +41,6 @@ import (
41
41
"tailscale.com/types/ptr"
42
42
)
43
43
44
- // testEnv represents the environment needed for a single sub-test so that tests
45
- // can run in parallel.
46
- type testEnv struct {
47
- kube * kubeServer // Fake kube server.
48
- lapi * localAPI // Local TS API server.
49
- d string // Temp dir for the specific test.
50
- argFile string // File with commands test_tailscale{,d}.sh were invoked with.
51
- runningSockPath string // Path to the running tailscaled socket.
52
- localAddrPort int // Port for the containerboot HTTP server.
53
- healthAddrPort int // Port for the (deprecated) containerboot health server.
54
- }
55
-
56
- func newTestEnv (t * testing.T ) testEnv {
57
- d := t .TempDir ()
58
-
59
- lapi := localAPI {FSRoot : d }
60
- if err := lapi .Start (); err != nil {
61
- t .Fatal (err )
62
- }
63
- t .Cleanup (lapi .Close )
64
-
65
- kube := kubeServer {FSRoot : d }
66
- kube .Start (t )
67
- t .Cleanup (kube .Close )
68
-
69
- tailscaledConf := & ipn.ConfigVAlpha {AuthKey : ptr .To ("foo" ), Version : "alpha0" }
70
- serveConf := ipn.ServeConfig {TCP : map [uint16 ]* ipn.TCPPortHandler {80 : {HTTP : true }}}
71
- egressCfg := egressSvcConfig ("foo" , "foo.tailnetxyz.ts.net" )
72
-
73
- dirs := []string {
74
- "var/lib" ,
75
- "usr/bin" ,
76
- "tmp" ,
77
- "dev/net" ,
78
- "proc/sys/net/ipv4" ,
79
- "proc/sys/net/ipv6/conf/all" ,
80
- "etc/tailscaled" ,
81
- }
82
- for _ , path := range dirs {
83
- if err := os .MkdirAll (filepath .Join (d , path ), 0700 ); err != nil {
84
- t .Fatal (err )
85
- }
86
- }
87
- files := map [string ][]byte {
88
- "usr/bin/tailscaled" : fakeTailscaled ,
89
- "usr/bin/tailscale" : fakeTailscale ,
90
- "usr/bin/iptables" : fakeTailscale ,
91
- "usr/bin/ip6tables" : fakeTailscale ,
92
- "dev/net/tun" : []byte ("" ),
93
- "proc/sys/net/ipv4/ip_forward" : []byte ("0" ),
94
- "proc/sys/net/ipv6/conf/all/forwarding" : []byte ("0" ),
95
- "etc/tailscaled/cap-95.hujson" : mustJSON (t , tailscaledConf ),
96
- "etc/tailscaled/serve-config.json" : mustJSON (t , serveConf ),
97
- filepath .Join ("etc/tailscaled/" , egressservices .KeyEgressServices ): mustJSON (t , egressCfg ),
98
- filepath .Join ("etc/tailscaled/" , egressservices .KeyHEPPings ): []byte ("4" ),
99
- }
100
- for path , content := range files {
101
- // Making everything executable is a little weird, but the
102
- // stuff that doesn't need to be executable doesn't care if we
103
- // do make it executable.
104
- if err := os .WriteFile (filepath .Join (d , path ), content , 0700 ); err != nil {
105
- t .Fatal (err )
106
- }
107
- }
108
-
109
- argFile := filepath .Join (d , "args" )
110
- runningSockPath := filepath .Join (d , "tmp/tailscaled.sock" )
111
- var localAddrPort , healthAddrPort int
112
- for _ , p := range []* int {& localAddrPort , & healthAddrPort } {
113
- ln , err := net .Listen ("tcp" , ":0" )
114
- if err != nil {
115
- t .Fatalf ("Failed to open listener: %v" , err )
116
- }
117
- if err := ln .Close (); err != nil {
118
- t .Fatalf ("Failed to close listener: %v" , err )
119
- }
120
- port := ln .Addr ().(* net.TCPAddr ).Port
121
- * p = port
122
- }
123
-
124
- return testEnv {
125
- kube : & kube ,
126
- lapi : & lapi ,
127
- d : d ,
128
- argFile : argFile ,
129
- runningSockPath : runningSockPath ,
130
- localAddrPort : localAddrPort ,
131
- healthAddrPort : healthAddrPort ,
132
- }
133
- }
134
-
135
44
func TestContainerBoot (t * testing.T ) {
136
45
boot := filepath .Join (t .TempDir (), "containerboot" )
137
46
if err := exec .Command ("go" , "build" , "-ldflags" , "-X main.testSleepDuration=1ms" , "-o" , boot , "tailscale.com/cmd/containerboot" ).Run (); err != nil {
@@ -515,6 +424,37 @@ func TestContainerBoot(t *testing.T) {
515
424
},
516
425
}
517
426
},
427
+ "auth_key_once_extra_args_override_dns" : func (env * testEnv ) testCase {
428
+ return testCase {
429
+ Env : map [string ]string {
430
+ "TS_AUTHKEY" : "tskey-key" ,
431
+ "TS_AUTH_ONCE" : "true" ,
432
+ "TS_ACCEPT_DNS" : "false" ,
433
+ "TS_EXTRA_ARGS" : "--accept-dns" ,
434
+ },
435
+ Phases : []phase {
436
+ {
437
+ WantCmds : []string {
438
+ "/usr/bin/tailscaled --socket=/tmp/tailscaled.sock --state=mem: --statedir=/tmp --tun=userspace-networking" ,
439
+ },
440
+ },
441
+ {
442
+ Notify : & ipn.Notify {
443
+ State : ptr .To (ipn .NeedsLogin ),
444
+ },
445
+ WantCmds : []string {
446
+ "/usr/bin/tailscale --socket=/tmp/tailscaled.sock up --accept-dns=true --authkey=tskey-key" ,
447
+ },
448
+ },
449
+ {
450
+ Notify : runningNotify ,
451
+ WantCmds : []string {
452
+ "/usr/bin/tailscale --socket=/tmp/tailscaled.sock set --accept-dns=true" ,
453
+ },
454
+ },
455
+ },
456
+ }
457
+ },
518
458
"kube_storage" : func (env * testEnv ) testCase {
519
459
return testCase {
520
460
Env : map [string ]string {
@@ -766,6 +706,41 @@ func TestContainerBoot(t *testing.T) {
766
706
},
767
707
}
768
708
},
709
+ "extra_args_accept_dns" : func (env * testEnv ) testCase {
710
+ return testCase {
711
+ Env : map [string ]string {
712
+ "TS_EXTRA_ARGS" : "--accept-dns" ,
713
+ },
714
+ Phases : []phase {
715
+ {
716
+ WantCmds : []string {
717
+ "/usr/bin/tailscaled --socket=/tmp/tailscaled.sock --state=mem: --statedir=/tmp --tun=userspace-networking" ,
718
+ "/usr/bin/tailscale --socket=/tmp/tailscaled.sock up --accept-dns=true" ,
719
+ },
720
+ }, {
721
+ Notify : runningNotify ,
722
+ },
723
+ },
724
+ }
725
+ },
726
+ "extra_args_accept_dns_overrides_env_var" : func (env * testEnv ) testCase {
727
+ return testCase {
728
+ Env : map [string ]string {
729
+ "TS_ACCEPT_DNS" : "true" , // Overridden by TS_EXTRA_ARGS.
730
+ "TS_EXTRA_ARGS" : "--accept-dns=false" ,
731
+ },
732
+ Phases : []phase {
733
+ {
734
+ WantCmds : []string {
735
+ "/usr/bin/tailscaled --socket=/tmp/tailscaled.sock --state=mem: --statedir=/tmp --tun=userspace-networking" ,
736
+ "/usr/bin/tailscale --socket=/tmp/tailscaled.sock up --accept-dns=false" ,
737
+ },
738
+ }, {
739
+ Notify : runningNotify ,
740
+ },
741
+ },
742
+ }
743
+ },
769
744
"hostname" : func (env * testEnv ) testCase {
770
745
return testCase {
771
746
Env : map [string ]string {
@@ -1604,3 +1579,94 @@ func egressSvcConfig(name, fqdn string) egressservices.Configs {
1604
1579
},
1605
1580
}
1606
1581
}
1582
+
1583
+ // testEnv represents the environment needed for a single sub-test so that tests
1584
+ // can run in parallel.
1585
+ type testEnv struct {
1586
+ kube * kubeServer // Fake kube server.
1587
+ lapi * localAPI // Local TS API server.
1588
+ d string // Temp dir for the specific test.
1589
+ argFile string // File with commands test_tailscale{,d}.sh were invoked with.
1590
+ runningSockPath string // Path to the running tailscaled socket.
1591
+ localAddrPort int // Port for the containerboot HTTP server.
1592
+ healthAddrPort int // Port for the (deprecated) containerboot health server.
1593
+ }
1594
+
1595
+ func newTestEnv (t * testing.T ) testEnv {
1596
+ d := t .TempDir ()
1597
+
1598
+ lapi := localAPI {FSRoot : d }
1599
+ if err := lapi .Start (); err != nil {
1600
+ t .Fatal (err )
1601
+ }
1602
+ t .Cleanup (lapi .Close )
1603
+
1604
+ kube := kubeServer {FSRoot : d }
1605
+ kube .Start (t )
1606
+ t .Cleanup (kube .Close )
1607
+
1608
+ tailscaledConf := & ipn.ConfigVAlpha {AuthKey : ptr .To ("foo" ), Version : "alpha0" }
1609
+ serveConf := ipn.ServeConfig {TCP : map [uint16 ]* ipn.TCPPortHandler {80 : {HTTP : true }}}
1610
+ egressCfg := egressSvcConfig ("foo" , "foo.tailnetxyz.ts.net" )
1611
+
1612
+ dirs := []string {
1613
+ "var/lib" ,
1614
+ "usr/bin" ,
1615
+ "tmp" ,
1616
+ "dev/net" ,
1617
+ "proc/sys/net/ipv4" ,
1618
+ "proc/sys/net/ipv6/conf/all" ,
1619
+ "etc/tailscaled" ,
1620
+ }
1621
+ for _ , path := range dirs {
1622
+ if err := os .MkdirAll (filepath .Join (d , path ), 0700 ); err != nil {
1623
+ t .Fatal (err )
1624
+ }
1625
+ }
1626
+ files := map [string ][]byte {
1627
+ "usr/bin/tailscaled" : fakeTailscaled ,
1628
+ "usr/bin/tailscale" : fakeTailscale ,
1629
+ "usr/bin/iptables" : fakeTailscale ,
1630
+ "usr/bin/ip6tables" : fakeTailscale ,
1631
+ "dev/net/tun" : []byte ("" ),
1632
+ "proc/sys/net/ipv4/ip_forward" : []byte ("0" ),
1633
+ "proc/sys/net/ipv6/conf/all/forwarding" : []byte ("0" ),
1634
+ "etc/tailscaled/cap-95.hujson" : mustJSON (t , tailscaledConf ),
1635
+ "etc/tailscaled/serve-config.json" : mustJSON (t , serveConf ),
1636
+ filepath .Join ("etc/tailscaled/" , egressservices .KeyEgressServices ): mustJSON (t , egressCfg ),
1637
+ filepath .Join ("etc/tailscaled/" , egressservices .KeyHEPPings ): []byte ("4" ),
1638
+ }
1639
+ for path , content := range files {
1640
+ // Making everything executable is a little weird, but the
1641
+ // stuff that doesn't need to be executable doesn't care if we
1642
+ // do make it executable.
1643
+ if err := os .WriteFile (filepath .Join (d , path ), content , 0700 ); err != nil {
1644
+ t .Fatal (err )
1645
+ }
1646
+ }
1647
+
1648
+ argFile := filepath .Join (d , "args" )
1649
+ runningSockPath := filepath .Join (d , "tmp/tailscaled.sock" )
1650
+ var localAddrPort , healthAddrPort int
1651
+ for _ , p := range []* int {& localAddrPort , & healthAddrPort } {
1652
+ ln , err := net .Listen ("tcp" , ":0" )
1653
+ if err != nil {
1654
+ t .Fatalf ("Failed to open listener: %v" , err )
1655
+ }
1656
+ if err := ln .Close (); err != nil {
1657
+ t .Fatalf ("Failed to close listener: %v" , err )
1658
+ }
1659
+ port := ln .Addr ().(* net.TCPAddr ).Port
1660
+ * p = port
1661
+ }
1662
+
1663
+ return testEnv {
1664
+ kube : & kube ,
1665
+ lapi : & lapi ,
1666
+ d : d ,
1667
+ argFile : argFile ,
1668
+ runningSockPath : runningSockPath ,
1669
+ localAddrPort : localAddrPort ,
1670
+ healthAddrPort : healthAddrPort ,
1671
+ }
1672
+ }
0 commit comments