Skip to content

Commit 2874c54

Browse files
committed
Python: Move pyramid tests from internal repo
Use minimal mock instead of full library
1 parent 7c44c37 commit 2874c54

File tree

13 files changed

+99
-0
lines changed

13 files changed

+99
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.py:7 | Function home |
2+
| test.py:15 | Function greet |
3+
| test.py:24 | Function stuff |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import python
2+
3+
import semmle.python.web.pyramid.View
4+
5+
from Function func
6+
7+
where is_pyramid_view_function(func)
8+
9+
select func.getLocation().toString(), func.toString()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.py:8 | Response() | externally controlled string |
2+
| test.py:17 | Response() | externally controlled string |
3+
| test.py:25 | Dict | externally controlled string |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
9+
from TaintSink sink, TaintKind kind
10+
where sink.sinks(kind) and sink.getLocation().getFile().getName().matches("%test.py")
11+
select sink.getLocation().toString(), sink.(ControlFlowNode).getNode().toString(), kind
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.py:7 | request | pyramid.request |
2+
| test.py:15 | request | pyramid.request |
3+
| test.py:24 | request | pyramid.request |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
9+
from TaintSource src, TaintKind kind
10+
where src.isSourceOf(kind)
11+
select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
| test.py:7 | request | pyramid.request |
2+
| test.py:15 | request | pyramid.request |
3+
| test.py:16 | Attribute | {externally controlled string} |
4+
| test.py:16 | Subscript | externally controlled string |
5+
| test.py:16 | request | pyramid.request |
6+
| test.py:17 | BinaryExpr | externally controlled string |
7+
| test.py:17 | name | externally controlled string |
8+
| test.py:24 | request | pyramid.request |
9+
| test.py:25 | Attribute | externally controlled string |
10+
| test.py:25 | Dict | {externally controlled string} |
11+
| test.py:25 | request | pyramid.request |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
from TaintedNode node
9+
where node.getLocation().getFile().getName().matches("%test.py")
10+
11+
select node.getLocation().toString(), node.getAstNode().toString(), node.getTaintKind()
12+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: --max-import-depth=2 -p ../../../query-tests/Security/lib/
2+
optimize: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pyramid.view import view_config
2+
from pyramid.response import Response
3+
4+
@view_config(
5+
route_name='home'
6+
)
7+
def home(request):
8+
return Response('Welcome!')
9+
10+
11+
@view_config(
12+
route_name='greet',
13+
request_method='POST'
14+
)
15+
def greet(request):
16+
name = request.POST['arg']
17+
return Response('Welcome %s!' % name)
18+
19+
20+
@view_config(
21+
route_name='stuff',
22+
renderer='json'
23+
)
24+
def stuff(request):
25+
return {"err": 0, "body": request.body}

0 commit comments

Comments
 (0)