Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed Dec 31, 2024
1 parent 2a4a7a3 commit b615cc7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
6 changes: 0 additions & 6 deletions authentik/enterprise/providers/ssf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,3 @@ class StreamEvent(models.Model):

def __str__(self):
return f"Stream event {self.type}"

def queue(self):
"""Queue event to be sent"""
from authentik.enterprise.providers.ssf.tasks import send_single_ssf_event

return send_single_ssf_event.delay(str(self.stream.uuid), str(self.uuid))
2 changes: 1 addition & 1 deletion authentik/enterprise/providers/ssf/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def ssf_device_post_save(sender: type[Model], instance: Device, created: bool, *


@receiver(post_delete)
def ssf_device_post_delete(sender: type[Model], instance: Device, created: bool, **_):
def ssf_device_post_delete(sender: type[Model], instance: Device, **_):
if not isinstance(instance, Device):
return
if not instance.confirmed:
Expand Down
17 changes: 14 additions & 3 deletions authentik/enterprise/providers/ssf/tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from authentik.core.models import Application
from authentik.core.tests.utils import create_test_cert
from authentik.enterprise.providers.ssf.models import SSFProvider
from authentik.enterprise.providers.ssf.models import SSFProvider, Stream
from authentik.lib.generators import generate_id


Expand Down Expand Up @@ -41,6 +41,17 @@ def test_stream_add(self):
},
HTTP_AUTHORIZATION=f"Bearer {self.provider.token.key}",
)
print(res)
print(res.content)
self.assertEqual(res.status_code, 201)

def test_stream_delete(self):
"""delete stream"""
stream = Stream.objects.create(provider=self.provider)
res = self.client.delete(
reverse(
"authentik_providers_ssf:stream",
kwargs={"application_slug": self.application.slug, "provider": self.provider.pk},
),
HTTP_AUTHORIZATION=f"Bearer {self.provider.token.key}",
)
self.assertEqual(res.status_code, 204)
self.assertFalse(Stream.objects.filter(pk=stream.pk).exists())
8 changes: 4 additions & 4 deletions authentik/enterprise/providers/ssf/views/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class StreamSerializer(ModelSerializer):
aud = ListField(child=CharField())

def create(self, validated_data):
iss = self._context["request"].build_absolute_uri(
iss = self.context["request"].build_absolute_uri(
reverse(
"authentik_providers_ssf:configuration",
kwargs={
"application_slug": self.provider.application.slug,
"provider": self.provider.pk,
"application_slug": validated_data["provider"].application.slug,
"provider": validated_data["provider"].pk,
},
)
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_events_supported(self, instance: Stream) -> list[str]:

class StreamView(SSFView):
def post(self, request: Request, *args, **kwargs) -> Response:
stream = StreamSerializer(data=request.data)
stream = StreamSerializer(data=request.data, context={"request": request})
stream.is_valid(raise_exception=True)
instance: Stream = stream.save(provider=self.provider)
send_ssf_event(
Expand Down
4 changes: 3 additions & 1 deletion authentik/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ def get_optional_int(self, path: str, default=None) -> int | None:
return int(value)
except (ValueError, TypeError) as exc:
if value is None or (isinstance(value, str) and value.lower() == "null"):
return None
return default

Check warning on line 291 in authentik/lib/config.py

View check run for this annotation

Codecov / codecov/patch

authentik/lib/config.py#L291

Added line #L291 was not covered by tests
if value is UNSET:
return default
self.log("warning", "Failed to parse config as int", path=path, exc=str(exc))
return default

Expand Down

0 comments on commit b615cc7

Please sign in to comment.