Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add test for flask wtf csrf exempt config #17468

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/integration_tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ def test_full_setting(self):
self.assertEqual(dttm_col.python_date_format, "epoch_s")
self.assertEqual(dttm_col.expression, "CAST(dttm as INTEGER)")

def test_wtf_csrf_exempt_list(self):
# ensure that the exempt apis actually exist

# Derived from logic in flask-wtf:
# https://github.com/wtforms/flask-wtf/blob/v1.0.0/src/flask_wtf/csrf.py#L223-L224
all_view_functions = {
f"{view.__module__}.{view.__name__}" for view in app.view_functions.values()
}
for exempt_api in app.config["WTF_CSRF_EXEMPT_LIST"]:
Copy link
Contributor

@ofekisr ofekisr Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rare use case, but you should check against the default config (superset.config) and not from the test config even if the test config does not contain "WTF_CSRF_EXEMPT_LIST" key

self.assertTrue(exempt_api in all_view_functions)


if __name__ == "__main__":
unittest.main()