def test_unicode_next_path(): path = u'/en-US/føø/bãr' request = RequestFactory().get(path) request.session = {} url = utils.default_fxa_login_url(request) state = urlparse.parse_qs(urlparse.urlparse(url).query)['state'][0] next_path = urlsafe_b64decode(state.split(':')[1] + '===') assert next_path.decode('utf-8') == path
def test_unicode_next_path(): path = u'/en-US/føø/bãr' request = RequestFactory().get(path) request.session = {} url = utils.default_fxa_login_url(request) state = parse_qs(urlparse(url).query)['state'][0] next_path = urlsafe_b64decode(state.split(':')[1] + '===') assert next_path.decode('utf-8') == path
def test_unicode_next_path(): path = u"/en-US/føø/bãr" request = RequestFactory().get(path) request.session = {} url = utils.default_fxa_login_url(request) state = urlparse.parse_qs(urlparse.urlparse(url).query)["state"][0] next_path = urlsafe_b64decode(state.split(":")[1] + "===") assert next_path.decode("utf-8") == path
def test_default_fxa_login_url_with_state(): path = "/en-US/addons/abp/?source=ddg" request = RequestFactory().get(path) request.session = {"fxa_state": "myfxastate"} raw_url = utils.default_fxa_login_url(request) url = urlparse.urlparse(raw_url) base = "{scheme}://{netloc}{path}".format(scheme=url.scheme, netloc=url.netloc, path=url.path) assert base == "https://accounts.firefox.com/oauth/authorization" query = urlparse.parse_qs(url.query) next_path = urlsafe_b64encode(path).rstrip("=") assert query == { "action": ["signin"], "client_id": ["foo"], "redirect_url": ["https://testserver/fxa"], "scope": ["profile"], "state": ["myfxastate:{next_path}".format(next_path=next_path)], }
def test_default_fxa_login_url_with_state(): path = '/en-US/addons/abp/?source=ddg' request = RequestFactory().get(path) request.session = {'fxa_state': 'myfxastate'} raw_url = utils.default_fxa_login_url(request) url = urlparse(raw_url) base = '{scheme}://{netloc}{path}'.format( scheme=url.scheme, netloc=url.netloc, path=url.path ) assert base == 'https://accounts.firefox.com/oauth/authorization' query = parse_qs(url.query) next_path = urlsafe_b64encode(force_bytes(path)).rstrip(b'=') assert query == { 'action': ['signin'], 'client_id': ['foo'], 'scope': ['profile openid'], 'state': ['myfxastate:{next_path}'.format(next_path=force_str(next_path))], }
def test_default_fxa_login_url_with_state(): path = '/en-US/addons/abp/?source=ddg' request = RequestFactory().get(path) request.session = {'fxa_state': 'myfxastate'} raw_url = utils.default_fxa_login_url(request) url = urlparse.urlparse(raw_url) base = '{scheme}://{netloc}{path}'.format( scheme=url.scheme, netloc=url.netloc, path=url.path) assert base == 'https://accounts.firefox.com/oauth/authorization' query = urlparse.parse_qs(url.query) next_path = urlsafe_b64encode(path).rstrip('=') assert query == { 'action': ['signin'], 'client_id': ['foo'], 'redirect_url': ['https://testserver/fxa'], 'scope': ['profile'], 'state': ['myfxastate:{next_path}'.format(next_path=next_path)], }
def login_link(context): return utils.default_fxa_login_url(context['request'])