Skip to content

Commit

Permalink
fixup! feat(api): honor auto_policy during domain creation, closes #885
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Nov 30, 2024
1 parent d39ea0c commit 8a983a0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions api/desecapi/tests/test_token_domain_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,17 +725,30 @@ def test_auto_policy_from_creation(self):
def test_create_domain(self):
self.token.auto_policy = True
self.token.save()
self.token_manage.perm_create_domain = True
self.token_manage.save()

name = "domain.example"
with self.assertRequests(self.requests_desec_domain_creation(name)):
name_auto = "domain.example"
name_other = "other.example"
with self.assertRequests(self.requests_desec_domain_creation(name_other)):
response = self.client._request(
self.client.post,
self.reverse("v1:domain-list"),
using=self.token_manage,
data={"name": name_other},
)
self.assertStatus(response, status.HTTP_201_CREATED)
with self.assertRequests(self.requests_desec_domain_creation(name_auto)):
response = self.client._request(
self.client.post,
self.reverse("v1:domain-list"),
using=self.token,
data={"name": name},
data={"name": name_auto},
)
self.assertStatus(response, status.HTTP_201_CREATED)

self.assertEqual(self.token.tokendomainpolicy_set.count(), 2)
rrset = models.RRset(domain=models.Domain.objects.get(name=name))
rrset = models.RRset(domain=models.Domain.objects.get(name=name_auto))
self.assertTrue(self.token.get_policy(rrset).perm_write)
rrset = models.RRset(domain=models.Domain.objects.get(name=name_other))
self.assertFalse(self.token.get_policy(rrset).perm_write)

0 comments on commit 8a983a0

Please sign in to comment.