Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove an adaptation to Pythons older than 3.7 #2840

Merged
merged 1 commit into from Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 5 additions & 15 deletions python/nav/web/auth/remote_user.py
Expand Up @@ -18,27 +18,13 @@
"""
import logging
from os.path import join
import secrets

from nav.auditlog.models import LogEntry
from nav.config import NAVConfigParser
from nav.models.profiles import Account
from nav.web.auth.utils import ACCOUNT_ID_VAR

try:
# Python 3.6+
import secrets

def fake_password(length):
return secrets.token_urlsafe(length)

except ImportError:
from random import choice
import string

def fake_password(length):
symbols = string.ascii_letters + string.punctuation + string.digits
return u"".join(choice(symbols) for i in range(length))


__all__ = []

Expand All @@ -61,6 +47,10 @@
_config = RemoteUserConfigParser()


def fake_password(length):
return secrets.token_urlsafe(length)

Check warning on line 51 in python/nav/web/auth/remote_user.py

View check run for this annotation

Codecov / codecov/patch

python/nav/web/auth/remote_user.py#L51

Added line #L51 was not covered by tests


def authenticate(request):
"""Authenticate username from http header REMOTE_USER

Expand Down