-
Notifications
You must be signed in to change notification settings - Fork 159
Improve OpenPGP keyring test coverage #7947
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
base: main
Are you sure you want to change the base?
Changes from all commits
8ecb6cb
59a6beb
f600fe7
f6bd99f
2c76801
76a7731
60c2214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Generated by Django 5.2.14 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("core", "0154_task_api_version"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterModelOptions( | ||
| name="openpgpdistribution", | ||
| options={ | ||
| "default_related_name": "%(app_label)s_%(model_name)s", | ||
| "permissions": [ | ||
| ( | ||
| "manage_roles_openpgpdistribution", | ||
| "Can manage roles on openpgp distributions", | ||
| ) | ||
| ], | ||
| }, | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,20 +48,23 @@ def represent(self, repository_version=None): | |
| else: | ||
| content_filter = {} | ||
| data = self.packet() | ||
| # note: because these queries aren't ordered, the result may be nondetermininistic | ||
| for signature in self.openpgp_signatures.filter(**content_filter): | ||
| for signature in self.openpgp_signatures.filter(**content_filter).order_by("pk"): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we try to order by something different than PK? Problem is we don't really have access to much else. |
||
| data += signature.packet() | ||
| for user_id in self.user_ids.filter(**content_filter): | ||
| for user_id in self.user_ids.filter(**content_filter).order_by("pk"): | ||
| data += user_id.packet() | ||
| for signature in user_id.openpgp_signatures.filter(**content_filter): | ||
| for signature in user_id.openpgp_signatures.filter(**content_filter).order_by("pk"): | ||
| data += signature.packet() | ||
| for user_attribute in self.user_attributes.filter(**content_filter): | ||
| for user_attribute in self.user_attributes.filter(**content_filter).order_by("pk"): | ||
| data += user_attribute.packet() | ||
| for signature in user_attribute.openpgp_signatures.filter(**content_filter): | ||
| for signature in user_attribute.openpgp_signatures.filter(**content_filter).order_by( | ||
| "pk" | ||
| ): | ||
| data += signature.packet() | ||
| for public_subkey in self.public_subkeys.filter(**content_filter): | ||
| for public_subkey in self.public_subkeys.filter(**content_filter).order_by("pk"): | ||
| data += public_subkey.packet() | ||
| for signature in public_subkey.openpgp_signatures.filter(**content_filter): | ||
| for signature in public_subkey.openpgp_signatures.filter(**content_filter).order_by( | ||
| "pk" | ||
| ): | ||
| data += signature.packet() | ||
| return armor(data, ArmorKind.PublicKey).strip() # avoid trailing newline | ||
|
|
||
|
|
@@ -140,7 +143,7 @@ class OpenPGPSignature(_OpenPGPContent): | |
|
|
||
| @property | ||
| def expired(self): | ||
| return self.expiration_time and timezone.now() > self.created + self.expiration_time | ||
| return bool(self.expiration_time and timezone.now() > self.created + self.expiration_time) | ||
|
|
||
| @property | ||
| def key_expired(self): | ||
|
|
@@ -222,6 +225,8 @@ def content_handler(self, path): | |
| def content_handler_list_directory(self, rel_path): | ||
| if rel_path == "": | ||
| repository_version = self.repository_version or self.repository.latest_version() | ||
| if repository_version is None: | ||
| return set() | ||
| fingerprints = OpenPGPPublicKey.objects.filter( | ||
| pk__in=repository_version.content | ||
| ).values_list("fingerprint", flat=True) | ||
|
|
@@ -231,5 +236,5 @@ def content_handler_list_directory(self, rel_path): | |
| class Meta: | ||
| default_related_name = "%(app_label)s_%(model_name)s" | ||
| permissions = [ | ||
| ("manage_roles_openpgpdistribution", "Can manage roles on gem distributions"), | ||
| ("manage_roles_openpgpdistribution", "Can manage roles on openpgp distributions"), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,14 +260,21 @@ def get_viewset_for_model(model_obj, ignore_error=False): | |
| # go through the viewset registry to find the viewset for the passed-in model | ||
| for app in pulp_plugin_configs(): | ||
| for model, viewsets in app.named_viewsets.items(): | ||
| # There may be multiple viewsets for a model. In this | ||
| # case, we can't reverse the mapping. | ||
| if len(viewsets) == 1: | ||
| viewset = viewsets[0] | ||
| _model_viewset_cache.setdefault(model, viewset) | ||
| if model is model_class: | ||
| model_viewset = viewset | ||
| break | ||
| else: | ||
| # Multiple viewsets for the same model (e.g. RepositoryVersionViewSet | ||
| # and OpenPGPKeyringVersionViewSet both use RepositoryVersion). | ||
| # Prefer the base class — subclass viewsets exist for URL routing | ||
| # and custom access policies, not for model-to-viewset reverse lookups. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is theoretically correct (I think), but it's a huge hack that Claude came up with, and I'd prefer to just move the openpgp types to a new app. There's also conflicts with implementing import/export for types in pulpcore. If we were to actually move forwards with this I'd want to review this very very heavily. I have not really done so yet, I just want to see the impact it has on CI. |
||
| bases = [vs for vs in viewsets if all(issubclass(other, vs) for other in viewsets)] | ||
| if len(bases) != 1: | ||
| continue | ||
| viewset = bases[0] | ||
| _model_viewset_cache.setdefault(model, viewset) | ||
| if model is model_class: | ||
| model_viewset = viewset | ||
| break | ||
| if model_viewset is not None: | ||
| break | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So irritating that just fixing a typo requires a migration. I will probably try to see if we can fold this one into another one, should another one come along soon.