Skip to content

Commit a892e83

Browse files
committed
python: add simple test for AWS lambda
made space for other serverless frameworks in the directory `serverless`
1 parent af5cd7c commit a892e83

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import python
2+
import TestUtilities.InlineExpectationsTest
3+
4+
private module RemoteFlowTest implements TestSig {
5+
private import semmle.python.dataflow.new.RemoteFlowSources
6+
private import semmle.python.dataflow.new.internal.PrintNode
7+
8+
string getARelevantTag() { result = "remoteFlow" }
9+
10+
predicate hasActualResult(Location location, string element, string tag, string value) {
11+
exists(RemoteFlowSource source |
12+
location = source.getLocation() and
13+
tag = "remoteFlow" and
14+
value = prettyNode(source) and
15+
element = source.toString()
16+
)
17+
}
18+
}
19+
20+
import MakeTest<RemoteFlowTest>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def handler1(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
2+
return "Hello World!"
3+
4+
def handler2(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
5+
return "Hello World!"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def lambda_handler(event, context): # $ MISSING: remoteFlow=event, remoteFlow=context
2+
return "OK"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# inspired by https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/blank-python/template.yml
2+
# but we have added extra handlers
3+
AWSTemplateFormatVersion: '2010-09-09'
4+
Transform: 'AWS::Serverless-2016-10-31'
5+
Description: An AWS Lambda application that calls the Lambda API.
6+
Resources:
7+
function:
8+
Type: AWS::Serverless::Function
9+
Properties:
10+
Handler: lambda_function.lambda_handler
11+
Runtime: python3.8
12+
CodeUri: function/.
13+
Description: Call the AWS Lambda API
14+
Timeout: 10
15+
# Function's execution role
16+
Policies:
17+
- AWSLambdaBasicExecutionRole
18+
- AWSLambda_ReadOnlyAccess
19+
- AWSXrayWriteOnlyAccess
20+
Tracing: Active
21+
Layers:
22+
- !Ref libs
23+
function:
24+
Type: AWS::Serverless::Function
25+
Properties:
26+
Handler: extra_lambdas.handler1
27+
Runtime: python3.8
28+
CodeUri: function/.
29+
Description: Call the AWS Lambda API
30+
Timeout: 10
31+
# Function's execution role
32+
Policies:
33+
- AWSLambdaBasicExecutionRole
34+
- AWSLambda_ReadOnlyAccess
35+
- AWSXrayWriteOnlyAccess
36+
Tracing: Active
37+
Layers:
38+
- !Ref libs
39+
function:
40+
Type: AWS::Serverless::Function
41+
Properties:
42+
Handler: extra_lambdas.handler2
43+
Runtime: python3.8
44+
CodeUri: function/.
45+
Description: Call the AWS Lambda API
46+
Timeout: 10
47+
# Function's execution role
48+
Policies:
49+
- AWSLambdaBasicExecutionRole
50+
- AWSLambda_ReadOnlyAccess
51+
- AWSXrayWriteOnlyAccess
52+
Tracing: Active
53+
Layers:
54+
- !Ref libs
55+
libs:
56+
Type: AWS::Serverless::LayerVersion
57+
Properties:
58+
LayerName: blank-python-lib
59+
Description: Dependencies for the blank-python sample app.
60+
ContentUri: package/.
61+
CompatibleRuntimes:
62+
- python3.8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: -R .

0 commit comments

Comments
 (0)