@@ -384,6 +384,7 @@ fn into_vpc_lattice_request(vlr: VpcLatticeRequestV2) -> http::Request<Body> {
384384
385385 req
386386}
387+
387388#[ cfg( feature = "pass_through" ) ]
388389fn into_pass_through_request ( data : String ) -> http:: Request < Body > {
389390 let mut builder = http:: Request :: builder ( ) ;
@@ -479,7 +480,7 @@ impl RequestContext {
479480 Self :: ApiGatewayV2 ( ag) => ag. authorizer . as_ref ( ) ,
480481 #[ cfg( feature = "apigw_websockets" ) ]
481482 Self :: WebSocket ( ag) => Some ( & ag. authorizer ) ,
482- #[ cfg( any( feature = "alb" , feature = "pass_through" ) ) ]
483+ #[ cfg( any( feature = "alb" , feature = "pass_through" , feature = "vpc_lattice" ) ) ]
483484 _ => None ,
484485 }
485486 }
@@ -826,6 +827,7 @@ mod tests {
826827 }
827828
828829 #[ test]
830+ #[ cfg( feature = "vpc_lattice" ) ]
829831 fn deserializes_vpc_lattice_basic ( ) {
830832 let input = include_str ! ( "../tests/data/vpc_lattice_v2_request.json" ) ;
831833 let result = from_str ( input) ;
@@ -861,6 +863,7 @@ mod tests {
861863 }
862864
863865 #[ test]
866+ #[ cfg( feature = "vpc_lattice" ) ]
864867 fn deserializes_vpc_lattice_basic_base64 ( ) {
865868 let input = include_str ! ( "../tests/data/vpc_lattice_v2_request_base64.json" ) ;
866869 let result = from_str ( input) ;
@@ -896,6 +899,7 @@ mod tests {
896899 }
897900
898901 #[ test]
902+ #[ cfg( feature = "vpc_lattice" ) ]
899903 fn deserializes_vpc_lattice_headers ( ) {
900904 let input = include_str ! ( "../tests/data/vpc_lattice_v2_request.json" ) ;
901905 let result = from_str ( input) ;
@@ -936,6 +940,7 @@ mod tests {
936940 }
937941
938942 #[ test]
943+ #[ cfg( feature = "vpc_lattice" ) ]
939944 fn deserializes_vpc_lattice_multi_value_querys ( ) {
940945 let input = include_str ! ( "../tests/data/vpc_lattice_v2_request.json" ) ;
941946 let result = from_str ( input) ;
@@ -1179,4 +1184,65 @@ mod tests {
11791184 let authorizer = req_context. authorizer ( ) . expect ( "authorizer is missing" ) ;
11801185 assert_eq ! ( Some ( "admin" ) , authorizer. fields. get( "principalId" ) . unwrap( ) . as_str( ) ) ;
11811186 }
1187+
1188+ #[ test]
1189+ #[ cfg( all( feature = "apigw_http" , feature = "vpc_lattice" ) ) ]
1190+ fn vpc_lattice_event_does_not_match_apigw_v2 ( ) {
1191+ let data = include_bytes ! ( "../../lambda-events/src/fixtures/example-vpc-lattice-v2-request.json" ) ;
1192+ let result = serde_json:: from_slice :: < ApiGatewayV2httpRequest > ( data) ;
1193+ assert ! ( result. is_err( ) , "VPC Lattice event should not deserialize as APIGW V2" ) ;
1194+ }
1195+
1196+ #[ test]
1197+ #[ cfg( feature = "vpc_lattice" ) ]
1198+ fn vpc_lattice_method_none_defaults_to_get ( ) {
1199+ let input = r#"{
1200+ "version": "2.0",
1201+ "path": "/ping",
1202+ "headers": {"accept": ["*/*"]},
1203+ "queryStringParameters": {},
1204+ "isBase64Encoded": false,
1205+ "requestContext": {
1206+ "serviceNetworkArn": "arn:aws:vpc-lattice:us-east-1:123456789012:servicenetwork/sn-abc",
1207+ "serviceArn": "arn:aws:vpc-lattice:us-east-1:123456789012:service/svc-abc",
1208+ "targetGroupArn": "arn:aws:vpc-lattice:us-east-1:123456789012:targetgroup/tg-abc",
1209+ "region": "us-east-1",
1210+ "timeEpoch": "1724875399456789"
1211+ }
1212+ }"# ;
1213+ let result = from_str ( input) ;
1214+ assert ! ( result. is_ok( ) , "event was not parsed as expected {result:?}" ) ;
1215+ let request = result. expect ( "failed to parse request" ) ;
1216+ assert_eq ! ( request. method( ) , "GET" ) ;
1217+ }
1218+
1219+ #[ test]
1220+ #[ cfg( feature = "vpc_lattice" ) ]
1221+ fn vpc_lattice_post_with_body ( ) {
1222+ let input = r#"{
1223+ "version": "2.0",
1224+ "path": "/submit",
1225+ "method": "POST",
1226+ "headers": {"content-type": ["application/json"]},
1227+ "queryStringParameters": {},
1228+ "body": "{\"key\":\"value\"}",
1229+ "isBase64Encoded": false,
1230+ "requestContext": {
1231+ "serviceNetworkArn": "arn:aws:vpc-lattice:us-east-1:123456789012:servicenetwork/sn-abc",
1232+ "serviceArn": "arn:aws:vpc-lattice:us-east-1:123456789012:service/svc-abc",
1233+ "targetGroupArn": "arn:aws:vpc-lattice:us-east-1:123456789012:targetgroup/tg-abc",
1234+ "region": "us-east-1",
1235+ "timeEpoch": "1724875399456789"
1236+ }
1237+ }"# ;
1238+ let result = from_str ( input) ;
1239+ assert ! ( result. is_ok( ) , "event was not parsed as expected {result:?}" ) ;
1240+ let request = result. expect ( "failed to parse request" ) ;
1241+ assert_eq ! ( request. method( ) , "POST" ) ;
1242+ let body_str = match request. body ( ) {
1243+ Body :: Text ( s) => s. as_str ( ) ,
1244+ other => panic ! ( "expected text body, got {other:?}" ) ,
1245+ } ;
1246+ assert_eq ! ( body_str, r#"{"key":"value"}"# ) ;
1247+ }
11821248}
0 commit comments