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
7 changes: 4 additions & 3 deletions authentik/enterprise/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@
"""Get a summarized version of all (not expired) licenses"""
total = LicenseKey(get_license_aud(), 0, "Summarized license", 0, 0)
for lic in License.objects.all():
total.internal_users += lic.internal_users
total.external_users += lic.external_users
if lic.is_valid:
total.internal_users += lic.internal_users
total.external_users += lic.external_users
total.license_flags.extend(lic.status.license_flags)

Check warning on line 138 in authentik/enterprise/license.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/license.py#L135-L138

Added lines #L135 - L138 were not covered by tests
exp_ts = int(mktime(lic.expiry.timetuple()))
if total.exp == 0:
total.exp = exp_ts
total.exp = max(total.exp, exp_ts)
total.license_flags.extend(lic.status.license_flags)
return total

@staticmethod
Expand Down
4 changes: 4 additions & 0 deletions authentik/enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
internal_users = models.BigIntegerField()
external_users = models.BigIntegerField()

@property
def is_valid(self) -> bool:
return self.expiry >= now()

Check warning on line 44 in authentik/enterprise/models.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/models.py#L44

Added line #L44 was not covered by tests

@property
def serializer(self) -> type[BaseSerializer]:
from authentik.enterprise.api import LicenseSerializer
Expand Down
9 changes: 6 additions & 3 deletions authentik/enterprise/tests/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.utils.timezone import now
from rest_framework.exceptions import ValidationError

from authentik.core.models import User
from authentik.enterprise.license import LicenseKey
from authentik.enterprise.models import (
THRESHOLD_READ_ONLY_WEEKS,
Expand Down Expand Up @@ -71,9 +72,9 @@
)
def test_valid_multiple(self):
"""Check license verification"""
lic = License.objects.create(key=generate_id())
lic = License.objects.create(key=generate_id(), expiry=expiry_valid)

Check warning on line 75 in authentik/enterprise/tests/test_license.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_license.py#L75

Added line #L75 was not covered by tests
self.assertTrue(lic.status.status().is_valid)
lic2 = License.objects.create(key=generate_id())
lic2 = License.objects.create(key=generate_id(), expiry=expiry_valid)

Check warning on line 77 in authentik/enterprise/tests/test_license.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_license.py#L77

Added line #L77 was not covered by tests
self.assertTrue(lic2.status.status().is_valid)
total = LicenseKey.get_total()
self.assertEqual(total.internal_users, 200)
Expand Down Expand Up @@ -232,7 +233,9 @@
)
def test_expiry_expired(self):
"""Check license verification"""
License.objects.create(key=generate_id())
User.objects.all().delete()
License.objects.all().delete()
License.objects.create(key=generate_id(), expiry=expiry_expired)

Check warning on line 238 in authentik/enterprise/tests/test_license.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_license.py#L236-L238

Added lines #L236 - L238 were not covered by tests
self.assertEqual(LicenseKey.get_total().summary().status, LicenseUsageStatus.EXPIRED)

@patch(
Expand Down
Loading