Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Nov 20, 2023
1 parent e5dc664 commit b45b257
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions integration_tests/test_secure_flask_session_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from core_codemods.secure_flask_session_config import SecureFlaskSessionConfig
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestSecureFlaskSessionConfig(BaseIntegrationTest):
codemod = SecureFlaskSessionConfig
code_path = "tests/samples/flask_app.py"
original_code, expected_new_code = original_and_expected_from_code_path(
code_path, [(2, "app.config['SESSION_COOKIE_HTTPONLY'] = True\n")]
)
expected_diff = "--- \n+++ \n@@ -1,6 +1,6 @@\n from flask import Flask\n app = Flask(__name__)\n-app.config['SESSION_COOKIE_HTTPONLY'] = False\n+app.config['SESSION_COOKIE_HTTPONLY'] = True\n @app.route('/')\n def hello_world():\n return 'Hello World!'\n"
expected_line_change = "3"
change_description = SecureFlaskSessionConfig.CHANGE_DESCRIPTION
2 changes: 2 additions & 0 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .use_generator import UseGenerator
from .use_walrus_if import UseWalrusIf
from .with_threading_lock import WithThreadingLock
from .secure_flask_session_config import SecureFlaskSessionConfig

registry = CodemodCollection(
origin="pixee",
Expand Down Expand Up @@ -60,5 +61,6 @@
UseWalrusIf,
WithThreadingLock,
SQLQueryParameterization,
SecureFlaskSessionConfig,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Flask applications can configure sessions behavior at the application level.
This codemod looks for Flask application configuration that set `SESSION_COOKIE_HTTPONLY`, `SESSION_COOKIE_SECURE`, or `SESSION_COOKIE_SAMESITE` to an insecure value and changes it to a secure one.

The changes from this codemod look like this:

```diff
from flask import Flask
app = Flask(__name__)
- app.config['SESSION_COOKIE_HTTPONLY'] = False
- app.config.update(SESSION_COOKIE_SECURE=False)
+ app.config['SESSION_COOKIE_HTTPONLY'] = True
+ app.config.update(SESSION_COOKIE_SECURE=True)
```
6 changes: 6 additions & 0 deletions tests/samples/flask_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
app.config['SESSION_COOKIE_HTTPONLY'] = False
@app.route('/')
def hello_world():
return 'Hello World!'

0 comments on commit b45b257

Please sign in to comment.