-
Notifications
You must be signed in to change notification settings - Fork 2
Add URL and intersphinx mapping sanitization utilities to docs config #373
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
Merged
reactive-firewall
merged 11 commits into
master
from
feature-sanitize-documentation-urls-213
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93521bf
[FEATURE] Added inital implementation of url sanitization to document…
reactive-firewall 4938244
[PATCH] Apply some changes as per review (- WIP PR #373 -)
reactive-firewall e193d62
[PATCH] added regression for another typo found in PR #373
reactive-firewall b00d037
[STYLE] Minor improvements from review (- WIP PR #373 -)
reactive-firewall adc70cc
[TESTING] Improved testing as suggested in review (- WIP PR #373 -)
reactive-firewall 2977f7c
[TESTING] Added doctests as suggested in review (- WIP PR #373 -)
reactive-firewall 357247a
[STYLE] Applied changes as per review (- WIP PR #373 -)
reactive-firewall 836eeeb
[TESTING] Minor improvement to extra test logic (- WIP PR #373 -)
reactive-firewall a151a3a
[STYLE] Applied changes from Review (- WIP PR #213 -)
reactive-firewall e5c341c
[PATCH] Apply changes from review (- WIP PR #373 -)
reactive-firewall 03ab8e2
[SECURITY] Hardening documentation urls more (- WIP PR #373 -)
reactive-firewall 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
#! /usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Multicast Python Module (Testing) | ||
# .................................. | ||
# Copyright (c) 2025, Mr. Walls | ||
# .................................. | ||
# Licensed under MIT (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# .......................................... | ||
# https://www.github.com/reactive-firewall/multicast/LICENSE.md | ||
# .......................................... | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Extra Test module for docs.utils functionality. | ||
|
||
This module provides extra test cases for the docs.utils module, focusing on the | ||
utils.sanitize_url method for url encoding. | ||
""" | ||
|
||
|
||
__module__ = "tests" | ||
|
||
|
||
try: | ||
try: | ||
import context | ||
except Exception as _: # pragma: no branch | ||
del _ # skipcq - cleanup any error vars early | ||
from . import context | ||
if context.__name__ is None: | ||
raise ModuleNotFoundError("[CWE-758] Failed to import context") from None | ||
else: | ||
from context import unittest | ||
import docs.utils | ||
except Exception as err: | ||
raise ImportError("[CWE-758] Failed to import test context") from err | ||
|
||
reactive-firewall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@context.markWithMetaTag("extra", "security") | ||
class ExtraDocsUtilsTestSuite(context.BasicUsageTestSuite): | ||
reactive-firewall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Test cases for docs.utils module.""" | ||
|
||
__module__ = "tests.test_extra" | ||
|
||
URL_TEST_FIXTURES = [ | ||
{ | ||
"input_url": "https://github.com/user/repo", | ||
"expected": "https://github.com/user/repo", | ||
}, | ||
{ | ||
"input_url": "https://github.com/user/repo with spaces", | ||
"expected": "https://github.com/user/repo%20with%20spaces", | ||
}, | ||
{ | ||
"input_url": "https://github.com/user/repo?q=test&sort=desc", | ||
"expected": "https://github.com/user/repo?q%3Dtest%26sort%3Ddesc", | ||
}, | ||
{ | ||
"input_url": "https://github.com/user/repo#section", | ||
"expected": "https://github.com/user/repo#section", | ||
}, | ||
{ | ||
"input_url": "https://github.com/user/repo/<script>alert('xss')</script>", | ||
"expected": "https://github.com/user/repo/%3Cscript%3Ealert%28%27xss%27%29%3C/script%3E", | ||
reactive-firewall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
] | ||
reactive-firewall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_sanitize_url_GIVEN_raw_url_IS_reliable(self) -> None: | ||
"""Test case 1: Test to ensure reliable URL sanitization.""" | ||
# Mock _hearstep to return a non-empty response | ||
for test_params in self.URL_TEST_FIXTURES: | ||
sanitized_url = docs.utils.sanitize_url(test_params["input_url"]) | ||
# check for results | ||
self.assertIsNotNone(sanitized_url) | ||
# Verify results | ||
if test_params["input_url"] == test_params["expected"]: | ||
self.assertEqual( | ||
test_params["input_url"], sanitized_url, | ||
"Input and output URLs were different, should be the same.", | ||
) | ||
else: | ||
self.assertNotEqual( | ||
test_params["input_url"], sanitized_url, | ||
"Input and output URLs were the same, should be different.", | ||
) | ||
self.assertEqual(sanitized_url, test_params["expected"]) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.