python: add simple test for AWS lambda

made space for other serverless frameworks in the directory `serverless`
This commit is contained in:
Rasmus Lerchedahl Petersen
2023-06-21 11:58:11 +02:00
parent af5cd7cf4f
commit a892e83c8e
6 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
failures
testFailures

View File

@@ -0,0 +1,20 @@
import python
import TestUtilities.InlineExpectationsTest
private module RemoteFlowTest implements TestSig {
private import semmle.python.dataflow.new.RemoteFlowSources
private import semmle.python.dataflow.new.internal.PrintNode
string getARelevantTag() { result = "remoteFlow" }
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(RemoteFlowSource source |
location = source.getLocation() and
tag = "remoteFlow" and
value = prettyNode(source) and
element = source.toString()
)
}
}
import MakeTest<RemoteFlowTest>

View File

@@ -0,0 +1,5 @@
def handler1(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
return "Hello World!"
def handler2(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
return "Hello World!"

View File

@@ -0,0 +1,2 @@
def lambda_handler(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
return "OK"

View File

@@ -0,0 +1,62 @@
# inspired by https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/blank-python/template.yml
# but we have added extra handlers
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Lambda application that calls the Lambda API.
Resources:
function:
Type: AWS::Serverless::Function
Properties:
Handler: lambda_function.lambda_handler
Runtime: python3.8
CodeUri: function/.
Description: Call the AWS Lambda API
Timeout: 10
# Function's execution role
Policies:
- AWSLambdaBasicExecutionRole
- AWSLambda_ReadOnlyAccess
- AWSXrayWriteOnlyAccess
Tracing: Active
Layers:
- !Ref libs
function:
Type: AWS::Serverless::Function
Properties:
Handler: extra_lambdas.handler1
Runtime: python3.8
CodeUri: function/.
Description: Call the AWS Lambda API
Timeout: 10
# Function's execution role
Policies:
- AWSLambdaBasicExecutionRole
- AWSLambda_ReadOnlyAccess
- AWSXrayWriteOnlyAccess
Tracing: Active
Layers:
- !Ref libs
function:
Type: AWS::Serverless::Function
Properties:
Handler: extra_lambdas.handler2
Runtime: python3.8
CodeUri: function/.
Description: Call the AWS Lambda API
Timeout: 10
# Function's execution role
Policies:
- AWSLambdaBasicExecutionRole
- AWSLambda_ReadOnlyAccess
- AWSXrayWriteOnlyAccess
Tracing: Active
Layers:
- !Ref libs
libs:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: blank-python-lib
Description: Dependencies for the blank-python sample app.
ContentUri: package/.
CompatibleRuntimes:
- python3.8

View File

@@ -0,0 +1 @@
semmle-extractor-options: -R .