本文整理汇总了Python中test.mocking.get_directory_authority函数的典型用法代码示例。如果您正苦于以下问题:Python get_directory_authority函数的具体用法?Python get_directory_authority怎么用?Python get_directory_authority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_directory_authority函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_legacy_dir_key
def test_legacy_dir_key(self):
"""
Includes a 'legacy-dir-key' line with both valid and invalid content.
"""
test_value = '65968CCB6BECB5AA88459C5A072624C6995B6B72'
authority = get_directory_authority({'legacy-dir-key': test_value}, is_vote = True)
self.assertEqual(test_value, authority.legacy_dir_key)
# check that we'll fail if legacy-dir-key appears in a consensus
content = get_directory_authority({'legacy-dir-key': test_value}, content = True)
self.assertRaises(ValueError, DirectoryAuthority, content, True)
test_values = (
'',
'zzzzz',
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
)
for value in test_values:
content = get_directory_authority({'legacy-dir-key': value}, content = True)
self.assertRaises(ValueError, DirectoryAuthority, content, True)
authority = DirectoryAuthority(content, False)
self.assertEqual(None, authority.legacy_dir_key)
示例2: test_with_directory_authorities
def test_with_directory_authorities(self):
"""
Includes a couple directory authorities in the document.
"""
for is_document_vote in (False, True):
for is_authorities_vote in (False, True):
authority1 = get_directory_authority({'contact': 'doctor jekyll'}, is_vote = is_authorities_vote)
authority2 = get_directory_authority({'contact': 'mister hyde'}, is_vote = is_authorities_vote)
vote_status = 'vote' if is_document_vote else 'consensus'
content = get_network_status_document_v3({'vote-status': vote_status}, authorities = (authority1, authority2), content = True)
if is_document_vote == is_authorities_vote:
if is_document_vote:
# votes can only have a single authority
self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
document = NetworkStatusDocumentV3(content, validate = False)
else:
document = NetworkStatusDocumentV3(content)
self.assertEqual((authority1, authority2), document.directory_authorities)
else:
# authority votes in a consensus or consensus authorities in a vote
self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
document = NetworkStatusDocumentV3(content, validate = False)
self.assertEqual((authority1, authority2), document.directory_authorities)
示例3: test_with_legacy_directory_authorities
def test_with_legacy_directory_authorities(self):
"""
Includes both normal authorities and those following the '-legacy' format.
"""
legacy_content = "dir-source gabelmoo-legacy 81349FC1F2DBA2C2C11B45CB9706637D480AB913 212.112.245.170 212.112.245.170 80 443"
authority1 = get_directory_authority({'contact': 'doctor jekyll'}, is_vote = False)
authority2 = DirectoryAuthority(legacy_content, validate = True, is_vote = False)
authority3 = get_directory_authority({'contact': 'mister hyde'}, is_vote = False)
document = get_network_status_document_v3({"vote-status": "consensus"}, authorities = (authority1, authority2, authority3))
self.assertEquals((authority1, authority2, authority3), document.directory_authorities)
示例4: test_blank_lines
def test_blank_lines(self):
"""
Includes blank lines, which should be ignored.
"""
authority = get_directory_authority({'dir-source': AUTHORITY_HEADER[0][1] + '\n\n\n'})
self.assertEqual('Mike Perry <email>', authority.contact)
示例5: test_footer_consensus_method_requirement
def test_footer_consensus_method_requirement(self):
"""
Check that validation will notice if a footer appears before it was
introduced.
"""
content = get_network_status_document_v3({'consensus-method': '8'}, content = True)
self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
document = NetworkStatusDocumentV3(content, False)
self.assertEqual([DOC_SIG], document.signatures)
self.assertEqual([], document.get_unrecognized_lines())
# excludes a footer from a version that shouldn't have it
document = get_network_status_document_v3({'consensus-method': '8'}, ('directory-footer', 'directory-signature'))
self.assertEqual([], document.signatures)
self.assertEqual([], document.get_unrecognized_lines())
# Prior to conensus method 9 votes can still have a signature in their
# footer...
#
# https://trac.torproject.org/7932
document = get_network_status_document_v3(
{
'vote-status': 'vote',
'consensus-methods': '1 8',
},
exclude = ('directory-footer',),
authorities = (get_directory_authority(is_vote = True),)
)
self.assertEqual([DOC_SIG], document.signatures)
self.assertEqual([], document.get_unrecognized_lines())
示例6: test_unrecognized_line
def test_unrecognized_line(self):
"""
Includes unrecognized content in the descriptor.
"""
authority = get_directory_authority({"pepperjack": "is oh so tasty!"})
self.assertEquals(["pepperjack is oh so tasty!"], authority.get_unrecognized_lines())
示例7: test_unrecognized_line
def test_unrecognized_line(self):
"""
Includes unrecognized content in the descriptor.
"""
authority = get_directory_authority({'pepperjack': 'is oh so tasty!'})
self.assertEqual(['pepperjack is oh so tasty!'], authority.get_unrecognized_lines())
示例8: test_malformed_port
def test_malformed_port(self):
"""
Includes a malformed orport or dirport on the 'dir-source' line.
"""
test_values = (
"",
"-1",
"399482",
"blarg",
)
for value in test_values:
for include_or_port in (False, True):
for include_dir_port in (False, True):
if not include_or_port and not include_dir_port:
continue
dir_source = AUTHORITY_HEADER[0][1]
if include_or_port:
dir_source = dir_source.replace('9090', value)
if include_dir_port:
dir_source = dir_source.replace('9030', value)
content = get_directory_authority({"dir-source": dir_source}, content = True)
self.assertRaises(ValueError, DirectoryAuthority, content)
authority = DirectoryAuthority(content, False)
expected_value = 399482 if value == "399482" else None
actual_value = authority.or_port if include_or_port else authority.dir_port
self.assertEqual(expected_value, actual_value)
示例9: test_malformed_port
def test_malformed_port(self):
"""
Includes a malformed orport or dirport on the 'dir-source' line.
"""
test_values = (
'',
'-1',
'399482',
'blarg',
)
for value in test_values:
for include_or_port in (False, True):
for include_dir_port in (False, True):
if not include_or_port and not include_dir_port:
continue
dir_source = AUTHORITY_HEADER[0][1]
if include_or_port:
dir_source = dir_source.replace('9090', value)
if include_dir_port:
dir_source = dir_source.replace('9030', value)
content = get_directory_authority({'dir-source': dir_source}, content = True)
self.assertRaises(ValueError, DirectoryAuthority, content, True)
authority = DirectoryAuthority(content, False)
actual_value = authority.or_port if include_or_port else authority.dir_port
self.assertEqual(None, actual_value)
示例10: test_key_certificate
def test_key_certificate(self):
"""
Includes or exclude a key certificate from the directory entry.
"""
key_cert = get_key_certificate(content = True)
# include a key cert with a consensus
content = get_directory_authority(content = True) + b'\n' + key_cert
self.assertRaises(ValueError, DirectoryAuthority, content, True)
authority = DirectoryAuthority(content, False)
self.assertEqual('turtles', authority.nickname)
# exclude key cert from a vote
content = get_directory_authority(content = True, is_vote = True).replace(b'\n' + key_cert, b'')
self.assertRaises(ValueError, DirectoryAuthority, content, True, True)
authority = DirectoryAuthority(content, False, True)
self.assertEqual('turtles', authority.nickname)
示例11: test_first_line
def test_first_line(self):
"""
Includes a non-mandatory field before the 'dir-source' line.
"""
content = b'ho-hum 567\n' + get_directory_authority(content = True)
self.assertRaises(ValueError, DirectoryAuthority, content, True)
authority = DirectoryAuthority(content, False)
self.assertEqual('turtles', authority.nickname)
self.assertEqual(['ho-hum 567'], authority.get_unrecognized_lines())
示例12: test_duplicate_lines
def test_duplicate_lines(self):
"""
Duplicates linesin the entry.
"""
lines = get_directory_authority(content = True).split(b'\n')
for index, duplicate_line in enumerate(lines):
content = b'\n'.join(lines[:index] + [duplicate_line] + lines[index:])
self.assertRaises(ValueError, DirectoryAuthority, content, True)
authority = DirectoryAuthority(content, False)
self.assertEqual('turtles', authority.nickname)
示例13: test_duplicate_lines
def test_duplicate_lines(self):
"""
Duplicates linesin the entry.
"""
lines = get_directory_authority(content = True).split("\n")
for i in xrange(len(lines)):
content = "\n".join(lines[:i] + [lines[i]] + lines[i:])
self.assertRaises(ValueError, DirectoryAuthority, content)
authority = DirectoryAuthority(content, False)
self.assertEqual("turtles", authority.nickname)
示例14: test_malformed_fingerprint
def test_malformed_fingerprint(self):
"""
Includes a malformed fingerprint on the 'dir-source' line.
"""
test_values = ("", "zzzzz", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")
for value in test_values:
dir_source = AUTHORITY_HEADER[0][1].replace("27B6B5996C426270A5C95488AA5BCEB6BCC86956", value)
content = get_directory_authority({"dir-source": dir_source}, content=True)
self.assertRaises(ValueError, DirectoryAuthority, content)
authority = DirectoryAuthority(content, False)
self.assertEqual(value, authority.fingerprint)
示例15: test_malformed_address
def test_malformed_address(self):
"""
Includes a malformed ip address on the 'dir-source' line.
"""
test_values = ("", "71.35.150.", "71.35..29", "71.35.150", "71.35.150.256", "[fd9f:2e19:3bcf::02:9970]")
for value in test_values:
dir_source = AUTHORITY_HEADER[0][1].replace("76.73.17.194", value)
content = get_directory_authority({"dir-source": dir_source}, content=True)
self.assertRaises(ValueError, DirectoryAuthority, content)
authority = DirectoryAuthority(content, False)
self.assertEqual(value, authority.address)