-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #2479 - Refactors the form to be more testable #2528
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
286d2fe
Issue #2479 - Adds checker for form parameters
karlcow 5339d38
Issue #2479 - Makes the logging more flexible
karlcow b0febe6
Issue #2479 - Adds helpers for blacklisted domains
karlcow bbb3b60
Issue #2479 - Adds checks for submit values
karlcow 3748ac5
Issue #2479 - Adds test for HTTP POST on /issues/new
karlcow 6455daa
Issue #2479 - Fixes syntax kerfuffles
karlcow 02065ef
Issue #2479 - Makes report_issue uniform
karlcow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
from helpers import get_milestone_list | ||
from helpers import get_referer | ||
from helpers import get_user_info | ||
from helpers import is_blacklisted_domain | ||
from helpers import is_valid_issue_form | ||
from helpers import set_referer | ||
from issues import report_issue | ||
from webcompat import app | ||
|
@@ -169,9 +171,16 @@ def show_issues(): | |
def create_issue(): | ||
"""Create a new issue. | ||
|
||
GET will return an HTML response for reporting issues | ||
POST will create a new issue | ||
GET will return an HTML response for reporting issues. | ||
POST will create a new issue. | ||
|
||
Any deceptive requests will be ended as a 400. | ||
See https://tools.ietf.org/html/rfc7231#section-6.5.1 | ||
""" | ||
# Starting a logger | ||
log = app.logger | ||
log.setLevel(logging.INFO) | ||
# GET Requests | ||
if request.method == 'GET': | ||
bug_form = get_form(request.headers.get('User-Agent')) | ||
if g.user: | ||
|
@@ -186,40 +195,32 @@ def create_issue(): | |
if request.args.get('label'): | ||
session['label'] = request.args.getlist('label') | ||
return render_template('new-issue.html', form=bug_form) | ||
# copy the form so we can add the full UA string to it. | ||
# POST Requests | ||
if request.form: | ||
# Copy the form to add the full UA string. | ||
form = request.form.copy() | ||
# To be legit the form needs a couple of parameters | ||
# if one essential is missing, it's a bad request | ||
must_parameters = set(['url', 'problem_category', 'description', | ||
'os', 'browser', | ||
'username', 'submit_type']) | ||
if not must_parameters.issubset(form.keys()): | ||
if not is_valid_issue_form(form): | ||
abort(400) | ||
else: | ||
# https://tools.ietf.org/html/rfc7231#section-6.5.1 | ||
log.info('POST request without form.') | ||
abort(400) | ||
# see https://github.com/webcompat/webcompat.com/issues/1141 | ||
# see https://github.com/webcompat/webcompat.com/issues/1237 | ||
# see https://github.com/webcompat/webcompat.com/issues/1627 | ||
spamlist = ['qiangpiaoruanjian', 'cityweb.de', 'coco.fr'] | ||
for spam in spamlist: | ||
if spam in form.get('url'): | ||
msg = (u'Anonymous reporting for domain {0} ' | ||
'is temporarily disabled. Please contact ' | ||
'[email protected] ' | ||
'for more details.').format(spam) | ||
flash(msg, 'notimeout') | ||
return redirect(url_for('index')) | ||
# Logging the ip and url for investigation | ||
log.info('{ip} {url}'.format( | ||
ip=request.remote_addr, | ||
url=form['url'].encode('utf-8')) | ||
) | ||
# Checking blacklisted domains | ||
if is_blacklisted_domain(form['url']): | ||
msg = (u'Anonymous reporting for domain {0} ' | ||
'is temporarily disabled. Please contact ' | ||
'[email protected] ' | ||
'for more details.').format(form['url']) | ||
flash(msg, 'notimeout') | ||
return redirect(url_for('index')) | ||
form['ua_header'] = request.headers.get('User-Agent') | ||
form['reported_with'] = session.pop('src', 'web') | ||
# Reminder: label is a list, if it exists | ||
form['extra_labels'] = session.pop('label', None) | ||
# Logging the ip and url for investigation | ||
log = app.logger | ||
log.setLevel(logging.INFO) | ||
log.info('{ip} {url}'.format(ip=request.remote_addr, | ||
url=form['url'].encode('utf-8'))) | ||
# form submission for 3 scenarios: authed, to be authed, anonymous | ||
if form.get('submit_type') == AUTH_REPORT: | ||
if g.user: # If you're already authed, submit the bug. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.