Exemple #1
0
def test_open_remote_window(logger, version, addr):
    global webapi_results

    results = {}
    for value in ['deny', 'allow']:
        result = False
        webapi_results = None

        appname = 'Open Remote Window Test App'
        installed_appname = appname.lower().replace(" ", "-")
        apppath = os.path.join(static_path, 'open-remote-window-test-app')
        install_app(logger, appname, version, 'web', apppath, False, {
            'results_uri.js':
            'RESULTS_URI="http://%s:%s/webapi_results";' % addr
        })

        set_permission('open-remote-window', value, installed_appname)
        fxos_appgen.launch_app(appname)
        try:
            wait.Wait(timeout=30).until(lambda: webapi_results is not None)
        except wait.TimeoutException:
            results[value] = 'timed out'

        if webapi_results is not None:
            result = webapi_results['open-remote-window']

        # launching here will force the remote window (if any) to be hidden
        # but will not retrigger the test.
        fxos_appgen.launch_app(appname)
        logger.debug('uninstalling: %s' % appname)
        fxos_appgen.uninstall_app(appname)

        results['open-remote-window-' + value] = result

    return results
Exemple #2
0
def runtest(logger, runner, timeout):
    global headers
    global results

    headers = None
    results = None
    runner.start()

    try:
        wait.Wait(timeout=timeout).until(lambda: results is not None)
    except wait.TimeoutException:
        logger.error('timed out waiting for results')

    runner.stop()
    runner.wait()

    if results:
        # extract browser version from user-agent
        user_agent = headers['user-agent']
        version = None
        m = re.search('(Firefox/[\d\.]+|Chrome/[\d\.]+)', user_agent)
        if m:
            version = m.groups()[0].split('/')[1]

        return version, copy.copy(results)
    else:
        return None, None
def test_webapi(logger, report, args, addr):
    errors = False

    logger.debug('Running webapi verifier tests')

    for apptype in ['web', 'privileged', 'certified']:
        global webapi_results

        webapi_results = None

        appname = '%s WebAPI Verifier' % apptype.capitalize()
        sampleapppath = os.path.join(static_path, 'sample_apps')
        apppath = os.path.join(sampleapppath, 'webapi-test-app')
        install_app(
            logger, appname, args.version, apptype, apppath, True, {
                'results_uri.js':
                'RESULTS_URI="http://%s:%s/webapi_results";LOG_URI="http://%s:%s/webapi_log";'
                % (addr * 2)
            }, True)

        try:
            wait.Wait(timeout=120).until(lambda: webapi_results is not None)
        except wait.TimeoutException:
            logger.error('Timed out waiting for results for test: %s' %
                         last_test_started)
            errors = True

        logger.debug('uninstalling: %s' % appname)
        fxos_appgen.uninstall_app(appname)

        if webapi_results is None:
            continue

        if "headers" not in report:
            report["headers"] = headers

        results_folder = 'webapi_ref/'
        results_filename = '%s.json' % apptype
        if args.generate_reference:
            dirname = os.path.dirname(results_folder + results_filename)
            if not os.path.exists(dirname) and dirname <> "":
                os.makedirs(dirname)
            with open(results_folder + results_filename, 'w') as f:
                f.write(json.dumps(webapi_results, sort_keys=True, indent=2))
        else:
            file_path = pkg_resources.resource_filename(
                __name__,
                os.path.sep.join([
                    expected_results_path, 'expected_webapi_results',
                    results_filename
                ]))

            parse_webapi_results(file_path, webapi_results, '%s-' % apptype,
                                 logger, report)

    logger.debug('Done.')
    if errors:
        logger.error('Test webapi with errors')
Exemple #4
0
def test_open_remote_window(logger, version, addr, apptype, all_perms):
    print "Installing the open remote window test app. This will take a minute... "

    result = False

    appname = 'Open Remote Window Test App'
    apppath = os.path.join(static_path, 'open-remote-window-test-app')
    install_app(logger, appname, version, apptype, apppath, all_perms,
        {'results_uri.js':
            'RESULTS_URI="http://%s:%s/webapi_results";' % addr},
            True)

    global webapi_results
    webapi_results = None
    try:
        wait.Wait(timeout=60).until(lambda: webapi_results is not None)
    except wait.TimeoutException:
        logger.error('Timed out waiting for results')
        logger.test_end('permissions', 'ERROR')
        sys.exit(1)

    webapi_results = None

    script = """
        let manager = window.wrappedJSObject.AppWindowManager || window.wrappedJSObject.WindowManager;
        return manager.getRunningApps();
    """

    m = marionette.Marionette()
    m.start_session()
    running_apps = m.execute_script(script)
    for app in running_apps:
        if app.find('Remote Window') != -1:
            result = True
            # window.close() from the remote window doesn't seem to work
            kill_script = """
                let manager = window.wrappedJSObject.AppWindowManager || window.wrappedJSObject.WindowManager;
                manager.kill("%s")""" % app
            m.execute_script(kill_script)

    m.delete_session()

    fxos_appgen.uninstall_app(appname)

    return result
