Skip to content

Commit 6c24495

Browse files
committed
python: add concept tests
1 parent 441e206 commit 6c24495

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,35 @@ class HttpClientRequestTest extends InlineExpectationsTest {
503503
)
504504
}
505505
}
506+
507+
class CsrfProtectionSettingTest extends InlineExpectationsTest {
508+
CsrfProtectionSettingTest() { this = "CsrfProtectionSettingTest" }
509+
510+
override string getARelevantTag() { result = "CsrfProtectionSetting" }
511+
512+
override predicate hasActualResult(Location location, string element, string tag, string value) {
513+
exists(location.getFile().getRelativePath()) and
514+
exists(CsrfProtectionSetting setting |
515+
location = setting.getLocation() and
516+
element = setting.toString() and
517+
value = setting.getVerificationSetting().toString() and
518+
tag = "CsrfProtectionSetting"
519+
)
520+
}
521+
}
522+
523+
class CsrfLocalProtectionTest extends InlineExpectationsTest {
524+
CsrfLocalProtectionTest() { this = "CsrfLocalProtectionTest" }
525+
526+
override string getARelevantTag() { result = "CsrfLocalProtection" }
527+
528+
override predicate hasActualResult(Location location, string element, string tag, string value) {
529+
exists(location.getFile().getRelativePath()) and
530+
exists(CsrfLocalProtection p |
531+
location = p.getLocation() and
532+
element = p.toString() and
533+
value = p.getProtected().getName().toString() and
534+
tag = "CsrfLocalProtection"
535+
)
536+
}
537+
}

python/ql/test/library-tests/frameworks/django-v2-v3/response_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CustomJsonResponse(JsonResponse):
118118
def __init__(self, banner, content, *args, **kwargs):
119119
super().__init__(content, *args, content_type="text/html", **kwargs)
120120

121-
@csrf_protect
121+
@csrf_protect # $CsrfLocalProtection=safe__custom_json_response
122122
def safe__custom_json_response(request):
123123
return CustomJsonResponse("ACME Responses", {"foo": request.GET.get("foo")}) # $HttpResponse mimetype=application/json MISSING: responseBody=Dict SPURIOUS: responseBody="ACME Responses"
124124

python/ql/test/library-tests/frameworks/django-v2-v3/testproj/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'django.contrib.staticfiles',
4141
]
4242

43-
MIDDLEWARE = [
43+
MIDDLEWARE = [ # $CsrfProtectionSetting=false
4444
'django.middleware.security.SecurityMiddleware',
4545
'django.contrib.sessions.middleware.SessionMiddleware',
4646
'django.middleware.common.CommonMiddleware',

0 commit comments

Comments
 (0)