-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gazette: Adds Auth view for TOTP second factor
TYPE: Feature LINK: SEA-1413
- Loading branch information
Showing
3 changed files
with
121 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE 1.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-02-10 17:10+0100\n" | ||
"POT-Creation-Date: 2024-08-08 10:53+0200\n" | ||
"PO-Revision-Date: 2019-04-01 07:57+0200\n" | ||
"Last-Translator: Marc Sommerhalder <[email protected]>\n" | ||
"Language-Team: German\n" | ||
|
@@ -495,6 +495,21 @@ msgstr "Passwort geändert." | |
msgid "Wrong username or password reset link not valid any more." | ||
msgstr "Ungültige Adresse oder abgelaufener Link." | ||
|
||
msgid "Failed to continue login, please ensure cookies are allowed." | ||
msgstr "" | ||
"Das Fortsetzen des Logins ist fehlgeschlagen, bitte stellen Sie sicher, dass " | ||
"Sie Cookies erlauben." | ||
|
||
msgid "Invalid or expired TOTP provided." | ||
msgstr "Ungültige oder abgelaufenes TOTP eingegeben." | ||
|
||
msgid "Please enter the six digit code from your authenticator app" | ||
msgstr "" | ||
"Bitte geben Sie den sechsstelligen Code aus ihrer Authenticator App ein" | ||
|
||
msgid "Enter TOTP" | ||
msgstr "TOTP eingeben" | ||
|
||
msgid "Category added." | ||
msgstr "Rubrik hinzugefügt." | ||
|
||
|
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import onegov.gazette | ||
import os | ||
import pyotp | ||
import transaction | ||
|
||
from lxml.html import document_fromstring | ||
from tests.shared import Client, utils | ||
from onegov.user import UserCollection | ||
from pytest import mark | ||
from sqlalchemy.orm.session import close_all_sessions | ||
from tests.shared import Client, utils | ||
|
||
|
||
@mark.skip('Will mess up tests in the CI') | ||
|
@@ -37,7 +41,7 @@ def test_view_login_logout(gazette_app): | |
login.form['password'] = 'hunter2' | ||
page = login.form.submit().maybe_follow() | ||
|
||
assert 'Angemeldet als {}'.format(realname or username) in page | ||
assert f'Angemeldet als {realname or username}' in page | ||
assert 'Abmelden' in page | ||
assert 'Anmelden' not in page | ||
|
||
|
@@ -99,3 +103,40 @@ def test_view_reset_password(gazette_app): | |
login_page.form['password'] = 'new_password' | ||
login_page = login_page.form.submit().maybe_follow() | ||
assert "Angemeldet als [email protected]" in login_page.maybe_follow() | ||
|
||
|
||
def test_login_totp(gazette_app): | ||
gazette_app.totp_enabled = True | ||
client = Client(gazette_app) | ||
|
||
totp_secret = pyotp.random_base32() | ||
totp = pyotp.TOTP(totp_secret) | ||
|
||
# configure TOTP for admin user | ||
users = UserCollection(client.app.session()) | ||
admin = users.by_username('[email protected]') | ||
admin.second_factor = {'type': 'totp', 'data': totp_secret} | ||
transaction.commit() | ||
close_all_sessions() | ||
|
||
login_page = client.get('/').maybe_follow().click('Anmelden') | ||
login_page.form['username'] = '[email protected]' | ||
login_page.form['password'] = 'hunter2' | ||
|
||
totp_page = login_page.form.submit().maybe_follow() | ||
assert "TOTP eingeben" in totp_page.text | ||
totp_page.form['totp'] = 'bogus' | ||
totp_page = totp_page.form.submit() | ||
assert "Ungültige oder abgelaufenes TOTP eingegeben." in totp_page.text | ||
|
||
totp_page.form['totp'] = totp.now() | ||
page = totp_page.form.submit().maybe_follow() | ||
|
||
assert 'Angemeldet als [email protected]' in page | ||
assert 'Abmelden' in page | ||
assert 'Anmelden' not in page | ||
|
||
page = client.get('/').maybe_follow().click('Abmelden').maybe_follow() | ||
assert 'Sie sind angemeldet' not in page | ||
assert 'Abmelden' not in page | ||
assert 'Anmelden' in page |