test_replication.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from conftest import DeSECAPIV1Client, return_eventually, query_replication, random_domainname, assert_eventually, \
  2. faketime_add
  3. some_ds_records = [
  4. '60604 8 1 ef66f772935b412376c8445c4442b802b0322814',
  5. '60604 8 2 c2739629145faaf464ff1bc65612fd1eb5766e80c96932d808edfb55d1e1f2ce',
  6. '60604 8 4 5943dac4fc4aad637445f483b0f43bd4152fab19250fd26df82bf12020a7f7101caa17e723cf433f43d2bbed11231e03',
  7. ]
  8. def test_signature_rotation(api_user_domain: DeSECAPIV1Client):
  9. name = random_domainname()
  10. api_user_domain.domain_create(name)
  11. rrsig = return_eventually(lambda: query_replication(name, "", 'RRSIG', covers='SOA'), timeout=20)
  12. faketime_add(days=7)
  13. assert_eventually(lambda: rrsig != query_replication(name, "", 'RRSIG', covers='SOA'), timeout=60)
  14. def test_zone_deletion(api_user_domain: DeSECAPIV1Client):
  15. name = api_user_domain.domain
  16. assert_eventually(lambda: query_replication(name, "", 'SOA') is not None, timeout=20)
  17. api_user_domain.domain_destroy(name)
  18. assert_eventually(lambda: query_replication(name, "", 'SOA') is None, timeout=20)
  19. def test_signature_rotation_performance(api_user_domain: DeSECAPIV1Client):
  20. root_domain = api_user_domain.domain
  21. # test configuration
  22. bulk_block_size = 500
  23. domain_sizes = {
  24. # number of delegations: number of zones
  25. 2000: 1,
  26. 1000: 2,
  27. 10: 10,
  28. }
  29. # create test domains
  30. domain_names = {
  31. num_delegations: [random_domainname() + f'.num-ds-{num_delegations}.' + root_domain for _ in range(num_zones)]
  32. for num_delegations, num_zones in domain_sizes.items()
  33. }
  34. for num_delegations, names in domain_names.items():
  35. for name in names:
  36. # create a domain with name `name` and `num_delegations` delegations
  37. api_user_domain.domain_create(name)
  38. for a in range(0, num_delegations, bulk_block_size): # run block-wise to avoid exceeding max request size
  39. r = api_user_domain.rr_set_create_bulk(
  40. name,
  41. [
  42. {"subname": f'x{i}', "type": "DS", "ttl": 3600, "records": some_ds_records}
  43. for i in range(a, a + bulk_block_size)
  44. ] + [
  45. {"subname": f'x{i}', "type": "NS", "ttl": 3600, "records": ['ns1.test.', 'ns2.test.']}
  46. for i in range(a, a + bulk_block_size)
  47. ]
  48. )
  49. assert r.status_code == 200
  50. # retrieve all SOA RRSIGs
  51. soa_rrsig = {}
  52. for names in domain_names.values():
  53. for name in names:
  54. soa_rrsig[name] = return_eventually(lambda: query_replication(name, "", 'RRSIG', covers='SOA'), timeout=20)
  55. # rotate signatures
  56. faketime_add(7)
  57. # assert SOA RRSIG has been updated
  58. for names in domain_names.values():
  59. for name in names:
  60. assert_eventually(
  61. lambda: soa_rrsig[name] != query_replication(name, "", 'RRSIG', covers='SOA'),
  62. timeout=600, # depending on number of domains in the database, this value requires increase
  63. )