Skip to content
Merged
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
1 change: 0 additions & 1 deletion examples/custom_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@

# Google Authenticator
# (For 2-factor authentication using a time-based one-time password algorithm)
# (See https://github.com/pyotp/pyotp and https://pypi.org/project/pyotp/ )
# (Also works with Authy and other compatible apps.)
# Usage: "self.get_google_auth_password()" (output based on timestamp)
# Usage with override: "self.get_google_auth_password(totp_key=TOTP_KEY)"
Expand Down
2 changes: 1 addition & 1 deletion help_docs/features_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Includes a [website tour builder](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md) for creating interactive walkthroughs.
* Includes a GUI for running pytest scripts: [SeleniumBase Commander](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/commander.md).
* Includes integrations for [GitHub Actions](https://seleniumbase.io/integrations/github/workflows/ReadMe/), [Google Cloud](https://github.com/seleniumbase/SeleniumBase/tree/master/integrations/google_cloud/ReadMe.md), [Azure](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/azure/jenkins/ReadMe.md), [S3](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/s3_logging_plugin.py), and [Docker](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/docker/ReadMe.md).
* Can handle Google Authenticator logins with [Python's one-time password library](https://pyotp.readthedocs.io/en/latest/).
* Can handle Google Authenticator logins that require 2FA via time-based tokens.
* Can load and make assertions on PDF files from websites or the local file system.
* Can inspect HTML to find issues and points of interest with the [HTML Inspector](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/html_inspector.md).
* Is backwards-compatible with Python [WebDriver](https://www.selenium.dev/projects/) methods. (Use: `self.driver`)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ behave==1.2.6
soupsieve~=2.10.0;python_version<"3.11.5"
soupsieve~=4.1.1;python_version>="3.11.5"
beautifulsoup4~=4.15.0
pyotp~=2.11.2
python-xlib==0.33;platform_system=="Linux"
PyAutoGUI>=0.9.54;platform_system=="Linux"
markdown-it-py==4.3.0
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.58.0"
__version__ = "4.58.1"
1 change: 0 additions & 1 deletion seleniumbase/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@

# Google Authenticator
# (For 2-factor authentication using a time-based one-time password algorithm)
# (See https://github.com/pyotp/pyotp and https://pypi.org/project/pyotp/ )
# (Also works with Authy and other compatible apps.)
# Usage: "self.get_google_auth_password()" (output based on timestamp)
# Usage with override: "self.get_google_auth_password(totp_key=TOTP_KEY)"
Expand Down
25 changes: 20 additions & 5 deletions seleniumbase/fixtures/shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def get_mfa_code(totp_key=None):
to using the one provided in [seleniumbase/config/settings.py].
Google Authenticator codes expire & change at 30-sec intervals.
If the fetched password expires in the next 1.2 seconds, waits
for a new one before returning it (may take up to 1.2 seconds).
See https://pyotp.readthedocs.io/en/latest/ for details."""
import pyotp
for a new one before returning it (may take up to 1.2 seconds)."""
import base64
import binascii
import hashlib
import hmac
import struct

if not totp_key:
totp_key = settings.TOTP_KEY
Expand All @@ -73,8 +76,20 @@ def get_mfa_code(totp_key=None):
if not float(cycle_lifespan) > 0.96:
# The new password cycle has begun
break
totp = pyotp.TOTP(totp_key)
return str(totp.now())
normalized_key = "".join(str(totp_key).split()).upper()
padded_key = normalized_key + "=" * (-len(normalized_key) % 8)
try:
secret_bytes = base64.b32decode(padded_key)
except binascii.Error as exc:
raise ValueError(
"Invalid TOTP secret key: must be a valid Base32 string."
) from exc
counter = struct.pack(">Q", int(time.time() // 30))
digest = hmac.new(secret_bytes, counter, hashlib.sha1).digest()
offset = digest[-1] & 0x0F
truncated = struct.unpack(">I", digest[offset: offset + 4])[0]
code_int = (truncated & 0x7FFFFFFF) % 1000000
return f"{code_int:06d}"


def is_arm_linux():
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@
'soupsieve~=2.10.0;python_version<"3.11.5"',
'soupsieve~=4.1.1;python_version>="3.11.5"',
'beautifulsoup4~=4.15.0',
'pyotp~=2.11.2',
'python-xlib==0.33;platform_system=="Linux"',
'PyAutoGUI>=0.9.54;platform_system=="Linux"',
'markdown-it-py==4.3.0',
Expand Down
Loading