Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion flask_oauthlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -257,6 +257,13 @@ def __init__(

self._tokengetter = None

if re.search(r'^http[s]?://.+$', base_url, re.I) is None:
message = ('`{0}` isn\'t a valid http url. '
'Missing http(s):// schema.')
raise ValueError(message.format(base_url))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format is not available in Python 2.6

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> '{}'.format('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: zero length field name in format

It will always be ValueError.


self.base_url = base_url

def make_client(self, token=None):
# request_token_url is for oauth1
if self.request_token_url:
Expand Down
20 changes: 19 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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'
)