Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d0943f

Browse files
committed
Python: Add tests for turbogears.
1 parent 26c5ebd commit 7d0943f

10 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:7:5:7:32 | Function onerror |
2+
| test.py:13:5:13:50 | Function ok_validated |
3+
| test.py:18:5:18:57 | Function partially_validated |
4+
| test.py:22:5:22:51 | Function not_validated |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
import python
4+
5+
import semmle.python.web.turbogears.TurboGears
6+
7+
from TurboGearsControllerMethod m
8+
select m
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:8 | BinaryExpr | externally controlled string |
2+
| test.py:14 | BinaryExpr | externally controlled string |
3+
| test.py:19 | BinaryExpr | externally controlled string |
4+
| test.py:23 | BinaryExpr | externally controlled string |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 TaintSink sink, TaintKind kind
9+
where sink.sinks(kind)
10+
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:18 | b | externally controlled string |
2+
| test.py:22 | a | externally controlled string |
3+
| test.py:22 | b | externally controlled string |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.security.strings.Untrusted
6+
7+
8+
from TaintSource src, TaintKind kind
9+
where src.isSourceOf(kind)
10+
select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
| test.py:18 | b | externally controlled string |
2+
| test.py:19 | BinaryExpr | [externally controlled string] |
3+
| test.py:19 | BinaryExpr | externally controlled string |
4+
| test.py:19 | Tuple | [externally controlled string] |
5+
| test.py:19 | b | externally controlled string |
6+
| test.py:22 | a | externally controlled string |
7+
| test.py:22 | b | externally controlled string |
8+
| test.py:23 | BinaryExpr | [externally controlled string] |
9+
| test.py:23 | BinaryExpr | externally controlled string |
10+
| test.py:23 | Tuple | [externally controlled string] |
11+
| test.py:23 | a | externally controlled string |
12+
| test.py:23 | b | externally controlled string |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import python
3+
4+
5+
import semmle.python.web.HttpRequest
6+
import semmle.python.web.HttpResponse
7+
import semmle.python.security.strings.Untrusted
8+
9+
10+
from TaintedNode node
11+
12+
select node.getLocation().toString(), node.getNode().getNode().toString(), node.getTaintKind()
13+
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=3 --lang=3 -p ../../../query-tests/Security/lib/
2+
optimize: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from tg import request, validate, expose, TGController
3+
from formencode import validators
4+
5+
class RootController(TGController):
6+
@expose()
7+
def onerror(self, **kwargs):
8+
return 'An error occurred: %s' % request.validation['errors']
9+
10+
@expose()
11+
@validate({"a": validators.Int(not_empty=True), "b": validators.Email},
12+
error_handler=onerror)
13+
def ok_validated(self, a=None, b=None, *args):
14+
return 'Values: %s, %s, %s' % (a, b, args)
15+
16+
@expose()
17+
@validate({"a": validators.Int(not_empty=True)})
18+
def partially_validated(self, a=None, b=None, *args):
19+
return 'Values: %s, %s, %s' % (a, b, args)
20+
21+
@expose()
22+
def not_validated(self, a=None, b=None, *args):
23+
return 'Values: %s, %s, %s' % (a, b, args)

0 commit comments

Comments
 (0)