Skip to content

Commit

Permalink
Upgrade Selenium dependency
Browse files Browse the repository at this point in the history
Moreover, ChromeDriverManager isn't needed any longer.
  • Loading branch information
claudep committed Feb 3, 2024
1 parent 3c4888c commit a4b94c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ django-user-sessions

# Example app (WebAuthn)

webauthn~=1.6.0
webauthn~=1.11.0

# Testing

Expand Down
3 changes: 1 addition & 2 deletions requirements_e2e.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# test with selenium
selenium~=4.4.3
webdriver-manager~=3.8.3,!=3.8.5
selenium~=4.16.0
12 changes: 6 additions & 6 deletions tests/test_views_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def test_with_remember(self):
self.assertEqual(1, len([cookie for cookie in response.cookies if cookie.startswith('remember-cookie_')]))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))
response = self.client.get('/secure/raises/')
self.assertEqual(response.status_code, 403)

Expand Down Expand Up @@ -733,7 +733,7 @@ def test_without_remember(self):
self.assertEqual(0, len([cookie for cookie in response.cookies if cookie.startswith('remember-cookie_')]))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))
response = self.client.get('/secure/raises/')
self.assertEqual(response.status_code, 403)

Expand All @@ -758,7 +758,7 @@ def test_expired(self):
self.assertEqual(1, len([cookie for cookie in response.cookies if cookie.startswith('remember-cookie_')]))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))
response = self.client.get('/secure/raises/')
self.assertEqual(response.status_code, 403)

Expand Down Expand Up @@ -790,7 +790,7 @@ def test_wrong_signature(self):
self.assertEqual(1, len([cookie for cookie in response.cookies if cookie.startswith('remember-cookie_')]))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))
response = self.client.get('/secure/raises/')
self.assertEqual(response.status_code, 403)

Expand Down Expand Up @@ -822,7 +822,7 @@ def test_remember_token_throttling(self):
self.assertEqual(1, len([cookie for cookie in response.cookies if cookie.startswith('remember-cookie_')]))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))

# Login having an invalid remember cookie
self.set_invalid_remember_cookie()
Expand Down Expand Up @@ -877,7 +877,7 @@ def test_phonedevice_with_remember_cookie(self, mock_signal, fake):
self.assertRedirects(response, resolve_url(settings.LOGIN_REDIRECT_URL))

# Logout
self.client.get(reverse('logout'))
self.client.post(reverse('logout'))

# Ask for SMS challenge
response = self._post({'auth-username': '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ deps =
dj42: Django<5.0
djmain: https://github.com/django/django/archive/main.tar.gz
yubikey: django-otp-yubikey
webauthn: webauthn>=1.2.1,<1.99
webauthn: webauthn>=1.11.0,<1.99
webauthn: -rrequirements_e2e.txt
coverage
freezegun
Expand Down
18 changes: 3 additions & 15 deletions two_factor/plugins/webauthn/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@
except ImportError:
webauthn = None

try:
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
except ImportError:
ChromeDriverManager = None


@skipUnless(webdriver, 'package selenium is not present')
@skipUnless(ChromeDriverManager, 'package webdriver-manager is not present')
@skipUnless(webauthn, 'package webauthn is not present')
class E2ETests(UserMixin, StaticLiveServerTestCase):
port = 8000
Expand All @@ -40,12 +33,7 @@ def setUp(self):

options = webdriver.ChromeOptions()
options.add_argument('headless')
try:
driver = ChromeDriverManager()
except ValueError:
driver = ChromeDriverManager(chrome_type=ChromeType.CHROMIUM)
self.webdriver = webdriver.Chrome(driver.install(), options=options)

self.webdriver = webdriver.Chrome(options=options)
super().setUp()

def tearDown(self):
Expand All @@ -70,7 +58,7 @@ def wait_for_url(self, url):
WebDriverWait(self.webdriver, self.timeout).until(EC.url_to_be(url))

def do_login(self):
self.wait_for_url(self.login_url)
self.webdriver.get(self.login_url)

username = self.webdriver.find_element(By.ID, 'id_auth-username')
username.clear()
Expand All @@ -84,7 +72,7 @@ def do_login(self):
button_next.click()

def register_authenticator(self):
self.wait_for_url(urljoin(self.base_url, reverse("two_factor:setup")))
self.webdriver.get(urljoin(self.base_url, reverse("two_factor:setup")))
self.webdriver.find_element(By.XPATH, "//button[@type='submit']").click()

self.wait_for_element(By.XPATH, "//input[@value='webauthn']").click()
Expand Down

0 comments on commit a4b94c8

Please sign in to comment.