Only redirect when redirect url is an internal page.

This commit is contained in:
Diana Huang
2013-07-24 15:56:03 -04:00
parent a96099868d
commit d1b503d53a
10 changed files with 80 additions and 9 deletions

View File

@@ -65,7 +65,7 @@ def log_in(username, password):
@world.absorb
def register_by_course_id(course_id, is_staff=False):
create_user('robot')
create_user('robot', 'password')
u = User.objects.get(username='robot')
if is_staff:
u.is_staff = True

View File

@@ -168,6 +168,11 @@ def dialogs_are_closed(step):
assert world.dialogs_closed()
@step(u'visit the url "([^"]*)"')
def visit_url(step, url):
world.browser.visit(django_url(url))
@step('I will confirm all alerts')
def i_confirm_all_alerts(step):
"""

View File

@@ -0,0 +1,20 @@
// checks whether or not the url is external to the local site.
// generously provided by StackOverflow: http://stackoverflow.com/questions/6238351/fastest-way-to-detect-external-urls
function isExternal(url) {
// parse the url into protocol, host, path, query, and fragment. More information can be found here: http://tools.ietf.org/html/rfc3986#appendix-B
var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/);
// match[1] matches a protocol if one exists in the url
// if the protocol in the url does not match the protocol in the window's location, this url is considered external
if (typeof match[1] === "string" &&
match[1].length > 0
&& match[1].toLowerCase() !== location.protocol)
return true;
// match[2] matches the host if one exists in the url
// if the host in the url does not match the host of the window location, this url is considered external
if (typeof match[2] === "string" &&
match[2].length > 0 &&
// this regex removes the port number if it patches the current location's protocol
match[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"), "") !== location.host)
return true;
return false;
}