def MakeWorkingFile(file_data): """Fills in arguments to make a basic working file. Used for ensuring that the basic template is standards-compliant. """ file_data = file_data.decode('utf-8') file_data = FillInParameter('ARRAY_OF_RANDOM_ROLLS', _ArrayOfRandomRolls(500), file_data) file_data = FillInParameter('REQUEST_AUDIO_AND_VIDEO', '{ video: true, audio: true }', file_data) file_data = FillInParameter('TRANSFORM_OFFER_SDP', _ReturnFirstArgument(), file_data) file_data = FillInParameter('TRANSFORM_ANSWER_SDP', _ReturnFirstArgument(), file_data) return file_data
def Fuzz(template): """Generates a single random HTML page which tries to mess with getUserMedia. We require a template which has certain placeholders defined in it (such as FUZZ_USER_MEDIA_INPUT). We then replace these placeholders with random identifiers and data in certain patterns. For instance, since the getUserMedia function accepts an object, we try to pass in everything from {video:true, audio:false} (which is a correct value) to {sdjkjsjh34sd:455, video:'yxuhsd'} and other strange things. See the template at corpus/template.html for an example of how a template looks like. """ random.seed() attributes = RandomJavascriptAttributes(random.randint(0, 10)) if (random.random() < 0.8): attributes.append('video: %s' % RandomJavascriptValue()) if (random.random() < 0.8): attributes.append('audio: %s' % RandomJavascriptValue()) input_object = MakeJavascriptObject(attributes) template = FillInParameter('FUZZ_USER_MEDIA_INPUT', input_object, template) ok_callback = (RandomJavascriptValue() if random.random() < 0.5 else 'getUserMediaOkCallback') template = FillInParameter('FUZZ_OK_CALLBACK', ok_callback, template) fail_callback = (RandomJavascriptValue() if random.random() < 0.5 else 'getUserMediaFailedCallback') template = FillInParameter('FUZZ_FAIL_CALLBACK', fail_callback, template) before_call = 'location.reload();' if random.random() < 0.1 else '' template = FillInParameter('BEFORE_GET_USER_MEDIA_CALL', before_call, template) after_call = 'location.reload();' if random.random() < 0.3 else '' template = FillInParameter('AFTER_GET_USER_MEDIA_CALL', after_call, template) return template
def Fuzz(file_data): """Fuzzes the passed in template.""" file_data = file_data.decode('utf-8') # Generate a bunch of random numbers and encode them into the page. Since the # values get hard-coded into the page the page's choices will be reproducible. file_data = FillInParameter('ARRAY_OF_RANDOM_ROLLS', _ArrayOfRandomRolls(500), file_data) # Randomly decide how to fuzz SDP data. file_data = FillInParameter('REQUEST_AUDIO_AND_VIDEO', _RandomAudioOrVideo(), file_data) file_data = FillInParameter('TRANSFORM_OFFER_SDP', _RandomSdpTransform(), file_data) file_data = FillInParameter('TRANSFORM_ANSWER_SDP', _RandomSdpTransform(), file_data) # Random location.reload() calls in the call sequence can be challenging for # the code to deal with, so insert some here and there. if random.random() < 0.3: file_data = _InsertRandomLocationReloadsWithinMarkers(file_data) return file_data
def _IncludeJsFile(js_include_to_replace, js_path, file_data): js_file_data = _ReadFile(js_path) js_file_data = _Indent(js_file_data, 4) js_file_data = (' <script type="text/javascript">\n' + js_file_data + '\n </script>\n') return FillInParameter(js_include_to_replace, js_file_data, file_data)