This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 447
fixing XSS vulnerability #678
Open
marcosptf
wants to merge
6
commits into
quokkaproject:master
Choose a base branch
from
marcosptf:hotfix/issue675
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
470997a
WIP: fixing XSS vulnerability
marcosptf 538b074
fixing pep8
marcosptf 7156c76
fixing XSS issue
marcosptf 3136059
fixing patterns and add import regex
marcosptf 10b1d22
add pytest to hotfix/issue675
marcosptf 1746e24
add pytest to hotfix/issue675 - 2
marcosptf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ twine>=1.9.1 | |
wheel>=0.30.0 | ||
flask>=1.0 | ||
logzero | ||
pytest_mock |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,155 @@ | ||
import mock | ||
import quokka | ||
from quokka import create_app, create_app_base | ||
from pytest_mock import mocker | ||
from quokka.core.app import QuokkaApp | ||
from quokka.core.flask_dynaconf import configure_dynaconf | ||
|
||
|
||
################################ | ||
# pytest - fixtures - setUp(); # | ||
################################ | ||
class MockTestApp(object): | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
return self.config | ||
|
||
|
||
##################################### | ||
# pytest - Quokka - test__init__.py # | ||
##################################### | ||
def test_create_app_called_params_default(mocker): | ||
mocker.patch("quokka.create_app_base") | ||
mocker.patch("quokka.core.configure_extensions") | ||
quokka.create_app() | ||
quokka.create_app_base.assert_called_once_with(test=False) | ||
|
||
|
||
def test_create_app_called_test_false(mocker): | ||
mocker.patch("quokka.create_app_base") | ||
mocker.patch("quokka.core.configure_extensions") | ||
quokka.create_app(test=False) | ||
quokka.create_app_base.assert_called_once_with(test=False) | ||
|
||
|
||
def test_create_app_called_test_true(mocker): | ||
mocker.patch("quokka.create_app_base") | ||
mocker.patch("quokka.core.configure_extensions") | ||
quokka.create_app(test=True) | ||
quokka.create_app_base.assert_called_once_with(test=True) | ||
|
||
|
||
def test_create_app_called_test_true_and_settings_dict(mocker): | ||
mocker.patch("quokka.create_app_base") | ||
mocker.patch("quokka.core.configure_extensions") | ||
quokka.create_app(test=True, settings={'a':'1', 'b':'2', 'c':'3', 'd':'4', 'e':'5'}) | ||
quokka.create_app_base.assert_called_once_with(test=True, settings={'a':'1', 'b':'2', 'c':'3', 'd':'4', 'e':'5'}) | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_quokkaapp_called_is_false(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
quokka.create_app_base(test=False, ext_list=None) | ||
assert mock_QuokkaApp.called is False | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_dynaconf_called_is_false(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
quokka.create_app_base(test=False, ext_list=None) | ||
assert mock_configure_dynaconf.called is False | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_configure_extension_called_is_false(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
quokka.create_app_base(test=False, ext_list=None) | ||
assert mock_configure_extension.called is False | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_quokkaapp_called_is_false_and_test_true(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
quokka.create_app_base(test=True, ext_list=[]) | ||
assert mock_QuokkaApp.called is False | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_dynaconf_called_is_false_test_true_and_ext_list(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
quokka.create_app_base(test=True, ext_list=['quokka.core.configure_extension']) | ||
assert mock_configure_dynaconf.called is False | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_configure_dynaconf_called_is_true(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext) | ||
assert mock_configure_dynaconf.called is True | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_quokkaapp_called_is_true(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext) | ||
assert mock_QuokkaApp.called is True | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_configure_extension_called_is_true(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext) | ||
assert mock_configure_extension.called is True | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_configure_extension_called_is_true_and_settings(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext, settings={'a':'1', 'b':'2', 'c':'3', 'd':'4', 'e':'5'}) | ||
assert mock_configure_extension.called is True | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_configure_dynaconf_called_is_true_and_settings(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext, settings={'a':'1', 'b':'2', 'c':'3', 'd':'4', 'e':'5'}) | ||
assert mock_configure_dynaconf.called is True | ||
|
||
|
||
@mock.patch("quokka.core.app.QuokkaApp") | ||
@mock.patch("quokka.core.flask_dynaconf.configure_dynaconf") | ||
@mock.patch("quokka.core.configure_extension") | ||
def test_create_app_base_function_quokkaapp_called_is_true_and_settings(mock_configure_extension, mock_configure_dynaconf, mock_QuokkaApp): | ||
list_ext = ['quokka.core.app.QuokkaApp', | ||
'quokka.core.flask_dynaconf.configure_dynaconf', | ||
'quokka.core.configure_extension'] | ||
quokka.create_app_base(test=True, ext_list=list_ext, settings={'a':'1', 'b':'2', 'c':'3', 'd':'4', 'e':'5'}) | ||
assert mock_QuokkaApp.called is True | ||
|
||
|
||
def test_basic(app): | ||
assert app.name == 'quokka' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
from flask import request | ||
from urllib.parse import urljoin | ||
from slugify.main import Slugify | ||
from quokka.utils.text import ( | ||
abbreviate, normalize_var, | ||
make_social_link, make_social_link, | ||
make_social_name, cdata, | ||
make_external_url, split_all_category_roots, | ||
remove_tags_from_string | ||
) | ||
|
||
################################ | ||
#pytest - fixtures - setUp(); # | ||
################################ | ||
slugify = Slugify() | ||
slugify.to_lower = True | ||
slugify_category = Slugify() | ||
slugify_category.to_lower = True | ||
slugify_category.safe_chars = '/' | ||
abbrev = abbreviate("pytest-mock") | ||
norma = normalize_var("http://yahoo.com") | ||
make_link = make_social_link(network="twitter", txt="http://twitter.com/python") | ||
make_name = make_social_name('http://twitter.com/python') | ||
data = cdata("py-cdata") | ||
split = split_all_category_roots(cat="categoria1/categoria2/categoria3") | ||
|
||
|
||
################################## | ||
#pytest - Quokka - test_text.py # | ||
################################## | ||
def test_abbreviate(): | ||
debugger = abbreviate("pytest-mock") | ||
assert abbrev == 'pytest-mock' | ||
|
||
def test_normalize_var(): | ||
assert norma == "http:__yahoo.com" | ||
|
||
|
||
def test_make_social_link(): | ||
assert make_link == 'http://twitter.com/python' | ||
|
||
|
||
def test_make_social_name(): | ||
assert make_name == 'python' | ||
|
||
def test_cdata(): | ||
assert data == '<![CDATA[\npy-cdata\n]]>' | ||
|
||
def test_make_external_url(): | ||
with pytest.raises(RuntimeError) as err: | ||
make_external_url("http://it.yahoo.com") | ||
assert "Working outside of application context." in str(err.value) | ||
|
||
def test_split_all_category_roots(): | ||
assert split[0] == 'categoria1/categoria2/categoria3' | ||
assert split[1] == 'categoria1/categoria2' | ||
assert split[2] == 'categoria1' | ||
|
||
def test_remove_tags_from_string(): | ||
assert remove_tags_from_string('<script>alert("python-quokka");</script>') == 'alertpython-quokka' | ||
assert remove_tags_from_string('<script>console.log("python-quokka");</script>') == 'console.logpython-quokka' | ||
assert remove_tags_from_string('<b>python-quokka</b>') == 'python-quokka' | ||
assert remove_tags_from_string('<style>position:relative;top:10px;float:left;</style>') == 'position:relativetop:10pxfloat:left' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider remover these comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already fixed in another pr => #680