From 8113f89c4928f47ceaad9e3dd7018e06de82a894 Mon Sep 17 00:00:00 2001 From: Randy Topliffe Date: Wed, 26 Jun 2013 13:28:43 -0400 Subject: [PATCH 1/2] OAuthRemoteApp now checks to see if base_url is a valid http url --- flask_oauthlib/client.py | 9 ++++++++- tests/test_client.py | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 08afe2d8..6d3e7558 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -12,6 +12,7 @@ import logging import oauthlib.oauth1 import oauthlib.oauth2 +import re from functools import wraps from oauthlib.common import to_unicode from urlparse import urljoin, urlparse @@ -241,7 +242,6 @@ def __init__( ): self.oauth = oauth - self.base_url = base_url self.name = name self.request_token_url = request_token_url self.access_token_url = access_token_url @@ -257,6 +257,13 @@ def __init__( self._tokengetter = None + if re.search(r'^http[s]?://.+$', base_url, re.I) is None: + message = ('`{}` isn\'t a valid http url. ' + 'Missing http(s):// schema.') + raise ValueError(message.format(base_url)) + + self.base_url = base_url + def make_client(self, token=None): # request_token_url is for oauth1 if self.request_token_url: diff --git a/tests/test_client.py b/tests/test_client.py index 6138b5b5..794a6a86 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,6 +1,6 @@ from flask import Flask from nose.tools import raises -from flask_oauthlib.client import encode_request_data, add_query +from flask_oauthlib.client import encode_request_data, add_query, OAuth from .oauth2_client import create_client @@ -36,3 +36,21 @@ def test_raise_app(): app = create_client(app) client = app.extensions['oauthlib.client'] assert client.demo.name == 'dev' + + +@raises(ValueError) +def test_bad_base_url(): + app = Flask(__name__) + oauth = OAuth(app) + + oauth.remote_app( + 'dev', + consumer_key='dev', + consumer_secret='dev', + request_token_params={'scope': 'email'}, + base_url='127.0.0.1:5000/api/', + request_token_url=None, + access_token_method='GET', + access_token_url='http://127.0.0.1:5000/oauth/token', + authorize_url='http://127.0.0.1:5000/oauth/authorize' + ) From 0fb880e8a13a4637a88932d3b9bd3d5237fad50c Mon Sep 17 00:00:00 2001 From: Randy Topliffe Date: Thu, 27 Jun 2013 08:23:59 -0400 Subject: [PATCH 2/2] Fixed python2.6 compatibility issue --- flask_oauthlib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 6d3e7558..fba78a47 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -258,7 +258,7 @@ def __init__( self._tokengetter = None if re.search(r'^http[s]?://.+$', base_url, re.I) is None: - message = ('`{}` isn\'t a valid http url. ' + message = ('`{0}` isn\'t a valid http url. ' 'Missing http(s):// schema.') raise ValueError(message.format(base_url))