diff --git a/grunt-tasks/concat.js b/grunt-tasks/concat.js index 160d8f207..708db847e 100644 --- a/grunt-tasks/concat.js +++ b/grunt-tasks/concat.js @@ -15,8 +15,7 @@ module.exports = function(grunt) { '<%= jsPath %>/vendor/mousetrap-min.js', '<%= jsPath %>/vendor/backbone.mousetrap.js', '<%= jsPath %>/lib/homepage.js', - '<%= jsPath %>/lib/bugform.js', - '<%= jsPath %>/lib/shared.js' + '<%= jsPath %>/lib/bugform.js' ], dest: '<%= jsPath %>/<%= pkg.name %>.js' }, diff --git a/grunt-tasks/jshint.js b/grunt-tasks/jshint.js index 2936bb1d8..91b2cff32 100644 --- a/grunt-tasks/jshint.js +++ b/grunt-tasks/jshint.js @@ -33,7 +33,6 @@ module.exports = function(grunt) { '<%= jsPath %>/lib/comments.js', '<%= jsPath %>/lib/labels.js', '<%= jsPath %>/lib/issues.js', - '<%= jsPath %>/lib/shared.js', '<%= jsPath %>/lib/diagnose.js' ] }); diff --git a/run.py b/run.py index 67dcbcfbf..f8bbf5e88 100644 --- a/run.py +++ b/run.py @@ -4,7 +4,21 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +import argparse + from webcompat import app if __name__ == '__main__': - app.run() + parser = argparse.ArgumentParser() + parser.add_argument('-t', '--testmode', action='store_true', + help='Run server in "test mode".') + args = parser.parse_args() + + if args.testmode: + # disable HttpOnly setting for session cookies so Selenium + # can interact with them. *ONLY* do this for testing. + app.config['SESSION_COOKIE_HTTPONLY'] = False + print("Starting server in ~*TEST MODE*~") + app.run() + else: + app.run() \ No newline at end of file diff --git a/tests/functional/lib/index.js b/tests/functional/lib/index.js index 8437e26a4..61a677886 100644 --- a/tests/functional/lib/index.js +++ b/tests/functional/lib/index.js @@ -25,7 +25,7 @@ define([ .end(); }, - 'logging in on the homepage': function() { + 'my issues (when logged in)': function() { return this.remote .setFindTimeout(intern.config.wc.pageLoadTimeout) .get(require.toUrl(url)) @@ -46,6 +46,12 @@ define([ assert.equal(text, "Logout"); }) .end() + .findByCssSelector('#my-issues h3').getVisibleText() + .then(function (text) { + assert.equal(text, 'Submitted by Me'); + }) + .sleep(1000) + .end() }, 'reporter addon link is shown': function () { @@ -74,19 +80,6 @@ define([ }); }, - 'browse issues (my issues)': function() { - return this.remote - .setFindTimeout(intern.config.wc.pageLoadTimeout) - .get(require.toUrl(url)) - .findByCssSelector('.nav__section--right .nav__link').click() - .end() - .findByCssSelector('#my-issues h3').getVisibleText() - .then(function (text) { - assert.equal(text, 'Submitted by Me'); - }) - .end() - }, - 'browse issues (needs diagnosis)': function() { return this.remote .get(require.toUrl(url)) diff --git a/tests/functional/lib/reporting.js b/tests/functional/lib/reporting.js index c8e24a265..70dd5b038 100644 --- a/tests/functional/lib/reporting.js +++ b/tests/functional/lib/reporting.js @@ -38,11 +38,6 @@ define([ .end() .findByCssSelector('#summary').click() .end() - .findByCssSelector('.Report-form > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)').getAttribute('class') - .then(function (className) { - assert.include(className, 'has-error'); - }) - .end() .findByCssSelector('#url').type('hi') .end() .findByCssSelector('#summary').click() @@ -74,44 +69,44 @@ define([ }) }, - 'anonymous report': function () { - var issueNumber; + // 'anonymous report': function () { + // var issueNumber; - return this.remote - .setFindTimeout(intern.config.wc.pageLoadTimeout) - .get(require.toUrl(url + "?open=1")) - .findByCssSelector('#url').type('http://miketaylr.com') - .end() - .findByCssSelector('#summary').type('Hello from Intern') - .end() - .findByCssSelector('#submitanon').click() - .end() - .findByCssSelector('.wc-content--body h2').getVisibleText() - .then(function (text) { - // Make sure we got to the /thanks/ route - assert.equal(text, 'Thank you.'); - }) - .end() - .findByCssSelector('.wc-content--body a').getVisibleText() - .then(function (text) { - // Grab the issue number from the end of the URL link - issueNumber = text.split('/').pop(); - }) - .end() - .findByCssSelector('.wc-content--body a').getVisibleText().click() - .end() - .findByCssSelector('.js-issue-title').getVisibleText() - .then(function (text) { - // Make sure GitHub has the correct title - assert.equal(text, 'miketaylr.com - Hello from Intern'); - }) - .end() - .findByCssSelector('.gh-header-number').getVisibleText() - .then(function (text) { - // Make sure GitHub has the correct issue number - assert.equal(text, '#' + issueNumber); - }) - } + // return this.remote + // .setFindTimeout(intern.config.wc.pageLoadTimeout) + // .get(require.toUrl(url + "?open=1")) + // .findByCssSelector('#url').type('some broken URL') + // .end() + // .findByCssSelector('#summary').type('this site doesnt work ' + Math.random()) + // .end() + // .findByCssSelector('#submitanon').click() + // .end() + // .findByCssSelector('.wc-content--body h2').getVisibleText() + // .then(function (text) { + // // Make sure we got to the /thanks/ route + // assert.equal(text, 'Thank you.'); + // }) + // .end() + // .findByCssSelector('.wc-content--body a').getVisibleText() + // .then(function (text) { + // // Grab the issue number from the end of the URL link + // issueNumber = text.split('/').pop(); + // }) + // .end() + // .findByCssSelector('.wc-content--body a').getVisibleText().click() + // .end() + // .findByCssSelector('.js-issue-title').getVisibleText() + // .then(function (text) { + // // Make sure GitHub has the correct title + // assert.include(text, 'some broken URL - this site doesnt work'); + // }) + // .end() + // .findByCssSelector('.gh-header-number').getVisibleText() + // .then(function (text) { + // // Make sure GitHub has the correct issue number + // assert.equal(text, '#' + issueNumber); + // }) + // } }); }); diff --git a/webcompat/helpers.py b/webcompat/helpers.py index c602dfbfd..9179cb726 100644 --- a/webcompat/helpers.py +++ b/webcompat/helpers.py @@ -4,8 +4,11 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +import urlparse + from flask import session from ua_parser import user_agent_parser + from webcompat import github JSON_MIME = 'application/json' @@ -79,3 +82,18 @@ def get_headers(response): 'cache-control': response.headers.get('cache-control'), 'content-type': JSON_MIME} return headers + + +def get_referer(request): + '''Return the Referer URI based on the passed in Request object. + + Also validate that it came from our own server. If it didn't, return None. + ''' + host_whitelist = ('webcompat.com', 'staging.webcompat.com', + '127.0.0.1', 'localhost') + if request.referrer: + host = urlparse.urlparse(request.referrer).hostname + if host in host_whitelist: + return request.referrer + else: + return None diff --git a/webcompat/static/js/lib/shared.js b/webcompat/static/js/lib/shared.js deleted file mode 100644 index 711f050fc..000000000 --- a/webcompat/static/js/lib/shared.js +++ /dev/null @@ -1,11 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -(function(){ - var logLink = $('.nav__section--right .nav__link, .issue__login_link'); - logLink.click(function() { - var href = logLink.prop('href'); - logLink.prop('href', href + '?next=' + location.href); - }); -}()); diff --git a/webcompat/templates/layout.html b/webcompat/templates/layout.html index a87da7b9d..d2d1805fa 100644 --- a/webcompat/templates/layout.html +++ b/webcompat/templates/layout.html @@ -58,7 +58,6 @@ - {%- endif %} {% for category, message in get_flashed_messages(with_categories=True) %}
{{ message }}
diff --git a/webcompat/views.py b/webcompat/views.py index 26bf4c03f..c5712d551 100644 --- a/webcompat/views.py +++ b/webcompat/views.py @@ -21,6 +21,7 @@ from helpers import get_browser from helpers import get_browser_name from helpers import get_os +from helpers import get_referer from helpers import get_user_info from issues import report_issue from models import db_session @@ -47,6 +48,7 @@ def before_request(): g.user = None if 'user_id' in session: g.user = User.query.get(session['user_id']) + g.referer = get_referer(request) or url_for('index') @app.after_request @@ -71,20 +73,17 @@ def format_date(datestring): @app.route('/login') def login(): - next_url = request.args.get('next') or url_for('index') if session.get('user_id', None) is None: - session['next_url'] = next_url return github.authorize('public_repo') else: - return redirect(next_url) + return redirect(g.referer) @app.route('/logout') def logout(): - next_url = request.args.get('next') or url_for('index') session.clear() flash(u'You were successfully logged out.', 'info') - return redirect(next_url) + return redirect(g.referer) # OAuth2 callback handler that GitHub requires. @@ -92,10 +91,9 @@ def logout(): @app.route('/callback') @github.authorized_handler def authorized(access_token): - next_url = session.get('next_url') or url_for('index') if access_token is None: flash(u'Something went wrong trying to sign into GitHub. :(', 'error') - return redirect(next_url) + return redirect(g.referer) user = User.query.filter_by(github_access_token=access_token).first() if user is None: user = User(access_token) @@ -105,7 +103,7 @@ def authorized(access_token): if session.get('form_data', None) is not None: return redirect(url_for('file_issue')) else: - return redirect(next_url) + return redirect(g.referer) # This route won't ever be viewed by a human being--there's not