This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add coverage for new is_onion_available function
- Loading branch information
1 parent
0690073
commit 0e417c7
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from sites.management.commands.scan import is_onion_available | ||
from django.test import TestCase | ||
|
||
|
||
class TestScan(TestCase): | ||
def test_invalid_onion_available_over_http(self): | ||
"""Simulates a HTTP site with the onion location header, | ||
which is invalid: Onion-Location is ignored if not served | ||
over HTTPS | ||
""" | ||
http_onion_available_pshtt = { | ||
"endpoints": { | ||
"http": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
"https": {"headers": {}}, | ||
"httpswww": {"headers": {}}, | ||
"httpwww": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
} | ||
} | ||
assert not is_onion_available(http_onion_available_pshtt) | ||
|
||
def test_onion_available_over_https(self): | ||
"""Simulates a HTTPS site with the onion location header""" | ||
https_onion_available_pshtt = { | ||
"endpoints": { | ||
"http": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
"https": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
"httpswww": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
"httpwww": { | ||
"headers": { | ||
"onion-location": "https://www.foobar.onion/", | ||
}, | ||
}, | ||
} | ||
} | ||
assert is_onion_available(https_onion_available_pshtt) | ||
|
||
def test_no_onion_available_over_https(self): | ||
"""Simulates a HTTPS site without the Onion-Location header""" | ||
https_onion_not_available_pshtt = { | ||
"endpoints": { | ||
"http": {"headers": {}}, | ||
"https": {"headers": {}}, | ||
"httpswww": {"headers": {}}, | ||
"httpwww": {"headers": {}}, | ||
} | ||
} | ||
assert not is_onion_available(https_onion_not_available_pshtt) |