~ubuntu-branches/ubuntu/trusty/jockey/trusty

« back to all changes in this revision

Viewing changes to tests/detection.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-03-08 16:08:06 UTC
  • mfrom: (2.1.31 upstream)
  • Revision ID: james.westby@ubuntu.com-20110308160806-udbldxcrfk734zsi
Tags: 0.9.2-0ubuntu1
* New upstream bug fix release:
  - Add X.org video driver ABI checking. (This was already cherrypicked
    in an earlier upload)
  - Drop our own verified_https.py and implement GPG fingerprint SSL
    checking with pycurl, which gets along with proxies. (LP: #729185)
  - Some code cleanup and more test cases.
* debian/control: Add python-pycurl dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from jockey.detection import HardwareID
26
26
from jockey.oslib import OSLib
27
27
 
28
 
import sandbox
 
28
import sandbox, http
29
29
 
30
30
class DetectionTest(sandbox.LogTestCase):
31
31
    def tearDown(self):
854
854
        drv = db.query(prn)
855
855
        self.assertEqual(len(drv), 0)
856
856
 
 
857
class GPGFingerPrintTest(sandbox.LogTestCase):
 
858
    def setUp(self):
 
859
        self.data_dir = os.path.join(os.path.dirname(__file__), 'data')
 
860
        self.localhost_pem = os.path.join(self.data_dir, 'localhost.pem')
 
861
        self.localhost_expired_pem = os.path.join(self.data_dir, 'localhost-expired.pem')
 
862
        self.orig_cert_file_paths = OSLib.inst.ssl_cert_file_paths
 
863
        OSLib.inst.ssl_cert_file_paths = [self.localhost_pem]
 
864
 
 
865
    def tearDown(self):
 
866
        http.stop()
 
867
        OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths
 
868
 
 
869
    def test_valid(self):
 
870
        '''GPG fingerprint: valid certificate, hostname, and fingerprint'''
 
871
 
 
872
        http.start(4443, self.data_dir, True, self.localhost_pem)
 
873
 
 
874
        result = jockey.detection.download_gpg_fingerprint(
 
875
                'https://localhost:4443/fingerprint')
 
876
        self.assertEqual(result, '0000 1111 2222 3333 4444  5555 6666 7777 8888 9999')
 
877
 
 
878
    def test_bad_fingerprint_syntax(self):
 
879
        '''GPG fingerprint: no fingerprint found'''
 
880
 
 
881
        http.start(4443, self.data_dir, True, self.localhost_pem)
 
882
 
 
883
        result = jockey.detection.download_gpg_fingerprint(
 
884
                'https://localhost:4443/bad_fingerprint')
 
885
        self.assertEqual(result, None, result)
 
886
 
 
887
    def test_404(self):
 
888
        '''GPG fingerprint: nonexisting address'''
 
889
 
 
890
        http.start(4443, self.data_dir, True, self.localhost_pem)
 
891
 
 
892
        result = jockey.detection.download_gpg_fingerprint(
 
893
                'https://localhost:4443/nonexisting')
 
894
        self.assertEqual(result, None, result)
 
895
 
 
896
    def test_wrong_host(self):
 
897
        '''GPG fingerprint: unknown hostname'''
 
898
 
 
899
        http.start(4443, self.data_dir, True, self.localhost_pem)
 
900
 
 
901
        result = jockey.detection.download_gpg_fingerprint(
 
902
                'https://127.0.0.1:4443/fingerprint')
 
903
        self.assertEqual(result, None, result)
 
904
 
 
905
    def test_expired_cert(self):
 
906
        '''expired certificate'''
 
907
 
 
908
        http.start(4443, self.data_dir, True, self.localhost_expired_pem)
 
909
 
 
910
        result = jockey.detection.download_gpg_fingerprint(
 
911
                'https://127.0.0.1:4443/fingerprint')
 
912
        self.assertEqual(result, None, result)
 
913
 
 
914
    def test_wrong_cert(self):
 
915
        '''wrong certificate'''
 
916
 
 
917
        OSLib.inst.ssl_cert_file_paths = [self.localhost_expired_pem]
 
918
        http.start(4443, '.', True, self.localhost_pem)
 
919
        result = jockey.detection.download_gpg_fingerprint(
 
920
                'https://127.0.0.1:4443/fingerprint')
 
921
        self.assertEqual(result, None, result)
 
922
 
 
923
    def test_system_cert(self):
 
924
        '''system-wide trusted certificate shouldn't match local test server'''
 
925
 
 
926
        if not self.orig_cert_file_paths:
 
927
            print '[SKIP, not available]'
 
928
            return
 
929
 
 
930
        OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths
 
931
        http.start(4443, '.', True, self.localhost_pem)
 
932
 
 
933
        result = jockey.detection.download_gpg_fingerprint(
 
934
                'https://127.0.0.1:4443/fingerprint')
 
935
        self.assertEqual(result, None, result)
 
936
 
857
937
if __name__ == '__main__':
858
938
    OSLib.inst = sandbox.TestOSLib()
859
939
    unittest.main()