@@ -20,7 +20,109 @@ const layerUnusedTailscaleExternalServices = Layer.mergeAll(
2020 ) ,
2121) ;
2222
23+ const protonAndTailscaleInterfaces = {
24+ pvpnksintrf1 : [ { address : "100.85.0.1" , family : "IPv4" , internal : false } ] ,
25+ tailscale0 : [ { address : "100.74.126.34" , family : "IPv4" , internal : false } ] ,
26+ } ;
27+
2328describe ( "tailscale endpoint provider" , ( ) => {
29+ it . effect ( "does not advertise Proton's CGNAT address as a Tailscale pairing endpoint" , ( ) =>
30+ Effect . gen ( function * ( ) {
31+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
32+ port : 3773 ,
33+ networkInterfaces : protonAndTailscaleInterfaces ,
34+ statusJson : `{"Self":{"TailscaleIPs":["100.74.126.34"]}}` ,
35+ } ) ;
36+ assert . deepEqual (
37+ endpoints . map ( ( endpoint ) => endpoint . httpBaseUrl ) ,
38+ [ "http://100.74.126.34:3773/" ] ,
39+ ) ;
40+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
41+ ) ;
42+
43+ it . effect (
44+ "does not advertise CGNAT interfaces when Tailscale reports no assigned addresses" ,
45+ ( ) =>
46+ Effect . gen ( function * ( ) {
47+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
48+ port : 3773 ,
49+ networkInterfaces : { pvpnksintrf1 : protonAndTailscaleInterfaces . pvpnksintrf1 } ,
50+ statusJson : `{"BackendState":"NoState","Self":{"TailscaleIPs":null}}` ,
51+ } ) ;
52+ assert . deepEqual ( endpoints , [ ] ) ;
53+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
54+ ) ;
55+
56+ it . effect ( "keeps native Tailscale interfaces with missing, malformed, or stale status" , ( ) =>
57+ Effect . gen ( function * ( ) {
58+ for ( const interfaceName of [ "tailscale0" , "Tailscale" ] ) {
59+ for ( const statusJson of [ null , "not-json" , `{"Self":{"TailscaleIPs":[]}}` ] ) {
60+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
61+ port : 3773 ,
62+ networkInterfaces : {
63+ pvpnksintrf1 : protonAndTailscaleInterfaces . pvpnksintrf1 ,
64+ [ interfaceName ] : protonAndTailscaleInterfaces . tailscale0 ,
65+ } ,
66+ statusJson,
67+ } ) ;
68+ assert . deepEqual (
69+ endpoints . map ( ( endpoint ) => endpoint . httpBaseUrl ) ,
70+ [ "http://100.74.126.34:3773/" ] ,
71+ ) ;
72+ }
73+ }
74+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
75+ ) ;
76+
77+ it . effect (
78+ "recognizes a macOS Tailscale tunnel by its IPv6 address when status is unavailable" ,
79+ ( ) =>
80+ Effect . gen ( function * ( ) {
81+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
82+ port : 3773 ,
83+ networkInterfaces : {
84+ utun3 : [ { address : "100.85.0.1" , family : "IPv4" , internal : false } ] ,
85+ utun4 : [
86+ { address : "100.74.126.34" , family : "IPv4" , internal : false } ,
87+ { address : "fd7a:115c:a1e0::1234" , family : "IPv6" , internal : false } ,
88+ ] ,
89+ } ,
90+ statusJson : null ,
91+ } ) ;
92+ assert . deepEqual (
93+ endpoints . map ( ( endpoint ) => endpoint . httpBaseUrl ) ,
94+ [ "http://100.74.126.34:3773/" ] ,
95+ ) ;
96+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
97+ ) ;
98+
99+ it . effect ( "uses assigned addresses for renamed adapters without IPv6" , ( ) =>
100+ Effect . gen ( function * ( ) {
101+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
102+ port : 3773 ,
103+ networkInterfaces : {
104+ vpn0 : [ { address : "100.74.126.34" , family : "IPv4" , internal : false } ] ,
105+ } ,
106+ statusJson : `{"Self":{"TailscaleIPs":["100.74.126.34"]}}` ,
107+ } ) ;
108+ assert . deepEqual (
109+ endpoints . map ( ( endpoint ) => endpoint . httpBaseUrl ) ,
110+ [ "http://100.74.126.34:3773/" ] ,
111+ ) ;
112+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
113+ ) ;
114+
115+ it . effect ( "does not advertise cached Tailscale addresses absent from local interfaces" , ( ) =>
116+ Effect . gen ( function * ( ) {
117+ const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
118+ port : 3773 ,
119+ networkInterfaces : { pvpnksintrf1 : protonAndTailscaleInterfaces . pvpnksintrf1 } ,
120+ statusJson : `{"Self":{"TailscaleIPs":["100.74.126.35"]}}` ,
121+ } ) ;
122+ assert . deepEqual ( endpoints , [ ] ) ;
123+ } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
124+ ) ;
125+
24126 it . effect ( "parses MagicDNS names from tailscale status" , ( ) =>
25127 Effect . gen ( function * ( ) {
26128 const dnsName = yield * parseTailscaleMagicDnsName (
@@ -49,7 +151,7 @@ describe("tailscale endpoint provider", () => {
49151 } ,
50152 ] ,
51153 } ,
52- statusJson : `{"Self":{"DNSName":"desktop.tail.ts.net."}}` ,
154+ statusJson : `{"Self":{"DNSName":"desktop.tail.ts.net.","TailscaleIPs":["100.100.100.100"] }}` ,
53155 } ) ;
54156 assert . deepEqual ( endpoints , [
55157 {
@@ -96,21 +198,24 @@ describe("tailscale endpoint provider", () => {
96198 } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
97199 ) ;
98200
99- it . effect ( "uses an injected magic DNS name reader instead of spawning tailscale " , ( ) =>
201+ it . effect ( "uses one injected status reader for both IP and MagicDNS endpoints " , ( ) =>
100202 Effect . gen ( function * ( ) {
101203 let readerCalls = 0 ;
102204 const endpoints = yield * resolveTailscaleAdvertisedEndpoints ( {
103205 port : 3773 ,
104- networkInterfaces : { } ,
105- readMagicDnsName : Effect . sync ( ( ) => {
206+ networkInterfaces : protonAndTailscaleInterfaces ,
207+ readStatus : Effect . sync ( ( ) => {
106208 readerCalls += 1 ;
107- return "desktop.tail.ts.net" ;
209+ return {
210+ magicDnsName : "desktop.tail.ts.net" ,
211+ tailnetIpv4Addresses : [ "100.74.126.34" ] ,
212+ } ;
108213 } ) ,
109214 } ) ;
110215 assert . equal ( readerCalls , 1 ) ;
111216 assert . deepEqual (
112217 endpoints . map ( ( endpoint ) => endpoint . httpBaseUrl ) ,
113- [ "https://desktop.tail.ts.net/" ] ,
218+ [ "http://100.74.126.34:3773/" , " https://desktop.tail.ts.net/"] ,
114219 ) ;
115220 } ) . pipe ( Effect . provide ( layerUnusedTailscaleExternalServices ) ) ,
116221 ) ;
0 commit comments