Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
test: add coverage for new is_onion_available function
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Sep 2, 2020
1 parent 0690073 commit 0e417c7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Empty file.
67 changes: 67 additions & 0 deletions sites/management/commands/tests/test_scan.py
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)

0 comments on commit 0e417c7

Please sign in to comment.