-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable webauthn plugin for security keys (#1528)
* feat: Enable webauthn handling when plugin is installed. * Minor code cleanup. * feat: Enable webauthn plugin for security keys Move key press prompt and remove TODO question. * feat: Enable webauthn plugin for security keys Fix lint and mypy errors. * feat: Enable webauthn plugin for security keys Check dict accesses for None. Remove commented out line. * feat: Enable webauthn plugin for security keys Change _urlsafe_b64recode to _unpadded_urlsafe_b64recode for clarity. * feat: Enable webauthn plugin for security keys Fix broken test and add test clauses to bring coverage to 100%. --------- Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>
- Loading branch information
1 parent
adb94f7
commit e2d5e63
Showing
4 changed files
with
276 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import List, Optional | ||
|
||
from google.oauth2.webauthn_handler import PluginHandler, WebAuthnHandler | ||
|
||
|
||
class WebauthnHandlerFactory: | ||
handlers: List[WebAuthnHandler] | ||
|
||
def __init__(self): | ||
self.handlers = [PluginHandler()] | ||
|
||
def get_handler(self) -> Optional[WebAuthnHandler]: | ||
for handler in self.handlers: | ||
if handler.is_available(): | ||
return handler | ||
return None |
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 mock | ||
import pytest # type: ignore | ||
|
||
from google.oauth2 import webauthn_handler | ||
from google.oauth2 import webauthn_handler_factory | ||
|
||
|
||
@pytest.fixture | ||
def os_get_stub(): | ||
with mock.patch.object( | ||
webauthn_handler.os.environ, | ||
"get", | ||
return_value="gcloud_webauthn_plugin", | ||
name="fake os.environ.get", | ||
) as mock_os_environ_get: | ||
yield mock_os_environ_get | ||
|
||
|
||
# Check that get_handler returns a value when env is set, | ||
# that type is PluginHandler, and that no value is returned | ||
# if env not set. | ||
def test_WebauthHandlerFactory_get(os_get_stub): | ||
factory = webauthn_handler_factory.WebauthnHandlerFactory() | ||
assert factory.get_handler() is not None | ||
|
||
assert isinstance(factory.get_handler(), webauthn_handler.PluginHandler) | ||
|
||
os_get_stub.return_value = None | ||
assert factory.get_handler() is None |