test_api_rrset.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import pytest
  2. from conftest import DeSECAPIV1Client
  3. @pytest.mark.parametrize("init_rrsets", [
  4. {
  5. ('www', 'A'): (3600, {'1.2.3.4'}),
  6. ('www', 'AAAA'): (3600, {'::1'}),
  7. ('one', 'CNAME'): (3600, {'some.example.net.'}),
  8. ('other', 'TXT'): (3600, {'"foo" "bar"', '"bar" "foo"'}),
  9. }
  10. ])
  11. @pytest.mark.parametrize("rrsets", [
  12. { # create three RRsets
  13. ('a' * 63, 'A'): (7000, {'4.3.2.1', '7.6.5.4'}),
  14. ('b', 'PTR'): (7000, {'1.foo.bar.com.', '2.bar.foo.net.'}),
  15. ('c.' + 'a' * 63, 'MX'): (7000, {'10 mail.something.net.'}),
  16. },
  17. { # update three RRsets
  18. ('www', 'A'): None, # ensure value from init_rrset is still there
  19. ('www', 'AAAA'): (7000, {'6666::6666', '7777::7777'}),
  20. ('one', 'CNAME'): (7000, {'other.example.net.'}),
  21. ('other', 'TXT'): (7000, {'"foobar"'}),
  22. },
  23. { # delete three RRsets
  24. ('www', 'A'): (7000, {}),
  25. ('www', 'AAAA'): None, # ensure value from init_rrset is still there
  26. ('one', 'CNAME'): (7000, {}),
  27. ('other', 'TXT'): (7000, {}),
  28. },
  29. { # create, update, delete
  30. ('a' * 63, 'A'): (7000, {'4.3.2.1', '7.6.5.4'}),
  31. ('www', 'A'): None, # ensure value from init_rrset is still there
  32. ('www', 'AAAA'): (7000, {'6666::6666', '7777::7777'}),
  33. ('one', 'CNAME'): None, # ensure value from init_rrset is still there
  34. ('other', 'TXT'): (7000, {}),
  35. },
  36. { # complex usecase
  37. ('', 'A'): (3600, {'1.2.3.4', '255.254.253.252'}), # create apex record
  38. ('*', 'MX'): (3601, {'0 mx.example.net.'}), # create wildcard record
  39. ('www', 'AAAA'): (3602, {}), # remove existing record
  40. ('www', 'A'): (7000, {'4.3.2.1', '7.6.5.4'}), # update existing record
  41. ('one', 'A'): (3603, {'1.1.1.1'}), # configure A instead of ...
  42. ('one', 'CNAME'): (3603, {}), # ... CNAME
  43. ('other', 'CNAME'): (3603, {'cname.example.com.'}), # configure CNAME instead of ...
  44. ('other', 'TXT'): (3600, {}), # ... TXT
  45. ('nonexistent', 'DNAME'): (3600, {}), # delete something that doesn't exist
  46. ('sub', 'CDNSKEY'): (3600, {'257 3 15 l02Woi0iS8Aa25FQkUd9RMzZHJpBoRQwAQEX1SxZJA4='}), # non-apex DNSSEC
  47. ('sub', 'CDS'): (3600, {'35217 15 2 401781b934e392de492ec77ae2e15d70f6575a1c0bc59c5275c04ebe80c6614c'}), # dto.
  48. # ('sub', 'DNSKEY'): (3600, {'257 3 15 l02Woi0iS8Aa25FQkUd9RMzZHJpBoRQwAQEX1SxZJA4='}) # no pdns support >= 4.6
  49. },
  50. ])
  51. def test(api_user_domain_rrsets: DeSECAPIV1Client, rrsets: dict):
  52. api_user_domain_rrsets.patch(f"/domains/{api_user_domain_rrsets.domain}/rrsets/", data=[
  53. {"subname": k[0], "type": k[1], "ttl": v[0], "records": list(v[1])}
  54. for k, v in rrsets.items()
  55. if v is not None
  56. ])
  57. api_user_domain_rrsets.assert_rrsets(rrsets)