@@ -721,6 +721,22 @@ describe("trusted-proxy auth", () => {
721721 expect ( ( ) => assertGatewayAuthConfigured ( auth , authConfig ) ) . toThrow ( / m u t u a l l y e x c l u s i v e / ) ;
722722 } ) ;
723723
724+ it ( "still requires trustedProxy config before reporting a token conflict" , ( ) => {
725+ const auth = resolveGatewayAuth ( {
726+ authConfig : {
727+ mode : "trusted-proxy" ,
728+ token : "shared-secret" ,
729+ } ,
730+ } ) ;
731+
732+ expect ( ( ) =>
733+ assertGatewayAuthConfigured ( auth , {
734+ mode : "trusted-proxy" ,
735+ token : "shared-secret" ,
736+ } ) ,
737+ ) . toThrow ( / n o t r u s t e d P r o x y c o n f i g w a s p r o v i d e d / ) ;
738+ } ) ;
739+
724740 it ( "supports Pomerium-style headers" , async ( ) => {
725741 const res = await authorizeTrustedProxy ( {
726742 auth : {
@@ -762,7 +778,7 @@ describe("trusted-proxy auth", () => {
762778 expect ( res . user ) . toBe ( "nick@example.com" ) ;
763779 } ) ;
764780
765- describe ( "local-direct token fallback " , ( ) => {
781+ describe ( "local-direct trusted-proxy requests " , ( ) => {
766782 function authorizeLocalDirect ( options ?: {
767783 token ?: string ;
768784 connectToken ?: string ;
@@ -787,38 +803,37 @@ describe("trusted-proxy auth", () => {
787803 } ) ;
788804 }
789805
790- it ( "allows local-direct request with a valid token" , async ( ) => {
791- const res = await authorizeLocalDirect ( {
792- token : "secret" ,
793- connectToken : "secret" ,
794- } ) ;
795- expect ( res . ok ) . toBe ( true ) ;
796- expect ( res . method ) . toBe ( "token" ) ;
797- } ) ;
798-
799- it ( "rejects local-direct request without credentials" , async ( ) => {
800- const res = await authorizeLocalDirect ( {
801- token : "secret" ,
802- } ) ;
803- expect ( res . ok ) . toBe ( false ) ;
804- expect ( res . reason ) . toBe ( "token_missing" ) ;
805- } ) ;
806-
807- it ( "rejects local-direct request with a wrong token" , async ( ) => {
808- const res = await authorizeLocalDirect ( {
809- token : "secret" ,
810- connectToken : "wrong" ,
811- } ) ;
812- expect ( res . ok ) . toBe ( false ) ;
813- expect ( res . reason ) . toBe ( "token_mismatch" ) ;
814- } ) ;
815-
816- it ( "rejects local-direct request when no local token is configured" , async ( ) => {
817- const res = await authorizeLocalDirect ( {
818- connectToken : "secret" ,
819- } ) ;
806+ it . each ( [
807+ {
808+ name : "without credentials" ,
809+ options : {
810+ token : "secret" ,
811+ } ,
812+ } ,
813+ {
814+ name : "with a valid token" ,
815+ options : {
816+ token : "secret" ,
817+ connectToken : "secret" ,
818+ } ,
819+ } ,
820+ {
821+ name : "with a wrong token" ,
822+ options : {
823+ token : "secret" ,
824+ connectToken : "wrong" ,
825+ } ,
826+ } ,
827+ {
828+ name : "when no local token is configured" ,
829+ options : {
830+ connectToken : "secret" ,
831+ } ,
832+ } ,
833+ ] ) ( "rejects local-direct request $name" , async ( { options } ) => {
834+ const res = await authorizeLocalDirect ( options ) ;
820835 expect ( res . ok ) . toBe ( false ) ;
821- expect ( res . reason ) . toBe ( "token_missing_config " ) ;
836+ expect ( res . reason ) . toBe ( "trusted_proxy_loopback_source " ) ;
822837 } ) ;
823838
824839 it ( "rejects trusted-proxy identity headers from loopback sources" , async ( ) => {
@@ -867,7 +882,7 @@ describe("trusted-proxy auth", () => {
867882 expect ( res . reason ) . toBe ( "trusted_proxy_loopback_source" ) ;
868883 } ) ;
869884
870- it ( "uses token fallback for direct loopback even when Host is not localish" , async ( ) => {
885+ it ( "rejects direct loopback even when Host is not localish" , async ( ) => {
871886 const res = await authorizeGatewayConnect ( {
872887 auth : {
873888 mode : "trusted-proxy" ,
@@ -885,8 +900,8 @@ describe("trusted-proxy auth", () => {
885900 } as never ,
886901 } ) ;
887902
888- expect ( res . ok ) . toBe ( true ) ;
889- expect ( res . method ) . toBe ( "token " ) ;
903+ expect ( res . ok ) . toBe ( false ) ;
904+ expect ( res . reason ) . toBe ( "trusted_proxy_loopback_source " ) ;
890905 } ) ;
891906
892907 it ( "rejects same-host proxy request with missing required header" , async ( ) => {
0 commit comments