@@ -831,6 +831,118 @@ describe('Proxy text producers', function () {
831831 ) ;
832832 } ) ;
833833
834+ it ( 'emits quoted Surge alpn for TLS protocol outputs' , function ( ) {
835+ const alpn = [ 'http/1.1' , 'h2' , 'h3' ] ;
836+ const output = produceExternal ( 'Surge' , [
837+ {
838+ type : 'vmess' ,
839+ name : 'Surge VMess ALPN' ,
840+ server : 'vmess-alpn.example.com' ,
841+ port : 443 ,
842+ cipher : 'auto' ,
843+ uuid : UUID ,
844+ alterId : 0 ,
845+ tls : true ,
846+ alpn,
847+ } ,
848+ {
849+ type : 'trojan' ,
850+ name : 'Surge Trojan ALPN' ,
851+ server : 'trojan-alpn.example.com' ,
852+ port : 443 ,
853+ password : 'secret' ,
854+ alpn,
855+ } ,
856+ {
857+ type : 'http' ,
858+ name : 'Surge HTTPS ALPN' ,
859+ server : 'https-alpn.example.com' ,
860+ port : 443 ,
861+ tls : true ,
862+ alpn,
863+ } ,
864+ {
865+ type : 'h2-connect' ,
866+ name : 'Surge H2 ALPN' ,
867+ server : 'h2-alpn.example.com' ,
868+ port : 443 ,
869+ alpn,
870+ } ,
871+ {
872+ type : 'socks5' ,
873+ name : 'Surge SOCKS5 ALPN' ,
874+ server : 'socks-alpn.example.com' ,
875+ port : 1080 ,
876+ tls : true ,
877+ alpn,
878+ } ,
879+ {
880+ type : 'anytls' ,
881+ name : 'Surge AnyTLS ALPN' ,
882+ server : 'anytls-alpn.example.com' ,
883+ port : 443 ,
884+ password : 'secret' ,
885+ alpn,
886+ } ,
887+ {
888+ type : 'trusttunnel' ,
889+ name : 'Surge TrustTunnel ALPN' ,
890+ server : 'trust-alpn.example.com' ,
891+ port : 443 ,
892+ alpn,
893+ } ,
894+ {
895+ type : 'tuic' ,
896+ name : 'Surge TUIC ALPN' ,
897+ server : 'tuic-alpn.example.com' ,
898+ port : 443 ,
899+ uuid : UUID ,
900+ password : 'secret' ,
901+ alpn,
902+ } ,
903+ {
904+ type : 'hysteria2' ,
905+ name : 'Surge Hysteria2 ALPN' ,
906+ server : 'hy2-alpn.example.com' ,
907+ port : 443 ,
908+ password : 'secret' ,
909+ alpn,
910+ } ,
911+ ] ) ;
912+
913+ expect ( output . match ( / a l p n = " h t t p \/ 1 \. 1 , h 2 , h 3 " / g) ) . to . have . length ( 9 ) ;
914+ } ) ;
915+
916+ it ( 'omits Surge alpn for non-TLS outputs' , function ( ) {
917+ const output = produceExternal ( 'Surge' , [
918+ {
919+ type : 'vmess' ,
920+ name : 'Surge VMess Plain ALPN' ,
921+ server : 'vmess-plain-alpn.example.com' ,
922+ port : 80 ,
923+ uuid : UUID ,
924+ alterId : 0 ,
925+ alpn : [ 'http/1.1' , 'h2' ] ,
926+ } ,
927+ {
928+ type : 'http' ,
929+ name : 'Surge HTTP Plain ALPN' ,
930+ server : 'http-plain-alpn.example.com' ,
931+ port : 80 ,
932+ alpn : [ 'http/1.1' , 'h2' ] ,
933+ } ,
934+ {
935+ type : 'socks5' ,
936+ name : 'Surge SOCKS5 Plain ALPN' ,
937+ server : 'socks-plain-alpn.example.com' ,
938+ port : 1080 ,
939+ alpn : [ 'http/1.1' , 'h2' ] ,
940+ } ,
941+ ] ) ;
942+
943+ expect ( output ) . to . not . include ( 'alpn=' ) ;
944+ } ) ;
945+
834946 it ( 'produces Surge TUIC v5 lines with port hopping' , function ( ) {
835947 const output = produceExternal ( 'Surge' , {
836948 type : 'tuic' ,
@@ -847,7 +959,7 @@ describe('Proxy text producers', function () {
847959 } ) ;
848960
849961 expect ( output ) . to . equal (
850- `Surge TUIC=tuic-v5,tuic.example.com,443,uuid=${ UUID } ,password="secret",alpn=h3, port-hopping="9000;9002-9004",sni="sni.example.com",skip-cert-verify=true,ecn=true` ,
962+ `Surge TUIC=tuic-v5,tuic.example.com,443,uuid=${ UUID } ,password="secret",port-hopping="9000;9002-9004",sni="sni.example.com",alpn="h3 ",skip-cert-verify=true,ecn=true` ,
851963 ) ;
852964 } ) ;
853965
@@ -880,7 +992,7 @@ describe('Proxy text producers', function () {
880992 ] ) ;
881993
882994 expect ( output ) . to . equal (
883- `Surge TUIC Plain=tuic-v5,tuic.example.com,443,uuid=${ UUID } ,password="secret",alpn=h3, sni="sni.example.com",skip-cert-verify=true\nSurge Hysteria2 Plain=hysteria2,hy2.example.com,443,password="secret",sni="peer.example.com",skip-cert-verify=true` ,
995+ `Surge TUIC Plain=tuic-v5,tuic.example.com,443,uuid=${ UUID } ,password="secret",sni="sni.example.com",alpn="h3 ",skip-cert-verify=true\nSurge Hysteria2 Plain=hysteria2,hy2.example.com,443,password="secret",sni="peer.example.com",skip-cert-verify=true` ,
884996 ) ;
885997 } ) ;
886998
0 commit comments