@@ -147,17 +147,23 @@ macro_rules! init_app {
147147}
148148
149149fn create_request (
150- method : http:: Method ,
150+ method : & http:: Method ,
151151 path : & str ,
152152 headers : Option < HashMap < & ' static str , String > > ,
153153 payload : Option < serde_json:: Value > ,
154+ settings : Option < & Settings > ,
154155) -> test:: TestRequest {
155- let settings = get_test_settings ( ) ;
156+ let test_settings = get_test_settings ( ) ;
157+ let settings = settings. unwrap_or ( & test_settings) ;
156158 let mut req = test:: TestRequest :: with_uri ( path)
157159 . method ( method. clone ( ) )
158160 . insert_header ( (
159161 "Authorization" ,
160- create_hawk_header ( method. as_str ( ) , settings. port , path) ,
162+ create_hawk_header (
163+ method. as_str ( ) ,
164+ settings. port ,
165+ & ( ReverseProxyState :: from_settings ( settings) . get_webroot ( ) + path) ,
166+ ) ,
161167 ) )
162168 . insert_header ( ( "Accept" , "application/json" ) )
163169 . insert_header ( (
@@ -229,20 +235,34 @@ async fn test_endpoint(
229235 status : Option < StatusCode > ,
230236 expected_body : Option < & str > ,
231237) {
232- let app = init_app ! ( ) . await ;
233-
234- let req = create_request ( method, path, None , None ) . to_request ( ) ;
235- let sresp = app
236- . call ( req)
237- . await
238- . expect ( "Could not get sresp in test_endpoint" ) ;
239- match status {
240- None => assert ! ( sresp. response( ) . status( ) . is_success( ) ) ,
241- Some ( status) => assert ! ( sresp. response( ) . status( ) == status) ,
242- } ;
243- if let Some ( x_body) = expected_body {
244- let body = test:: read_body ( sresp) . await ;
245- assert_eq ! ( body, x_body. as_bytes( ) ) ;
238+ for prefix in [ None , Some ( "/firefox-sync" ) ] {
239+ let settings = match prefix {
240+ None => None ,
241+ Some ( prefix) => {
242+ let mut settings = get_test_settings ( ) ;
243+ settings. public_url = Some ( format ! ( "https://example.com{}" , prefix) . to_owned ( ) ) ;
244+ Some ( settings)
245+ }
246+ } ;
247+
248+ let app = match settings. clone ( ) {
249+ None => init_app ! ( ) . await ,
250+ Some ( settings) => init_app ! ( settings) . await ,
251+ } ;
252+
253+ let req = create_request ( & method, path, None , None , settings. as_ref ( ) ) . to_request ( ) ;
254+ let sresp = app
255+ . call ( req)
256+ . await
257+ . expect ( "Could not get sresp in test_endpoint" ) ;
258+ match status {
259+ None => assert ! ( sresp. response( ) . status( ) . is_success( ) ) ,
260+ Some ( status) => assert ! ( sresp. response( ) . status( ) == status) ,
261+ } ;
262+ if let Some ( x_body) = expected_body {
263+ let body = test:: read_body ( sresp) . await ;
264+ assert_eq ! ( body, x_body. as_bytes( ) ) ;
265+ }
246266 }
247267}
248268
@@ -265,7 +285,7 @@ where
265285 ) )
266286 . await ;
267287
268- let req = create_request ( method, path, None , None ) . to_request ( ) ;
288+ let req = create_request ( & method, path, None , None , Some ( & settings ) ) . to_request ( ) ;
269289 let sresponse = match app. call ( req) . await {
270290 Ok ( v) => v,
271291 Err ( e) => {
@@ -309,11 +329,12 @@ async fn test_endpoint_with_body(
309329 metrics
310330 ) )
311331 . await ;
312- let req = create_request ( method, path, None , Some ( body) ) . to_request ( ) ;
332+ let req = create_request ( & method, path, None , Some ( body) , Some ( & settings ) ) . to_request ( ) ;
313333 let sresponse = app
314334 . call ( req)
315335 . await
316336 . expect ( "Could not get sresponse in test_endpoint_with_body" ) ;
337+ println ! ( "{sresponse:#?}" ) ;
317338 assert ! ( sresponse. response( ) . status( ) . is_success( ) ) ;
318339 test:: read_body ( sresponse) . await
319340}
@@ -530,7 +551,7 @@ async fn invalid_content_type() {
530551 let mut headers = HashMap :: new ( ) ;
531552 headers. insert ( "Content-Type" , "application/javascript" . to_owned ( ) ) ;
532553 let req = create_request (
533- http:: Method :: PUT ,
554+ & http:: Method :: PUT ,
534555 path,
535556 Some ( headers. clone ( ) ) ,
536557 Some ( json ! ( BsoBody {
@@ -540,6 +561,7 @@ async fn invalid_content_type() {
540561 ttl: Some ( 31_536_000 ) ,
541562 ..Default :: default ( )
542563 } ) ) ,
564+ None ,
543565 )
544566 . to_request ( ) ;
545567
@@ -553,7 +575,7 @@ async fn invalid_content_type() {
553575 let path = "/1.5/42/storage/bookmarks" ;
554576
555577 let req = create_request (
556- http:: Method :: POST ,
578+ & http:: Method :: POST ,
557579 path,
558580 Some ( headers. clone ( ) ) ,
559581 Some ( json ! ( [ BsoBody {
@@ -563,6 +585,7 @@ async fn invalid_content_type() {
563585 ttl: Some ( 31_536_000 ) ,
564586 ..Default :: default ( )
565587 } ] ) ) ,
588+ None ,
566589 )
567590 . to_request ( ) ;
568591
@@ -580,13 +603,14 @@ async fn invalid_batch_post() {
580603 let mut headers = HashMap :: new ( ) ;
581604 headers. insert ( "accept" , "application/json" . to_owned ( ) ) ;
582605 let req = create_request (
583- http:: Method :: POST ,
606+ & http:: Method :: POST ,
584607 "/1.5/42/storage/tabs?batch=sammich" ,
585608 Some ( headers) ,
586609 Some ( json ! ( [
587610 { "id" : "123" , "payload" : "xxx" , "sortindex" : 23 } ,
588611 { "id" : "456" , "payload" : "xxxasdf" , "sortindex" : 23 }
589612 ] ) ) ,
613+ None ,
590614 )
591615 . to_request ( ) ;
592616
@@ -610,10 +634,11 @@ async fn accept_new_or_dev_ios() {
610634 ) ;
611635
612636 let req = create_request (
613- http:: Method :: GET ,
637+ & http:: Method :: GET ,
614638 "/1.5/42/info/collections" ,
615639 Some ( headers) ,
616640 None ,
641+ None ,
617642 )
618643 . to_request ( ) ;
619644 let response = app. call ( req) . await . unwrap ( ) ;
@@ -626,10 +651,11 @@ async fn accept_new_or_dev_ios() {
626651 ) ;
627652
628653 let req = create_request (
629- http:: Method :: GET ,
654+ & http:: Method :: GET ,
630655 "/1.5/42/info/collections" ,
631656 Some ( headers) ,
632657 None ,
658+ None ,
633659 )
634660 . to_request ( ) ;
635661 let response = app. call ( req) . await . unwrap ( ) ;
@@ -642,10 +668,11 @@ async fn accept_new_or_dev_ios() {
642668 ) ;
643669
644670 let req = create_request (
645- http:: Method :: GET ,
671+ & http:: Method :: GET ,
646672 "/1.5/42/info/collections" ,
647673 Some ( headers) ,
648674 None ,
675+ None ,
649676 )
650677 . to_request ( ) ;
651678 let response = app. call ( req) . await . unwrap ( ) ;
@@ -662,22 +689,24 @@ async fn reject_old_ios() {
662689 ) ;
663690
664691 let req = create_request (
665- http:: Method :: GET ,
692+ & http:: Method :: GET ,
666693 "/1.5/42/info/collections" ,
667694 Some ( headers. clone ( ) ) ,
668695 None ,
696+ None ,
669697 )
670698 . to_request ( ) ;
671699 let response = app. call ( req) . await . unwrap ( ) ;
672700 assert_eq ! ( response. status( ) , StatusCode :: SERVICE_UNAVAILABLE ) ;
673701
674702 let req = create_request (
675- http:: Method :: POST ,
703+ & http:: Method :: POST ,
676704 "/1.5/42/storage/tabs?batch=sammich" ,
677705 Some ( headers) ,
678706 Some ( json ! ( [
679707 { "id" : "123" , "payload" : "xxx" , "sortindex" : 23 } ,
680708 ] ) ) ,
709+ None ,
681710 )
682711 . to_request ( ) ;
683712 let response = app. call ( req) . await . unwrap ( ) ;
@@ -689,8 +718,14 @@ async fn reject_old_ios() {
689718#[ actix_rt:: test]
690719async fn info_configuration_xlm ( ) {
691720 let app = init_app ! ( ) . await ;
692- let req =
693- create_request ( http:: Method :: GET , "/1.5/42/info/configuration" , None , None ) . to_request ( ) ;
721+ let req = create_request (
722+ & http:: Method :: GET ,
723+ "/1.5/42/info/configuration" ,
724+ None ,
725+ None ,
726+ None ,
727+ )
728+ . to_request ( ) ;
694729 let response = app. call ( req) . await . unwrap ( ) ;
695730 assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
696731 let xlm = response. headers ( ) . get ( X_LAST_MODIFIED ) ;
@@ -714,18 +749,26 @@ async fn overquota() {
714749 let app = init_app ! ( settings) . await ;
715750
716751 // Clear out any data that's already in the store.
717- let req = create_request ( http:: Method :: DELETE , "/1.5/42/storage" , None , None ) . to_request ( ) ;
752+ let req = create_request (
753+ & http:: Method :: DELETE ,
754+ "/1.5/42/storage" ,
755+ None ,
756+ None ,
757+ Some ( & settings) ,
758+ )
759+ . to_request ( ) ;
718760 let resp = app. call ( req) . await . unwrap ( ) ;
719761 assert ! ( resp. response( ) . status( ) . is_success( ) ) ;
720762
721763 // Quota is enforced before the write, allowing one write to go over
722764 let req = create_request (
723- http:: Method :: PUT ,
765+ & http:: Method :: PUT ,
724766 "/1.5/42/storage/xxx_col2/12345" ,
725767 None ,
726768 Some ( json ! (
727769 { "payload" : "*" . repeat( 500 ) }
728770 ) ) ,
771+ Some ( & settings) ,
729772 )
730773 . to_request ( ) ;
731774 let response = app. call ( req) . await . unwrap ( ) ;
@@ -736,12 +779,13 @@ async fn overquota() {
736779 actix_rt:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
737780
738781 let req = create_request (
739- http:: Method :: PUT ,
782+ & http:: Method :: PUT ,
740783 "/1.5/42/storage/xxx_col2/12345" ,
741784 None ,
742785 Some ( json ! (
743786 { "payload" : "*" . repeat( 500 ) }
744787 ) ) ,
788+ Some ( & settings) ,
745789 )
746790 . to_request ( ) ;
747791 let response = app. call ( req) . await . unwrap ( ) ;
@@ -763,7 +807,14 @@ async fn overquota() {
763807
764808 // XXX: this should run as cleanup regardless of test failure but it's
765809 // difficult. e.g. FutureExt::catch_unwind isn't compatible w/ actix-web
766- let req = create_request ( http:: Method :: DELETE , "/1.5/42/storage" , None , None ) . to_request ( ) ;
810+ let req = create_request (
811+ & http:: Method :: DELETE ,
812+ "/1.5/42/storage" ,
813+ None ,
814+ None ,
815+ Some ( & settings) ,
816+ )
817+ . to_request ( ) ;
767818 let resp = app. call ( req) . await . unwrap ( ) ;
768819 assert ! ( resp. response( ) . status( ) . is_success( ) ) ;
769820}
@@ -776,7 +827,14 @@ async fn lbheartbeat_max_pool_size_check() {
776827 let app = init_app ! ( settings) . await ;
777828
778829 // Test all is well.
779- let lb_req = create_request ( http:: Method :: GET , "/__lbheartbeat__" , None , None ) . to_request ( ) ;
830+ let lb_req = create_request (
831+ & http:: Method :: GET ,
832+ "/__lbheartbeat__" ,
833+ None ,
834+ None ,
835+ Some ( & settings) ,
836+ )
837+ . to_request ( ) ;
780838 let sresp = app. call ( lb_req) . await . unwrap ( ) ;
781839 let status = sresp. status ( ) ;
782840 // Uncomment only for debugging purposes:
@@ -788,10 +846,11 @@ async fn lbheartbeat_max_pool_size_check() {
788846 headers. insert ( "TEST_CONNECTIONS" , "10" . to_owned ( ) ) ;
789847 headers. insert ( "TEST_IDLES" , "0" . to_owned ( ) ) ;
790848 let req = create_request (
791- http:: Method :: GET ,
849+ & http:: Method :: GET ,
792850 "/__lbheartbeat__" ,
793851 Some ( headers. clone ( ) ) ,
794852 None ,
853+ Some ( & settings) ,
795854 )
796855 . to_request ( ) ;
797856 let sresp = app. call ( req) . await . unwrap ( ) ;
@@ -802,8 +861,14 @@ async fn lbheartbeat_max_pool_size_check() {
802861
803862 // check duration for exhausted connections
804863 actix_rt:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
805- let req =
806- create_request ( http:: Method :: GET , "/__lbheartbeat__" , Some ( headers) , None ) . to_request ( ) ;
864+ let req = create_request (
865+ & http:: Method :: GET ,
866+ "/__lbheartbeat__" ,
867+ Some ( headers) ,
868+ None ,
869+ Some ( & settings) ,
870+ )
871+ . to_request ( ) ;
807872 let sresp = app. call ( req) . await . unwrap ( ) ;
808873 let status = sresp. status ( ) ;
809874 let body = test:: read_body ( sresp) . await ;
@@ -818,8 +883,14 @@ async fn lbheartbeat_max_pool_size_check() {
818883 let mut headers: HashMap < & str , String > = HashMap :: new ( ) ;
819884 headers. insert ( "TEST_CONNECTIONS" , "5" . to_owned ( ) ) ;
820885 headers. insert ( "TEST_IDLES" , "5" . to_owned ( ) ) ;
821- let req =
822- create_request ( http:: Method :: GET , "/__lbheartbeat__" , Some ( headers) , None ) . to_request ( ) ;
886+ let req = create_request (
887+ & http:: Method :: GET ,
888+ "/__lbheartbeat__" ,
889+ Some ( headers) ,
890+ None ,
891+ Some ( & settings) ,
892+ )
893+ . to_request ( ) ;
823894 let sresp = app. call ( req) . await . unwrap ( ) ;
824895 let status = sresp. status ( ) ;
825896 // Uncomment only for debugging purposes:
@@ -835,13 +906,27 @@ async fn lbheartbeat_ttl_check() {
835906
836907 let app = init_app ! ( settings) . await ;
837908
838- let lb_req = create_request ( http:: Method :: GET , "/__lbheartbeat__" , None , None ) . to_request ( ) ;
909+ let lb_req = create_request (
910+ & http:: Method :: GET ,
911+ "/__lbheartbeat__" ,
912+ None ,
913+ None ,
914+ Some ( & settings) ,
915+ )
916+ . to_request ( ) ;
839917 let sresp = app. call ( lb_req) . await . unwrap ( ) ;
840918 assert ! ( sresp. status( ) . is_success( ) ) ;
841919
842920 actix_rt:: time:: sleep ( Duration :: from_secs ( 3 ) ) . await ;
843921
844- let lb_req = create_request ( http:: Method :: GET , "/__lbheartbeat__" , None , None ) . to_request ( ) ;
922+ let lb_req = create_request (
923+ & http:: Method :: GET ,
924+ "/__lbheartbeat__" ,
925+ None ,
926+ None ,
927+ Some ( & settings) ,
928+ )
929+ . to_request ( ) ;
845930 let sresp = app. call ( lb_req) . await . unwrap ( ) ;
846931 assert_eq ! ( sresp. status( ) , StatusCode :: INTERNAL_SERVER_ERROR ) ;
847932}
0 commit comments