示例#1
0
def test_report_with_auth_on(setup):
    """Test that we can still work with github-auth-report."""
    with patch('webcompat.issues.github.post') as json_resp:
        json_resp.return_value = {'number': 2}
        json_data = report_issue(FORM_AUTH, proxy=False)
        assert type(json_data) is dict
        assert json_data.get('number') == 2
示例#2
0
def test_report_issue_fails_400_for_proxy(setup):
    """Test github-proxy-report fails with a 400."""
    with patch('webcompat.issues.proxy_request') as github_data:
        github_data.return_value = mock_api_response({
            'status_code': 400,
            'content': '[{"number":2}]',
        })
        with pytest.raises(BadRequest):
            rv = report_issue(FORM_ANON, proxy=True)
示例#3
0
def file_issue():
    """File an issue on behalf of the user that just gave us authorization."""
    form_data = session.get('form', None)
    if not session:
        abort(401)
    if session and (form_data is None):
        abort(403)
    json_response = report_issue(session['form'])
    # Get rid of stashed form data
    session.pop('form', None)
    session['show_thanks'] = True
    return redirect(url_for('show_issue', number=json_response.get('number')))
示例#4
0
def test_report_issue_returns_number(setup):
    """Test issue posting report the right json."""
    with patch('webcompat.issues.proxy_request') as github_data:
        github_data.return_value = mock_api_response({
            'status_code': 201,
            'content': '[{"number":2}]',
        })
        with patch('webcompat.issues.report_private_issue') as silent:
            # We avoid making a call to report_private_issue
            silent.return_value = None
            json_data = report_issue(FORM_ANON, proxy=True)
            assert type(json_data) is dict
            assert json_data.get('number') == 2
示例#5
0
 def test_report_issue_returns_number(self, mockpost):
     """Test we can expect an issue number back."""
     mockpost.return_value.status_code = 201
     mockpost.return_value.json.return_value = {'number': 2}
     form = MultiDict([
         ('browser', 'Firefox 99.0'),
         ('description', 'sup'),
         ('details', ''),
         ('os', 'Mac OS X 13'),
         ('problem_category', 'unknown_bug'),
         ('submit_type', 'github-proxy-report'),
         ('url', 'http://3139.example.com'),
         ('username', ''),
     ])
     rv = report_issue(form, True)
     self.assertEquals(rv.get('number'), 2)
示例#6
0
def create_issue():
    """Create a new issue or prefill a form for submission.

    * HTTP GET with (optional) parameters
      * create a form with prefilled data.
      * parameters:
        * url: URL of the Web site
        * src: source of the request (web, addon, etc.)
        * label: controled list of labels
    * HTTP POST with a JSON payload
      * create a form with prefilled data
      * content-type is application/json
      * json may include:
        * title
        * User agent string
        * OS identification
        * labels list
        * type of bugs
        * short summary
        * full description
        * tested in another browser
        * body
        * utm_ params for Google Analytics
    * HTTP POST with an attached form
      * submit a form to GitHub to create a new issue
      * form submit type:
        * authenticated: Github authentification
        * anonymous: handled by webcompat-bot

    Any deceptive requests will be ended as a 400.
    See https://tools.ietf.org/html/rfc7231#section-6.5.1
    """
    push('/css/dist/webcompat.min.css', **{
        'as': 'style',
        'rel': 'preload'
    })
    push(bust_cache('/js/dist/webcompat.min.js'), **{
        'as': 'script',
        'rel': 'preload'
    })
    # Starting a logger
    log = app.logger
    log.setLevel(logging.INFO)
    if g.user:
        get_user_info()
    # We define which type of requests we are dealing with.
    request_type = form_type(request)
    # Form Prefill section
    if request_type == 'prefill':
        form_data = prepare_form(request)

        if ab_active('exp') == 'form-v2':
            bug_form = get_form(form_data, form=FormWizard)
            # TODO: remove this when the experiment has ended
            form_data['extra_labels'].append('form-v2-experiment')
        else:
            bug_form = get_form(form_data)

        session['extra_labels'] = form_data['extra_labels']
        source = form_data.pop('utm_source', None)
        campaign = form_data.pop('utm_campaign', None)
        return render_template('new-issue.html', form=bug_form, source=source,
                               campaign=campaign, nonce=request.nonce)
    # Issue Creation section
    elif request_type == 'create':
        # Check if there is a form
        if not request.form:
            log.info('POST request without form.')
            abort(400)
        # Adding parameters to the form
        form = request.form.copy()
        extra_labels = session.pop('extra_labels', None)
        if extra_labels:
            form['extra_labels'] = extra_labels
        # Logging the ip and url for investigation
        log.info('{ip} {url}'.format(
            ip=request.remote_addr,
            url=form['url'].encode('utf-8')))
        # Check if the form is valid
        if not is_valid_issue_form(form):
            log.info('Invalid issue form request')
            abort(400)
        if form.get('submit_type') == PROXY_REPORT:
            # Checking blacklisted domains
            domain = urllib.parse.urlsplit(form['url']).hostname
            if is_blacklisted_domain(domain):
                msg = app.config['IS_BLACKLISTED_DOMAIN'].format(form['url'])
                flash(msg, 'notimeout')
                return redirect(url_for('index'))
            # Anonymous reporting
            json_response = report_issue(form, proxy=True)
            session['show_thanks'] = True
            return redirect(
                url_for('show_issue', number=json_response.get('number')))
        # Authenticated reporting
        if form.get('submit_type') == AUTH_REPORT:
            if g.user:  # If you're already authed, submit the bug.
                json_response = report_issue(form)
                session['show_thanks'] = True
                return redirect(url_for('show_issue',
                                        number=json_response.get('number')))
            else:
                # Stash form data into session, go do GitHub auth
                session['form'] = form
                return redirect(url_for('login'))
    else:
        log.info('No idea. Abort from /issues/new')
        abort(400)
示例#7
0
def test_report_issue_fails_400_for_unknown_type(setup):
    """Test request fails with a 400 because type unknown."""
    with pytest.raises(BadRequest):
        rv = report_issue(FORM, proxy=True)