Exemple #5
0
def test_permissions(logger, report, args, addr):
    errors = False

    #logger.test_start('permissions')
    logger.debug('Running permissions tests')

    permissions = get_permissions()

    # test default permissions
    for apptype in ['web', 'privileged', 'certified']:
        logger.debug('Testing default permissions: %s' % apptype)
        results = {}
        expected_webapi_results = None

        appname = 'Default Permissions Test App'
        fxos_appgen.uninstall_app(appname)
        installed_appname = appname.lower().replace(" ", "-")
        fxos_appgen.generate_app(appname,
                                 install=True,
                                 app_type=apptype,
                                 all_perm=True)

        for permission in permissions:
            result = get_permission(permission, installed_appname)
            results[permission] = result

        results_filename = '%s.json' % apptype
        if args.generate_reference:
            with open(results_filename, 'w') as f:
                f.write(json.dumps(results, sort_keys=True, indent=2))
        else:
            file_path = pkg_resources.resource_filename(
                __name__,
                os.path.sep.join([
                    expected_results_path, 'expected_permissions_results',
                    results_filename
                ]))
            parse_permissions_results(file_path, results, '%s-' % apptype,
                                      logger, report)

        fxos_appgen.uninstall_app(appname)

    # test individual permissions
    logger.debug('Testing individual permissions')
    results = {}

    # first install test app for embed-apps permission test
    embed_appname = 'Embed Apps Test App'
    apppath = os.path.join(static_path, 'embed-apps-test-app')
    install_app(
        logger, embed_appname, args.version, 'certified', apppath, True, {
            'results_uri.js':
            'RESULTS_URI="http://%s:%s/webapi_results_embed_apps";' % addr
        }, False)

    appname = 'Permissions Test App'
    installed_appname = appname.lower().replace(" ", "-")
    apppath = os.path.join(static_path, 'permissions-test-app')
    install_app(
        logger, appname, args.version, 'web', apppath, False, {
            'results_uri.js':
            'RESULTS_URI="http://%s:%s/webapi_results";LOG_URI="http://%s:%s/webapi_log";'
            % (addr * 2)
        })

    for permission in [None] + permissions:
        global webapi_results
        global webapi_results_embed_app
        webapi_results = None
        webapi_results_embed_app = None

        # if we try to launch after killing too quickly, the app seems
        # to not fully launch
        time.sleep(5)

        if permission is not None:
            logger.debug('testing permission: %s' % permission)
            set_permission(permission, u'allow', installed_appname)
        else:
            logger.debug('testing permission: None')
        fxos_appgen.launch_app(appname)

        try:
            wait.Wait(timeout=60).until(lambda: webapi_results is not None)

            # embed-apps results are posted to a separate URL
            if webapi_results_embed_app:
                webapi_results['embed-apps'] = webapi_results_embed_app[
                    'embed-apps']
            else:
                webapi_results['embed-apps'] = False

            if permission is None:
                expected_webapi_results = webapi_results
            else:
                results[permission] = diff_results(expected_webapi_results,
                                                   webapi_results)
        except wait.TimeoutException:
            logger.error('Timed out waiting for results')
            errors = True
            if permission is not None:
                results[permission] = 'timed out'
            else:
                # If we timeout on our baseline results there is
                # no point in proceeding.
                logger.error(
                    'Could not get baseline results for permissions. Skipping tests.'
                )
                break

        kill('app://' + installed_appname)
        if permission is not None:
            set_permission(permission, u'deny', installed_appname)

    logger.debug('uninstalling: %s' % appname)
    fxos_appgen.uninstall_app(appname)

    # we test open-remote-window separately as opening a remote
    # window might stop the test app
    results['open-remote-window'] = test_open_remote_window(
        logger, args.version, addr)

    results_filename = 'permissions.json'
    if args.generate_reference:
        with open(results_filename, 'w') as f:
            f.write(json.dumps(results, sort_keys=True, indent=2))
    else:
        file_path = pkg_resources.resource_filename(
            __name__,
            os.path.sep.join([
                expected_results_path, 'expected_permissions_results',
                results_filename
            ]))
        parse_permissions_results(file_path, results, 'individual-', logger,
                                  report)

    logger.debug('Done.')
    if errors:
        logger.error('Test individual with errors')

    # clean up embed-apps test app
    logger.debug('uninstalling: %s' % embed_appname)
    fxos_appgen.uninstall_app(embed_appname)
Exemple #6
0
        logger.debug('Running webapi verifier tests')

        for apptype in ['web', 'privileged', 'certified']:
            global webapi_results

            webapi_results = None

            appname = '%s WebAPI Verifier' % apptype.capitalize()
            apppath = os.path.join(static_path, 'webapi-test-app')
            install_app(logger, appname, args.version, apptype, apppath, True,
                        {'results_uri.js':
                            'RESULTS_URI="http://%s:%s/webapi_results";' % addr},
                        True)

            try:
                wait.Wait(timeout=120).until(lambda: webapi_results is not None)
            except wait.TimeoutException:
                logger.error('Timed out waiting for results')
                errors = True

            fxos_appgen.uninstall_app(appname)

            if webapi_results is None:
                continue

            if "headers" not in report:
                report["headers"] = headers
                test_user_agent(headers['user-agent'], logger)

            results_filename = '%s.%s.json' % (args.version, apptype)
            if args.generate_reference: