Skip to content

Commit

Permalink
Testing for allowed grant types
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Apr 2, 2015
1 parent 764b580 commit fb764a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/test_oauth2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Client(db.Model):
nullable=False)
_redirect_uris = db.Column(db.Text)
default_scope = db.Column(db.Text, default='email address')
disallow_grant_type = db.Column(db.String(20))

@property
def user(self):
Expand All @@ -57,8 +58,13 @@ def default_scopes(self):

@property
def allowed_grant_types(self):
return ['authorization_code', 'password', 'client_credentials',
'refresh_token']
types = [
'authorization_code', 'password',
'client_credentials', 'refresh_token',
]
if self.disallow_grant_type:
types.remove(self.disallow_grant_type)
return types


class Grant(db.Model):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_oauth2/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def test_get_token(self):
}, headers={'Authorization': 'Basic %s' % auth})
assert b'access_token' in rv.data

def test_disallow_grant_type(self):
self.oauth_client.disallow_grant_type = 'password'
db.session.add(self.oauth_client)
db.session.commit()

rv = self.client.post('/oauth/token', data={
'grant_type': 'password',
'username': 'foo',
'password': 'right',
'client_id': self.oauth_client.client_id,
'client_secret': self.oauth_client.client_secret,
})
assert b'error' in rv.data


class TestSQLAlchemyProvider(TestDefaultProvider):
def create_server(self):
Expand Down

0 comments on commit fb764a3

Please sign in to comment.