-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: openID provider validation flow (#2186)
* fix: openID provider validation flow * remove test cleanup
- Loading branch information
Showing
7 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
|
||
from flask_appbuilder.security.manager import AUTH_OID | ||
|
||
basedir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
SQLALCHEMY_DATABASE_URI = os.environ.get( | ||
"SQLALCHEMY_DATABASE_URI" | ||
) or "sqlite:///" + os.path.join(basedir, "app.db") | ||
|
||
SECRET_KEY = "thisismyscretkey" | ||
|
||
AUTH_TYPE = AUTH_OID | ||
|
||
OPENID_PROVIDERS = [ | ||
{"name": "Google", "url": "https://www.google.com/accounts/o8/id"}, | ||
{"name": "Yahoo", "url": "https://me.yahoo.com"}, | ||
{"name": "AOL", "url": "http://openid.aol.com/<username>"}, | ||
{"name": "Flickr", "url": "http://www.flickr.com/<username>"}, | ||
{"name": "OpenStack", "url": "https://openstackid.org/"}, | ||
] | ||
|
||
WTF_CSRF_ENABLED = False | ||
|
||
# Will allow user self registration | ||
AUTH_USER_REGISTRATION = True | ||
|
||
# The default user self registration role for all users | ||
AUTH_USER_REGISTRATION_ROLE = "Admin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from flask_appbuilder import SQLA | ||
from tests.base import FABTestCase | ||
|
||
|
||
class MVCOIDTestCase(FABTestCase): | ||
def setUp(self): | ||
from flask import Flask | ||
from flask_appbuilder import AppBuilder | ||
|
||
self.app = Flask(__name__) | ||
self.app.config.from_object("tests.config_oid") | ||
self.db = SQLA(self.app) | ||
self.appbuilder = AppBuilder(self.app, self.db.session) | ||
|
||
def test_oid_login_get(self): | ||
""" | ||
OID: Test login get | ||
""" | ||
self.appbuilder.sm.oid.try_login = MagicMock(return_value="Login ok") | ||
|
||
with self.app.test_client() as client: | ||
response = client.get("/login/") | ||
self.assertEqual(response.status_code, 200) | ||
for provider in self.app.config["OPENID_PROVIDERS"]: | ||
self.assertIn(provider["name"], response.data.decode("utf-8")) | ||
|
||
def test_oid_login_post(self): | ||
""" | ||
OID: Test login post with a valid provider | ||
""" | ||
self.appbuilder.sm.oid.try_login = MagicMock(return_value="Login ok") | ||
|
||
with self.app.test_client() as client: | ||
response = client.post("/login/", data=dict(openid="OpenStack")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.data, b"Login ok") | ||
self.appbuilder.sm.oid.try_login.assert_called_with( | ||
"https://openstackid.org/", ask_for=["email"], ask_for_optional=[] | ||
) | ||
|
||
def test_oid_login_post_invalid_provider(self): | ||
""" | ||
OID: Test login post with an invalid provider | ||
""" | ||
self.appbuilder.sm.oid.try_login = MagicMock(return_value="Not Ok") | ||
|
||
with self.app.test_client() as client: | ||
response = client.post("/login/", data=dict(openid="DoesNotExist")) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.location, "/login/") | ||
self.appbuilder.sm.oid.try_login.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters