@@ -34,6 +34,8 @@ import {
3434 RelayConnectionRegistration ,
3535 SshConnectionProfile ,
3636 SshConnectionRegistration ,
37+ TailnetConnectionCredential ,
38+ TailnetConnectionRegistration ,
3739 type ConnectionCredential ,
3840 type ConnectionProfile ,
3941} from "./catalog.ts" ;
@@ -1965,6 +1967,86 @@ describe("EnvironmentRegistry routes", () => {
19651967 } ) ,
19661968 ) ;
19671969
1970+ it . effect (
1971+ "registering a route again with the same kind of credential keeps its learned routes" ,
1972+ ( ) =>
1973+ Effect . gen ( function * ( ) {
1974+ const learnedId = `learned:${ LAN_TARGET . environmentId } :http://100.88.1.2:3773@${ LAN_TARGET . connectionId } ` ;
1975+ const learned = new BearerConnectionTarget ( { ...LAN_TARGET , connectionId : learnedId } ) ;
1976+ const harness = yield * makeHarness (
1977+ [ LAN_TARGET , learned , RELAY_TARGET ] ,
1978+ [
1979+ LAN_PROFILE ,
1980+ new BearerConnectionProfile ( {
1981+ connectionId : learnedId ,
1982+ environmentId : LAN_TARGET . environmentId ,
1983+ label : LAN_TARGET . label ,
1984+ httpBaseUrl : "http://100.88.1.2:3773/" ,
1985+ wsBaseUrl : "ws://100.88.1.2:3773/" ,
1986+ learned : true ,
1987+ network : "tailscale" ,
1988+ } ) ,
1989+ ] ,
1990+ [ [ LAN_TARGET . connectionId , BEARER_CREDENTIAL ] ] ,
1991+ ) ;
1992+ yield * Effect . gen ( function * ( ) {
1993+ const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
1994+ yield * registry . register ( lanRegistration ( ) ) ;
1995+
1996+ expect ( routesOf ( yield * Ref . get ( harness . storedTargets ) , LAN_TARGET . environmentId ) ) . toEqual (
1997+ [ LAN_TARGET , learned , RELAY_TARGET ] ,
1998+ ) ;
1999+ } ) . pipe ( Effect . provide ( harness . layer ) , Effect . scoped ) ;
2000+ } ) ,
2001+ ) ;
2002+
2003+ it . effect (
2004+ "renaming a route upgraded to Tailscale sign-in keeps its learned Tailscale route" ,
2005+ ( ) =>
2006+ Effect . gen ( function * ( ) {
2007+ const learnedId = `learned:${ LAN_TARGET . environmentId } :http://100.88.1.2:3773@${ LAN_TARGET . connectionId } ` ;
2008+ const learned = new BearerConnectionTarget ( { ...LAN_TARGET , connectionId : learnedId } ) ;
2009+ const session = new TailnetConnectionCredential ( {
2010+ signInBaseUrl : "http://100.88.1.2:3773/" ,
2011+ accessToken : "tailnet-token" ,
2012+ expiresAtEpochMs : 4_102_444_800_000 ,
2013+ dpopThumbprint : "thumbprint" ,
2014+ } ) ;
2015+ const harness = yield * makeHarness (
2016+ [ LAN_TARGET , learned , RELAY_TARGET ] ,
2017+ [
2018+ LAN_PROFILE ,
2019+ new BearerConnectionProfile ( {
2020+ connectionId : learnedId ,
2021+ environmentId : LAN_TARGET . environmentId ,
2022+ label : LAN_TARGET . label ,
2023+ httpBaseUrl : "http://100.88.1.2:3773/" ,
2024+ wsBaseUrl : "ws://100.88.1.2:3773/" ,
2025+ learned : true ,
2026+ authorization : "tailnet" ,
2027+ network : "tailscale" ,
2028+ } ) ,
2029+ ] ,
2030+ [ [ LAN_TARGET . connectionId , session ] ] ,
2031+ ) ;
2032+ const renamed = new BearerConnectionTarget ( { ...LAN_TARGET , label : "Renamed" } ) ;
2033+ yield * Effect . gen ( function * ( ) {
2034+ const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
2035+ yield * registry . register (
2036+ new TailnetConnectionRegistration ( {
2037+ target : renamed ,
2038+ profile : new BearerConnectionProfile ( { ...LAN_PROFILE , label : "Renamed" } ) ,
2039+ credential : session ,
2040+ } ) ,
2041+ ) ;
2042+
2043+ expect ( routesOf ( yield * Ref . get ( harness . storedTargets ) , LAN_TARGET . environmentId ) ) . toEqual (
2044+ [ renamed , learned , RELAY_TARGET ] ,
2045+ ) ;
2046+ } ) . pipe ( Effect . provide ( harness . layer ) , Effect . scoped ) ;
2047+ } ) ,
2048+ ) ;
2049+
19682050 it . effect ( "pairing at a saved address under a new id drops routes learned over the old one" , ( ) =>
19692051 Effect . gen ( function * ( ) {
19702052 const learnedId = `learned:${ LAN_TARGET . environmentId } :http://100.88.1.2:3773@${ LAN_TARGET . connectionId } ` ;
0 commit comments