
* init Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix some other stuff Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more progress Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix missing format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make it work, send verification event Signed-off-by: Jens Langhammer <jens@goauthentik.io> * progress Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more progress Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * save iss Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add signals for MFA devices Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * refactor more Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-work auth Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add API to list ssf streams Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start rbac Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add ssf icon Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix web Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix bugs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make events expire, rewrite sending logic Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add oidc token test Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add stream list Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add jwks tests and fixes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update web ui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix configuration endpoint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * replace port number correctly Signed-off-by: Jens Langhammer <jens@goauthentik.io> * better log what went wrong Signed-off-by: Jens Langhammer <jens@goauthentik.io> * linter has opinions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix messages Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix set status Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more debug logging Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix issuer here too Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove port :443...removal apparently apple's HTTP logic is wrong and includes the port in the Host header even if the default port is used (80 or 443), which then fails as the URL doesn't exactly match what the admin configured...so instead of trying to add magic about this we'll add it in the docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix error when no request in context Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add signal for admin session revoke Signed-off-by: Jens Langhammer <jens@goauthentik.io> * set txn based on request id Signed-off-by: Jens Langhammer <jens@goauthentik.io> * validate method and endpoint url Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix request ID detection Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add timestamp Signed-off-by: Jens Langhammer <jens@goauthentik.io> * temp migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix signal Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add signal tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * the final commit Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ok actually the last commit Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
155 lines
6.1 KiB
Python
155 lines
6.1 KiB
Python
import json
|
|
from dataclasses import asdict
|
|
|
|
from django.urls import reverse
|
|
from django.utils import timezone
|
|
from rest_framework.test import APITestCase
|
|
|
|
from authentik.core.models import Application
|
|
from authentik.core.tests.utils import create_test_admin_user, create_test_cert, create_test_flow
|
|
from authentik.enterprise.providers.ssf.models import (
|
|
SSFEventStatus,
|
|
SSFProvider,
|
|
Stream,
|
|
StreamEvent,
|
|
)
|
|
from authentik.lib.generators import generate_id
|
|
from authentik.providers.oauth2.id_token import IDToken
|
|
from authentik.providers.oauth2.models import AccessToken, OAuth2Provider
|
|
|
|
|
|
class TestStream(APITestCase):
|
|
def setUp(self):
|
|
self.application = Application.objects.create(name=generate_id(), slug=generate_id())
|
|
self.provider = SSFProvider.objects.create(
|
|
name=generate_id(),
|
|
signing_key=create_test_cert(),
|
|
backchannel_application=self.application,
|
|
)
|
|
|
|
def test_stream_add_token(self):
|
|
"""test stream add (token auth)"""
|
|
res = self.client.post(
|
|
reverse(
|
|
"authentik_providers_ssf:stream",
|
|
kwargs={"application_slug": self.application.slug},
|
|
),
|
|
data={
|
|
"iss": "https://authentik.company/.well-known/ssf-configuration/foo/5",
|
|
"aud": ["https://app.authentik.company"],
|
|
"delivery": {
|
|
"method": "https://schemas.openid.net/secevent/risc/delivery-method/push",
|
|
"endpoint_url": "https://app.authentik.company",
|
|
},
|
|
"events_requested": [
|
|
"https://schemas.openid.net/secevent/caep/event-type/credential-change",
|
|
"https://schemas.openid.net/secevent/caep/event-type/session-revoked",
|
|
],
|
|
"format": "iss_sub",
|
|
},
|
|
HTTP_AUTHORIZATION=f"Bearer {self.provider.token.key}",
|
|
)
|
|
self.assertEqual(res.status_code, 201)
|
|
stream = Stream.objects.filter(provider=self.provider).first()
|
|
self.assertIsNotNone(stream)
|
|
event = StreamEvent.objects.filter(stream=stream).first()
|
|
self.assertIsNotNone(event)
|
|
self.assertEqual(event.status, SSFEventStatus.PENDING_FAILED)
|
|
self.assertEqual(
|
|
event.payload["events"],
|
|
{"https://schemas.openid.net/secevent/ssf/event-type/verification": {"state": None}},
|
|
)
|
|
|
|
def test_stream_add_poll(self):
|
|
"""test stream add - poll method"""
|
|
res = self.client.post(
|
|
reverse(
|
|
"authentik_providers_ssf:stream",
|
|
kwargs={"application_slug": self.application.slug},
|
|
),
|
|
data={
|
|
"iss": "https://authentik.company/.well-known/ssf-configuration/foo/5",
|
|
"aud": ["https://app.authentik.company"],
|
|
"delivery": {
|
|
"method": "https://schemas.openid.net/secevent/risc/delivery-method/poll",
|
|
},
|
|
"events_requested": [
|
|
"https://schemas.openid.net/secevent/caep/event-type/credential-change",
|
|
"https://schemas.openid.net/secevent/caep/event-type/session-revoked",
|
|
],
|
|
"format": "iss_sub",
|
|
},
|
|
HTTP_AUTHORIZATION=f"Bearer {self.provider.token.key}",
|
|
)
|
|
self.assertEqual(res.status_code, 400)
|
|
self.assertJSONEqual(
|
|
res.content,
|
|
{"delivery": {"method": ["Polling for SSF events is not currently supported."]}},
|
|
)
|
|
|
|
def test_stream_add_oidc(self):
|
|
"""test stream add (oidc auth)"""
|
|
provider = OAuth2Provider.objects.create(
|
|
name=generate_id(),
|
|
authorization_flow=create_test_flow(),
|
|
)
|
|
self.application.provider = provider
|
|
self.application.save()
|
|
user = create_test_admin_user()
|
|
token = AccessToken.objects.create(
|
|
provider=provider,
|
|
user=user,
|
|
token=generate_id(),
|
|
auth_time=timezone.now(),
|
|
_scope="openid user profile",
|
|
_id_token=json.dumps(
|
|
asdict(
|
|
IDToken("foo", "bar"),
|
|
)
|
|
),
|
|
)
|
|
|
|
res = self.client.post(
|
|
reverse(
|
|
"authentik_providers_ssf:stream",
|
|
kwargs={"application_slug": self.application.slug},
|
|
),
|
|
data={
|
|
"iss": "https://authentik.company/.well-known/ssf-configuration/foo/5",
|
|
"aud": ["https://app.authentik.company"],
|
|
"delivery": {
|
|
"method": "https://schemas.openid.net/secevent/risc/delivery-method/push",
|
|
"endpoint_url": "https://app.authentik.company",
|
|
},
|
|
"events_requested": [
|
|
"https://schemas.openid.net/secevent/caep/event-type/credential-change",
|
|
"https://schemas.openid.net/secevent/caep/event-type/session-revoked",
|
|
],
|
|
"format": "iss_sub",
|
|
},
|
|
HTTP_AUTHORIZATION=f"Bearer {token.token}",
|
|
)
|
|
self.assertEqual(res.status_code, 201)
|
|
stream = Stream.objects.filter(provider=self.provider).first()
|
|
self.assertIsNotNone(stream)
|
|
event = StreamEvent.objects.filter(stream=stream).first()
|
|
self.assertIsNotNone(event)
|
|
self.assertEqual(event.status, SSFEventStatus.PENDING_FAILED)
|
|
self.assertEqual(
|
|
event.payload["events"],
|
|
{"https://schemas.openid.net/secevent/ssf/event-type/verification": {"state": None}},
|
|
)
|
|
|
|
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},
|
|
),
|
|
HTTP_AUTHORIZATION=f"Bearer {self.provider.token.key}",
|
|
)
|
|
self.assertEqual(res.status_code, 204)
|
|
self.assertFalse(Stream.objects.filter(pk=stream.pk).exists())
|