Skip to content

Commit

Permalink
blueprints: handle model referencing non-existent app/model (goauthen…
Browse files Browse the repository at this point in the history
…tik#10796)

Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu authored Aug 6, 2024
1 parent 34b01d9 commit 02e852b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion authentik/blueprints/v1/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ def resolve(self, entry: BlueprintEntry, blueprint: Blueprint) -> Any:
else:
model_name = self.model_name

model_class = apps.get_model(*model_name.split("."))
try:
model_class = apps.get_model(*model_name.split("."))
except LookupError as exc:
raise EntryInvalidError.from_entry(exc, entry) from exc

query = Q()
for cond in self.conditions:
Expand Down
12 changes: 6 additions & 6 deletions authentik/blueprints/v1/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,17 @@ def __query_from_identifier(self, attrs: dict[str, Any]) -> Q:

return main_query | sub_query

def _validate_single(self, entry: BlueprintEntry) -> BaseSerializer | None:
def _validate_single(self, entry: BlueprintEntry) -> BaseSerializer | None: # noqa: PLR0915
"""Validate a single entry"""
if not entry.check_all_conditions_match(self._import):
self.logger.debug("One or more conditions of this entry are not fulfilled, skipping")
return None

model_app_label, model_name = entry.get_model(self._import).split(".")
model: type[SerializerModel] = registry.get_model(model_app_label, model_name)
try:
model: type[SerializerModel] = registry.get_model(model_app_label, model_name)
except LookupError as exc:
raise EntryInvalidError.from_entry(exc, entry) from exc
# Don't use isinstance since we don't want to check for inheritance
if not is_model_allowed(model):
raise EntryInvalidError.from_entry(f"Model {model} not allowed", entry)
Expand Down Expand Up @@ -313,10 +316,7 @@ def _validate_single(self, entry: BlueprintEntry) -> BaseSerializer | None:
try:
full_data = self.__update_pks_for_attrs(entry.get_attrs(self._import))
except ValueError as exc:
raise EntryInvalidError.from_entry(
exc,
entry,
) from exc
raise EntryInvalidError.from_entry(exc, entry) from exc
always_merger.merge(full_data, updated_identifiers)
serializer_kwargs["data"] = full_data

Expand Down
1 change: 1 addition & 0 deletions authentik/providers/radius/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Meta:


class RadiusProviderPropertyMapping(PropertyMapping):
"""Add additional attributes to Radius authentication responses."""

@property
def component(self) -> str:
Expand Down

0 comments on commit 02e852b

Please sign in to comment.