2015-04-02 20:33:06 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2017-11-30 18:33:11 +00:00
|
|
|
# Copyright 2015 - 2017, New York University and the TUF contributors
|
|
|
|
|
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
|
2015-04-02 20:33:06 +00:00
|
|
|
"""
|
|
|
|
|
<Program Name>
|
|
|
|
|
test_init.py
|
|
|
|
|
|
2017-01-11 16:43:19 +00:00
|
|
|
<Author>
|
2015-04-02 20:33:06 +00:00
|
|
|
Vladimir Diaz
|
|
|
|
|
|
|
|
|
|
<Started>
|
2017-01-11 16:43:19 +00:00
|
|
|
March 30, 2015.
|
2015-04-02 20:33:06 +00:00
|
|
|
|
|
|
|
|
<Copyright>
|
2018-02-05 16:31:19 +00:00
|
|
|
See LICENSE-MIT OR LICENSE for licensing information.
|
2015-04-02 20:33:06 +00:00
|
|
|
|
|
|
|
|
<Purpose>
|
|
|
|
|
Test cases for __init__.py (mainly the exceptions defined there).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Help with Python 3 compatibility, where the print statement is a function, an
|
|
|
|
|
# implicit relative import is invalid, and the '/' operator performs true
|
|
|
|
|
# division. Example: print 'hello world' raises a 'SyntaxError' exception.
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
from __future__ import division
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
import tuf
|
2017-01-11 16:43:19 +00:00
|
|
|
import tuf.exceptions
|
2016-01-20 15:29:58 +00:00
|
|
|
import tuf.log
|
2015-04-02 20:33:06 +00:00
|
|
|
|
2017-01-11 16:43:19 +00:00
|
|
|
import securesystemslib
|
|
|
|
|
|
2020-03-02 20:43:43 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2015-04-02 20:33:06 +00:00
|
|
|
|
|
|
|
|
class TestInit(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2016-07-25 15:20:30 +00:00
|
|
|
def tearDown(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2015-04-02 20:33:06 +00:00
|
|
|
def test_bad_signature_error(self):
|
2017-01-11 16:43:19 +00:00
|
|
|
bad_signature_error = securesystemslib.exceptions.BadSignatureError('bad_role')
|
2015-04-02 20:33:06 +00:00
|
|
|
logger.error(bad_signature_error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_slow_retrieval_error(self):
|
2017-01-11 16:43:19 +00:00
|
|
|
slow_signature_error = tuf.exceptions.SlowRetrievalError('bad_role')
|
2015-04-02 20:33:06 +00:00
|
|
|
logger.error(slow_signature_error)
|
|
|
|
|
|
2016-07-21 14:28:46 +00:00
|
|
|
|
|
|
|
|
def test_bad_hash_error(self):
|
2017-01-11 16:43:19 +00:00
|
|
|
bad_hash_error = securesystemslib.exceptions.BadHashError('01234', '56789')
|
2016-07-21 14:28:46 +00:00
|
|
|
logger.error(bad_hash_error)
|
|
|
|
|
|
2016-07-25 15:20:30 +00:00
|
|
|
|
|
|
|
|
def test_invalid_metadata_json_error(self):
|
2017-01-11 16:43:19 +00:00
|
|
|
format_error = securesystemslib.exceptions.FormatError('Improperly formatted JSON')
|
|
|
|
|
invalid_metadata_json_error = tuf.exceptions.InvalidMetadataJSONError(format_error)
|
2016-07-25 15:20:30 +00:00
|
|
|
logger.error(invalid_metadata_json_error)
|
|
|
|
|
|
2017-01-11 16:43:19 +00:00
|
|
|
|
|
|
|
|
|
2015-04-02 20:33:06 +00:00
|
|
|
# Run the unit tests.
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|