@@ -353,7 +353,7 @@ describe("RemoteEnvironmentAuthorization", () => {
353353 } ) ;
354354 const harness = yield * makeHarness ( {
355355 initialToken : cached ,
356- responses : [ websocketTicket ( "lan-ticket" ) ] ,
356+ responses : [ Response . json ( DESCRIPTOR ) , websocketTicket ( "lan-ticket" ) ] ,
357357 } ) ;
358358
359359 const authorized = yield * Effect . gen ( function * ( ) {
@@ -370,8 +370,42 @@ describe("RemoteEnvironmentAuthorization", () => {
370370 expect ( authorized . httpBaseUrl ) . toBe ( "http://192.168.1.10:3773/" ) ;
371371 expect ( authorized . socketUrl ) . toMatch ( / ^ w s : \/ \/ 1 9 2 \. 1 6 8 \. 1 \. 1 0 : 3 7 7 3 \/ w s \? / ) ;
372372 expect ( yield * Ref . get ( harness . bootstrapCalls ) ) . toBe ( 0 ) ;
373- expect ( String ( harness . fetch . calls [ 0 ] ?. [ 0 ] ) ) . toBe (
373+ expect ( harness . fetch . calls . map ( ( [ url ] ) => String ( url ) ) ) . toEqual ( [
374+ "http://192.168.1.10:3773/.well-known/t3/environment" ,
374375 "http://192.168.1.10:3773/api/auth/websocket-ticket" ,
376+ ] ) ;
377+ } ) ,
378+ ) ;
379+
380+ it . effect ( "sends no token to a direct address that answers as another machine" , ( ) =>
381+ Effect . gen ( function * ( ) {
382+ const harness = yield * makeHarness ( {
383+ initialToken : persistedToken ( { accessToken : "cached-access-token" } ) ,
384+ responses : [
385+ Response . json ( { ...DESCRIPTOR , environmentId : EnvironmentId . make ( "someone-else" ) } ) ,
386+ ] ,
387+ } ) ;
388+
389+ const error = yield * Effect . gen ( function * ( ) {
390+ const remote = yield * RemoteEnvironmentAuthorization . RemoteEnvironmentAuthorization ;
391+ return yield * remote
392+ . authorizeDpop ( {
393+ expectedEnvironmentId : ENVIRONMENT_ID ,
394+ directEndpoint : {
395+ httpBaseUrl : "http://192.168.1.10:3773/" ,
396+ wsBaseUrl : "ws://192.168.1.10:3773/" ,
397+ } ,
398+ } )
399+ . pipe ( Effect . flip ) ;
400+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
401+
402+ expect ( error ) . toMatchObject ( { _tag : "ConnectionBlockedError" , reason : "configuration" } ) ;
403+ expect ( harness . fetch . calls . map ( ( [ url ] ) => String ( url ) ) ) . toEqual ( [
404+ "http://192.168.1.10:3773/.well-known/t3/environment" ,
405+ ] ) ;
406+ // The token stays saved for the T3 Connect route.
407+ expect ( ( yield * Ref . get ( harness . tokens ) ) . get ( ENVIRONMENT_ID ) ?. accessToken ) . toBe (
408+ "cached-access-token" ,
375409 ) ;
376410 } ) ,
377411 ) ;
@@ -390,6 +424,7 @@ describe("RemoteEnvironmentAuthorization", () => {
390424 const harness = yield * makeHarness ( {
391425 initialToken : cached ,
392426 responses : [
427+ Response . json ( DESCRIPTOR ) ,
393428 authInvalid ( ) ,
394429 Response . json ( DESCRIPTOR ) ,
395430 accessToken ( "replacement-access-token" ) ,
0 commit comments