Package FuzzManager :: Package Collector :: Module tests
[hide private]
[frames] | no frames]

Source Code for Module FuzzManager.Collector.tests

  1  ''' 
  2  Tests 
  3   
  4  @author:     Christian Holler (:decoder) 
  5   
  6  @license: 
  7   
  8  This Source Code Form is subject to the terms of the Mozilla Public 
  9  License, v. 2.0. If a copy of the MPL was not distributed with this 
 10  file, You can obtain one at http://mozilla.org/MPL/2.0/. 
 11   
 12  @contact:    choller@mozilla.com 
 13  ''' 
 14  import unittest 
 15  import requests 
 16  import tempfile 
 17  import os 
 18   
 19  from requests.exceptions import ConnectionError 
 20  from Collector import Collector 
 21  import shutil 
 22  from FTB.Signatures.CrashInfo import CrashInfo 
 23  from FTB.ProgramConfiguration import ProgramConfiguration 
 24  from FTB.Signatures.CrashSignature import CrashSignature 
 25   
 26  # Server and credentials (user/password) used for testing 
 27  testServerURL = "http://127.0.0.1:8000/rest/" 
 28  testAuthCreds = ("admin", "admin") 
 29   
 30  # Check if we have a remote server for testing, if not, skip tests 
 31  haveServer = True 
 32  try: 
 33      requests.get(testServerURL) 
 34  except ConnectionError, e: 
 35      haveServer = False 
 36       
 37  asanTraceCrash = """ 
 38  ASAN:SIGSEGV 
 39  ================================================================= 
 40  ==5854==ERROR: AddressSanitizer: SEGV on unknown address 0x00000014 (pc 0x0810845f sp 0xffc57860 bp 0xffc57f18 T0) 
 41      #0 0x810845e in js::AbstractFramePtr::asRematerializedFrame() const /srv/repos/mozilla-central/js/src/shell/../jit/RematerializedFrame.h:114 
 42      #1 0x810845e in js::AbstractFramePtr::script() const /srv/repos/mozilla-central/js/src/shell/../vm/Stack-inl.h:572 
 43      #2 0x810845e in EvalInFrame(JSContext*, unsigned int, JS::Value*) /srv/repos/mozilla-central/js/src/shell/js.cpp:2655 
 44      #3 0x93f5b92 in js::CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), JS::CallArgs const&) /srv/repos/mozilla-central/js/src/jscntxtinlines.h:231 
 45      #4 0x93f5b92 in js::Invoke(JSContext*, JS::CallArgs, js::MaybeConstruct) /srv/repos/mozilla-central/js/src/vm/Interpreter.cpp:484 
 46      #5 0x9346ba7 in js::Invoke(JSContext*, JS::Value const&, JS::Value const&, unsigned int, JS::Value const*, JS::MutableHandle<JS::Value>) /srv/repos/mozilla-central/js/src/vm/Interpreter.cpp:540 
 47      #6 0x8702baa in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICCall_Fallback*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /srv/repos/mozilla-central/js/src/jit/BaselineIC.cpp:8638 
 48   
 49  AddressSanitizer can not provide additional info. 
 50  SUMMARY: AddressSanitizer: SEGV /srv/repos/mozilla-central/js/src/shell/../jit/RematerializedFrame.h:114 js::AbstractFramePtr::asRematerializedFrame() const 
 51  ==5854==ABORTING 
 52  """ 
 53   
 54  exampleTestCase = '''function init() { 
 55      while ( {}, this) !(Object === "Infinity");       
 56  } 
 57  eval("init()"); 
 58  ''' 
59 60 @unittest.skipIf(not haveServer, reason="No remote server available for testing") 61 -class TestCollectorSubmit(unittest.TestCase):
62 - def setUp(self):
63 self.url = testServerURL + "crashes/" 64 self.tmpCacheDir = tempfile.mkdtemp(prefix="collector-tmp-")
65
66 - def tearDown(self):
67 shutil.rmtree(self.tmpCacheDir)
68
69 - def getRemoteCrashEntryCount(self):
70 response = requests.get(self.url, auth=testAuthCreds) 71 return len(response.json())
72
73 - def runTest(self):
74 collector = Collector(self.tmpCacheDir, 75 serverHost='127.0.0.1', 76 serverPort='8000', 77 serverProtocol='http', 78 serverUser=testAuthCreds[0], 79 serverPass=testAuthCreds[1], 80 clientId='test-fuzzer1') 81 82 config = ProgramConfiguration("mozilla-central", "x86-64", "linux", version="ba0bc4f26681") 83 crashInfo = CrashInfo.fromRawCrashData([], asanTraceCrash.splitlines(), config) 84 85 # TODO: This is only a rudimentary check to see if we submitted *something*. 86 # We should check more precisely that the information submitted is correct. 87 issueCount = self.getRemoteCrashEntryCount() 88 collector.submit(crashInfo, exampleTestCase) 89 self.assertEqual(self.getRemoteCrashEntryCount(), issueCount + 1)
90
91 @unittest.skipIf(not haveServer, reason="No remote server available for testing") 92 -class TestCollectorRefresh(unittest.TestCase):
93 - def setUp(self):
94 self.tmpCacheDir = tempfile.mkdtemp(prefix="collector-tmp-")
95
96 - def tearDown(self):
97 shutil.rmtree(self.tmpCacheDir)
98
99 - def runTest(self):
100 collector = Collector(self.tmpCacheDir, 101 serverHost='127.0.0.1', 102 serverPort='8000', 103 serverProtocol='http', 104 serverUser=testAuthCreds[0], 105 serverPass=testAuthCreds[1], 106 clientId='test-fuzzer1') 107 108 collector.refresh() 109 110 receivedSignatures = False 111 112 for sigFile in os.listdir(self.tmpCacheDir): 113 receivedSignatures = True 114 CrashSignature.fromFile(os.path.join(self.tmpCacheDir, sigFile)) 115 116 if not receivedSignatures: 117 self.skipTest("Server did not provide signatures")
118 119 120 if __name__ == "__main__": 121 unittest.main() 122