dnsimple 12.1.0 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -3
  3. data/.github/workflows/release.yml +14 -41
  4. data/.github/workflows/sync-test-fixtures.yml +17 -38
  5. data/.rubocop.yml +1 -1
  6. data/.rubocop_todo.yml +3 -41
  7. data/CHANGELOG.md +13 -1
  8. data/Gemfile +1 -1
  9. data/Rakefile +5 -3
  10. data/dnsimple.gemspec +2 -1
  11. data/lib/dnsimple/struct/domain.rb +3 -0
  12. data/lib/dnsimple/struct/domain_price.rb +3 -0
  13. data/lib/dnsimple/struct/domain_registration.rb +3 -0
  14. data/lib/dnsimple/struct/tld.rb +6 -0
  15. data/lib/dnsimple/version.rb +1 -1
  16. data/test/dnsimple/client/accounts_test.rb +33 -0
  17. data/test/dnsimple/client/billing_test.rb +106 -0
  18. data/test/dnsimple/client/certificates_test.rb +506 -0
  19. data/test/dnsimple/client/client_service_test.rb +32 -0
  20. data/test/dnsimple/client/contacts_test.rb +231 -0
  21. data/test/dnsimple/client/dns_analytics_test.rb +102 -0
  22. data/test/dnsimple/client/domains_delegation_signer_records_test.rb +213 -0
  23. data/test/dnsimple/client/domains_dnssec_test.rb +109 -0
  24. data/test/dnsimple/client/domains_email_forwards_test.rb +209 -0
  25. data/test/dnsimple/client/domains_pushes_test.rb +180 -0
  26. data/test/dnsimple/client/domains_research_test.rb +40 -0
  27. data/test/dnsimple/client/domains_test.rb +222 -0
  28. data/test/dnsimple/client/identity_test.rb +52 -0
  29. data/test/dnsimple/client/oauth_test.rb +71 -0
  30. data/test/dnsimple/client/registrar_auto_renewal_test.rb +77 -0
  31. data/test/dnsimple/client/registrar_delegation_test.rb +109 -0
  32. data/test/dnsimple/client/registrar_test.rb +622 -0
  33. data/test/dnsimple/client/registrar_transfer_lock_test.rb +113 -0
  34. data/test/dnsimple/client/registrar_whois_privacy_test.rb +92 -0
  35. data/test/dnsimple/client/services_domains_test.rb +119 -0
  36. data/test/dnsimple/client/services_test.rb +126 -0
  37. data/test/dnsimple/client/templates_domains_test.rb +32 -0
  38. data/test/dnsimple/client/templates_records_test.rb +239 -0
  39. data/test/dnsimple/client/templates_test.rb +224 -0
  40. data/test/dnsimple/client/tlds_test.rb +184 -0
  41. data/test/dnsimple/client/vanity_name_servers_test.rb +58 -0
  42. data/test/dnsimple/client/webhooks_test.rb +149 -0
  43. data/test/dnsimple/client/zones_distributions_test.rb +136 -0
  44. data/test/dnsimple/client/zones_records_test.rb +403 -0
  45. data/test/dnsimple/client/zones_test.rb +271 -0
  46. data/test/dnsimple/client_test.rb +210 -0
  47. data/test/dnsimple/extra_test.rb +38 -0
  48. data/test/dnsimple/options/base_test.rb +23 -0
  49. data/test/dnsimple/options/list_options_test.rb +95 -0
  50. data/{spec → test}/fixtures.http/checkDomain/success.http +1 -1
  51. data/{spec → test}/fixtures.http/getDomain/success.http +1 -1
  52. data/{spec → test}/fixtures.http/getDomainPrices/success.http +1 -1
  53. data/{spec → test}/fixtures.http/getDomainRegistration/success.http +1 -1
  54. data/{spec → test}/fixtures.http/getTld/success.http +1 -1
  55. data/{spec → test}/fixtures.http/listTlds/success.http +1 -1
  56. data/{spec → test}/fixtures.http/registerDomain/success.http +1 -1
  57. data/test/test_helper.rb +35 -0
  58. metadata +216 -205
  59. data/.rspec +0 -1
  60. data/spec/dnsimple/client/accounts_spec.rb +0 -33
  61. data/spec/dnsimple/client/billing_spec.rb +0 -101
  62. data/spec/dnsimple/client/certificates_spec.rb +0 -452
  63. data/spec/dnsimple/client/client_service_spec.rb +0 -41
  64. data/spec/dnsimple/client/contacts_spec.rb +0 -228
  65. data/spec/dnsimple/client/dns_analytics_spec.rb +0 -84
  66. data/spec/dnsimple/client/domains_delegation_signer_records_spec.rb +0 -212
  67. data/spec/dnsimple/client/domains_dnssec_spec.rb +0 -124
  68. data/spec/dnsimple/client/domains_email_forwards_spec.rb +0 -210
  69. data/spec/dnsimple/client/domains_pushes_spec.rb +0 -164
  70. data/spec/dnsimple/client/domains_research_spec.rb +0 -38
  71. data/spec/dnsimple/client/domains_spec.rb +0 -206
  72. data/spec/dnsimple/client/identity_spec.rb +0 -58
  73. data/spec/dnsimple/client/oauth_spec.rb +0 -82
  74. data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +0 -82
  75. data/spec/dnsimple/client/registrar_delegation_spec.rb +0 -109
  76. data/spec/dnsimple/client/registrar_spec.rb +0 -627
  77. data/spec/dnsimple/client/registrar_transfer_lock_spec.rb +0 -118
  78. data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +0 -94
  79. data/spec/dnsimple/client/services_domains_spec.rb +0 -115
  80. data/spec/dnsimple/client/services_spec.rb +0 -111
  81. data/spec/dnsimple/client/templates_domains_spec.rb +0 -34
  82. data/spec/dnsimple/client/templates_records_spec.rb +0 -228
  83. data/spec/dnsimple/client/templates_spec.rb +0 -218
  84. data/spec/dnsimple/client/tlds_spec.rb +0 -163
  85. data/spec/dnsimple/client/vanity_name_servers_spec.rb +0 -56
  86. data/spec/dnsimple/client/webhooks_spec.rb +0 -150
  87. data/spec/dnsimple/client/zones_distributions_spec.rb +0 -137
  88. data/spec/dnsimple/client/zones_records_spec.rb +0 -414
  89. data/spec/dnsimple/client/zones_spec.rb +0 -261
  90. data/spec/dnsimple/client_spec.rb +0 -225
  91. data/spec/dnsimple/extra_spec.rb +0 -48
  92. data/spec/dnsimple/options/base_spec.rb +0 -24
  93. data/spec/dnsimple/options/list_options_spec.rb +0 -102
  94. data/spec/spec_helper.rb +0 -17
  95. data/spec/support/helpers.rb +0 -15
  96. data/spec/support/webmock.rb +0 -13
  97. /data/{spec → test}/fixtures.http/acceptPush/success.http +0 -0
  98. /data/{spec → test}/fixtures.http/accounts/success-account.http +0 -0
  99. /data/{spec → test}/fixtures.http/accounts/success-user.http +0 -0
  100. /data/{spec → test}/fixtures.http/activateZoneService/success.http +0 -0
  101. /data/{spec → test}/fixtures.http/appliedServices/success.http +0 -0
  102. /data/{spec → test}/fixtures.http/applyService/success.http +0 -0
  103. /data/{spec → test}/fixtures.http/applyTemplate/success.http +0 -0
  104. /data/{spec → test}/fixtures.http/authorizeDomainTransferOut/success.http +0 -0
  105. /data/{spec → test}/fixtures.http/badgateway.http +0 -0
  106. /data/{spec → test}/fixtures.http/batchChangeZoneRecords/error_400_create_validation_failed.http +0 -0
  107. /data/{spec → test}/fixtures.http/batchChangeZoneRecords/error_400_delete_validation_failed.http +0 -0
  108. /data/{spec → test}/fixtures.http/batchChangeZoneRecords/error_400_update_validation_failed.http +0 -0
  109. /data/{spec → test}/fixtures.http/batchChangeZoneRecords/success.http +0 -0
  110. /data/{spec → test}/fixtures.http/cancelDomainTransfer/success.http +0 -0
  111. /data/{spec → test}/fixtures.http/changeDomainDelegation/success.http +0 -0
  112. /data/{spec → test}/fixtures.http/changeDomainDelegationFromVanity/success.http +0 -0
  113. /data/{spec → test}/fixtures.http/changeDomainDelegationToVanity/success.http +0 -0
  114. /data/{spec → test}/fixtures.http/checkRegistrantChange/error-contactnotfound.http +0 -0
  115. /data/{spec → test}/fixtures.http/checkRegistrantChange/error-domainnotfound.http +0 -0
  116. /data/{spec → test}/fixtures.http/checkRegistrantChange/success.http +0 -0
  117. /data/{spec → test}/fixtures.http/checkZoneDistribution/error.http +0 -0
  118. /data/{spec → test}/fixtures.http/checkZoneDistribution/failure.http +0 -0
  119. /data/{spec → test}/fixtures.http/checkZoneDistribution/success.http +0 -0
  120. /data/{spec → test}/fixtures.http/checkZoneRecordDistribution/error.http +0 -0
  121. /data/{spec → test}/fixtures.http/checkZoneRecordDistribution/failure.http +0 -0
  122. /data/{spec → test}/fixtures.http/checkZoneRecordDistribution/success.http +0 -0
  123. /data/{spec → test}/fixtures.http/createContact/created.http +0 -0
  124. /data/{spec → test}/fixtures.http/createContact/error-validation-errors.http +0 -0
  125. /data/{spec → test}/fixtures.http/createDelegationSignerRecord/created.http +0 -0
  126. /data/{spec → test}/fixtures.http/createDelegationSignerRecord/validation-error.http +0 -0
  127. /data/{spec → test}/fixtures.http/createDomain/created.http +0 -0
  128. /data/{spec → test}/fixtures.http/createEmailForward/created.http +0 -0
  129. /data/{spec → test}/fixtures.http/createPrimaryServer/created.http +0 -0
  130. /data/{spec → test}/fixtures.http/createRegistrantChange/success.http +0 -0
  131. /data/{spec → test}/fixtures.http/createSecondaryZone/created.http +0 -0
  132. /data/{spec → test}/fixtures.http/createTemplate/created.http +0 -0
  133. /data/{spec → test}/fixtures.http/createTemplateRecord/created.http +0 -0
  134. /data/{spec → test}/fixtures.http/createWebhook/created.http +0 -0
  135. /data/{spec → test}/fixtures.http/createZoneRecord/created-apex.http +0 -0
  136. /data/{spec → test}/fixtures.http/createZoneRecord/created.http +0 -0
  137. /data/{spec → test}/fixtures.http/deactivateZoneService/success.http +0 -0
  138. /data/{spec → test}/fixtures.http/deleteContact/error-contact-in-use.http +0 -0
  139. /data/{spec → test}/fixtures.http/deleteContact/success.http +0 -0
  140. /data/{spec → test}/fixtures.http/deleteDelegationSignerRecord/success.http +0 -0
  141. /data/{spec → test}/fixtures.http/deleteDomain/success.http +0 -0
  142. /data/{spec → test}/fixtures.http/deleteEmailForward/success.http +0 -0
  143. /data/{spec → test}/fixtures.http/deleteRegistrantChange/success.http +0 -0
  144. /data/{spec → test}/fixtures.http/deleteRegistrantChange/success_async.http +0 -0
  145. /data/{spec → test}/fixtures.http/deleteTemplate/success.http +0 -0
  146. /data/{spec → test}/fixtures.http/deleteTemplateRecord/success.http +0 -0
  147. /data/{spec → test}/fixtures.http/deleteWebhook/success.http +0 -0
  148. /data/{spec → test}/fixtures.http/deleteZoneRecord/success.http +0 -0
  149. /data/{spec → test}/fixtures.http/disableDnssec/not-enabled.http +0 -0
  150. /data/{spec → test}/fixtures.http/disableDnssec/success.http +0 -0
  151. /data/{spec → test}/fixtures.http/disableDomainAutoRenewal/success.http +0 -0
  152. /data/{spec → test}/fixtures.http/disableDomainTransferLock/success.http +0 -0
  153. /data/{spec → test}/fixtures.http/disableVanityNameServers/success.http +0 -0
  154. /data/{spec → test}/fixtures.http/disableWhoisPrivacy/success.http +0 -0
  155. /data/{spec → test}/fixtures.http/dnsAnalytics/success.http +0 -0
  156. /data/{spec → test}/fixtures.http/downloadCertificate/success.http +0 -0
  157. /data/{spec → test}/fixtures.http/enableDnssec/success.http +0 -0
  158. /data/{spec → test}/fixtures.http/enableDomainAutoRenewal/success.http +0 -0
  159. /data/{spec → test}/fixtures.http/enableDomainTransferLock/success.http +0 -0
  160. /data/{spec → test}/fixtures.http/enableVanityNameServers/success.http +0 -0
  161. /data/{spec → test}/fixtures.http/enableWhoisPrivacy/created.http +0 -0
  162. /data/{spec → test}/fixtures.http/enableWhoisPrivacy/success.http +0 -0
  163. /data/{spec → test}/fixtures.http/getCertificate/success.http +0 -0
  164. /data/{spec → test}/fixtures.http/getCertificatePrivateKey/success.http +0 -0
  165. /data/{spec → test}/fixtures.http/getContact/success.http +0 -0
  166. /data/{spec → test}/fixtures.http/getDelegationSignerRecord/success.http +0 -0
  167. /data/{spec → test}/fixtures.http/getDnssec/success.http +0 -0
  168. /data/{spec → test}/fixtures.http/getDomainDelegation/success-empty.http +0 -0
  169. /data/{spec → test}/fixtures.http/getDomainDelegation/success.http +0 -0
  170. /data/{spec → test}/fixtures.http/getDomainPrices/failure.http +0 -0
  171. /data/{spec → test}/fixtures.http/getDomainRenewal/success.http +0 -0
  172. /data/{spec → test}/fixtures.http/getDomainRestore/success.http +0 -0
  173. /data/{spec → test}/fixtures.http/getDomainTransfer/success.http +0 -0
  174. /data/{spec → test}/fixtures.http/getDomainTransferLock/success.http +0 -0
  175. /data/{spec → test}/fixtures.http/getDomainsResearchStatus/error-validation.http +0 -0
  176. /data/{spec → test}/fixtures.http/getDomainsResearchStatus/success-available.http +0 -0
  177. /data/{spec → test}/fixtures.http/getDomainsResearchStatus/success-unavailable.http +0 -0
  178. /data/{spec → test}/fixtures.http/getDomainsResearchStatus/success-unsupported-tld.http +0 -0
  179. /data/{spec → test}/fixtures.http/getEmailForward/success.http +0 -0
  180. /data/{spec → test}/fixtures.http/getPrimaryServer/success.http +0 -0
  181. /data/{spec → test}/fixtures.http/getRegistrantChange/success.http +0 -0
  182. /data/{spec → test}/fixtures.http/getService/success.http +0 -0
  183. /data/{spec → test}/fixtures.http/getTemplate/success.http +0 -0
  184. /data/{spec → test}/fixtures.http/getTemplateRecord/success.http +0 -0
  185. /data/{spec → test}/fixtures.http/getTldExtendedAttributes/success-attributes.http +0 -0
  186. /data/{spec → test}/fixtures.http/getTldExtendedAttributes/success-noattributes.http +0 -0
  187. /data/{spec → test}/fixtures.http/getTldExtendedAttributes/success.http +0 -0
  188. /data/{spec → test}/fixtures.http/getWebhook/success.http +0 -0
  189. /data/{spec → test}/fixtures.http/getZone/success.http +0 -0
  190. /data/{spec → test}/fixtures.http/getZoneFile/success.http +0 -0
  191. /data/{spec → test}/fixtures.http/getZoneRecord/success.http +0 -0
  192. /data/{spec → test}/fixtures.http/initiatePush/success.http +0 -0
  193. /data/{spec → test}/fixtures.http/issueLetsencryptCertificate/success.http +0 -0
  194. /data/{spec → test}/fixtures.http/issueRenewalLetsencryptCertificate/success.http +0 -0
  195. /data/{spec → test}/fixtures.http/linkPrimaryServer/success.http +0 -0
  196. /data/{spec → test}/fixtures.http/listAccounts/success-account.http +0 -0
  197. /data/{spec → test}/fixtures.http/listAccounts/success-user.http +0 -0
  198. /data/{spec → test}/fixtures.http/listCertificates/success.http +0 -0
  199. /data/{spec → test}/fixtures.http/listCharges/fail-400-bad-filter.http +0 -0
  200. /data/{spec → test}/fixtures.http/listCharges/fail-403.http +0 -0
  201. /data/{spec → test}/fixtures.http/listCharges/success.http +0 -0
  202. /data/{spec → test}/fixtures.http/listContacts/success.http +0 -0
  203. /data/{spec → test}/fixtures.http/listDelegationSignerRecords/success.http +0 -0
  204. /data/{spec → test}/fixtures.http/listDomains/success.http +0 -0
  205. /data/{spec → test}/fixtures.http/listEmailForwards/success.http +0 -0
  206. /data/{spec → test}/fixtures.http/listPrimaryServers/success.http +0 -0
  207. /data/{spec → test}/fixtures.http/listPushes/success.http +0 -0
  208. /data/{spec → test}/fixtures.http/listRegistrantChanges/success.http +0 -0
  209. /data/{spec → test}/fixtures.http/listServices/success.http +0 -0
  210. /data/{spec → test}/fixtures.http/listTemplateRecords/success.http +0 -0
  211. /data/{spec → test}/fixtures.http/listTemplates/success.http +0 -0
  212. /data/{spec → test}/fixtures.http/listWebhooks/success.http +0 -0
  213. /data/{spec → test}/fixtures.http/listZoneRecords/success.http +0 -0
  214. /data/{spec → test}/fixtures.http/listZones/success.http +0 -0
  215. /data/{spec → test}/fixtures.http/method-not-allowed.http +0 -0
  216. /data/{spec → test}/fixtures.http/notfound-certificate.http +0 -0
  217. /data/{spec → test}/fixtures.http/notfound-contact.http +0 -0
  218. /data/{spec → test}/fixtures.http/notfound-delegationSignerRecord.http +0 -0
  219. /data/{spec → test}/fixtures.http/notfound-domain.http +0 -0
  220. /data/{spec → test}/fixtures.http/notfound-domainpush.http +0 -0
  221. /data/{spec → test}/fixtures.http/notfound-emailforward.http +0 -0
  222. /data/{spec → test}/fixtures.http/notfound-record.http +0 -0
  223. /data/{spec → test}/fixtures.http/notfound-template.http +0 -0
  224. /data/{spec → test}/fixtures.http/notfound-webhook.http +0 -0
  225. /data/{spec → test}/fixtures.http/notfound-whoisprivacy.http +0 -0
  226. /data/{spec → test}/fixtures.http/notfound-zone.http +0 -0
  227. /data/{spec → test}/fixtures.http/oauthAccessToken/error-invalid-request.http +0 -0
  228. /data/{spec → test}/fixtures.http/oauthAccessToken/success.http +0 -0
  229. /data/{spec → test}/fixtures.http/pages-1of3.http +0 -0
  230. /data/{spec → test}/fixtures.http/pages-2of3.http +0 -0
  231. /data/{spec → test}/fixtures.http/pages-3of3.http +0 -0
  232. /data/{spec → test}/fixtures.http/purchaseLetsencryptCertificate/success.http +0 -0
  233. /data/{spec → test}/fixtures.http/purchaseRenewalLetsencryptCertificate/success.http +0 -0
  234. /data/{spec → test}/fixtures.http/registerDomain/error-extended-attributes.http +0 -0
  235. /data/{spec → test}/fixtures.http/rejectPush/success.http +0 -0
  236. /data/{spec → test}/fixtures.http/renewDomain/error-tooearly.http +0 -0
  237. /data/{spec → test}/fixtures.http/renewDomain/success.http +0 -0
  238. /data/{spec → test}/fixtures.http/response.http +0 -0
  239. /data/{spec → test}/fixtures.http/restoreDomain/success.http +0 -0
  240. /data/{spec → test}/fixtures.http/success-with-malformed-json.http +0 -0
  241. /data/{spec → test}/fixtures.http/transferDomain/error-indnsimple.http +0 -0
  242. /data/{spec → test}/fixtures.http/transferDomain/error-missing-authcode.http +0 -0
  243. /data/{spec → test}/fixtures.http/transferDomain/success.http +0 -0
  244. /data/{spec → test}/fixtures.http/unapplyService/success.http +0 -0
  245. /data/{spec → test}/fixtures.http/unlinkPrimaryServer/success.http +0 -0
  246. /data/{spec → test}/fixtures.http/updateContact/success.http +0 -0
  247. /data/{spec → test}/fixtures.http/updateTemplate/success.http +0 -0
  248. /data/{spec → test}/fixtures.http/updateZoneNsRecords/success.http +0 -0
  249. /data/{spec → test}/fixtures.http/updateZoneRecord/success.http +0 -0
  250. /data/{spec → test}/fixtures.http/validation-error.http +0 -0
  251. /data/{spec → test}/fixtures.http/whoami/success-account.http +0 -0
  252. /data/{spec → test}/fixtures.http/whoami/success-user.http +0 -0
  253. /data/{spec → test}/fixtures.http/whoami/success.http +0 -0
@@ -0,0 +1,506 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class CertificatesTest < Minitest::Test
6
+ def setup
7
+ @subject = Dnsimple::Client.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").certificates
8
+ @account_id = 1010
9
+ end
10
+
11
+
12
+ test "certificates builds the correct request" do
13
+ domain_id = "example.com"
14
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
15
+ .to_return(read_http_fixture("listCertificates/success.http"))
16
+
17
+ @subject.certificates(@account_id, domain_id)
18
+
19
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates",
20
+ headers: { "Accept" => "application/json" })
21
+ end
22
+
23
+ test "certificates supports pagination" do
24
+ domain_id = "example.com"
25
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
26
+ .to_return(read_http_fixture("listCertificates/success.http"))
27
+
28
+ @subject.certificates(@account_id, domain_id, page: 2)
29
+
30
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates?page=2")
31
+ end
32
+
33
+ test "certificates supports extra request options" do
34
+ domain_id = "example.com"
35
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
36
+ .to_return(read_http_fixture("listCertificates/success.http"))
37
+
38
+ @subject.certificates(@account_id, domain_id, query: { foo: "bar" })
39
+
40
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates?foo=bar")
41
+ end
42
+
43
+ test "certificates returns the certificates" do
44
+ domain_id = "example.com"
45
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
46
+ .to_return(read_http_fixture("listCertificates/success.http"))
47
+
48
+ response = @subject.certificates(@account_id, domain_id)
49
+
50
+ assert_kind_of(Dnsimple::PaginatedResponse, response)
51
+ assert_kind_of(Array, response.data)
52
+ assert_equal(2, response.data.size)
53
+
54
+ response.data.each do |result|
55
+ assert_kind_of(Dnsimple::Struct::Certificate, result)
56
+ assert_kind_of(Integer, result.id)
57
+ end
58
+ end
59
+
60
+ test "certificates exposes the pagination information" do
61
+ domain_id = "example.com"
62
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
63
+ .to_return(read_http_fixture("listCertificates/success.http"))
64
+
65
+ response = @subject.certificates(@account_id, domain_id)
66
+
67
+ assert_respond_to(response, :page)
68
+ assert_equal(1, response.page)
69
+ assert_kind_of(Integer, response.per_page)
70
+ assert_kind_of(Integer, response.total_entries)
71
+ assert_kind_of(Integer, response.total_pages)
72
+ end
73
+
74
+
75
+ test "all_certificates delegates to client.paginate" do
76
+ domain_id = "dnsimple.us"
77
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
78
+ .to_return(read_http_fixture("listCertificates/success.http"))
79
+
80
+ mock = Minitest::Mock.new
81
+ mock.expect(:call, nil, [:certificates, @account_id, domain_id, { foo: "bar" }])
82
+ @subject.stub(:paginate, mock) do
83
+ @subject.all_certificates(@account_id, domain_id, { foo: "bar" })
84
+ end
85
+ mock.verify
86
+ end
87
+
88
+ test "all_certificates supports sorting" do
89
+ domain_id = "dnsimple.us"
90
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates})
91
+ .to_return(read_http_fixture("listCertificates/success.http"))
92
+
93
+ @subject.all_certificates(@account_id, domain_id, sort: "id:asc,expiration:desc")
94
+
95
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates?page=1&per_page=100&sort=id:asc,expiration:desc")
96
+ end
97
+
98
+
99
+ test "certificate builds the correct request" do
100
+ domain_id = "bingo.pizza"
101
+ certificate_id = 101967
102
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}})
103
+ .to_return(read_http_fixture("getCertificate/success.http"))
104
+
105
+ @subject.certificate(@account_id, domain_id, certificate_id)
106
+
107
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}",
108
+ headers: { "Accept" => "application/json" })
109
+ end
110
+
111
+ test "certificate supports extra request options" do
112
+ domain_id = "bingo.pizza"
113
+ certificate_id = 101967
114
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}})
115
+ .to_return(read_http_fixture("getCertificate/success.http"))
116
+
117
+ @subject.certificate(@account_id, domain_id, certificate_id, query: { foo: "bar" })
118
+
119
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}?foo=bar")
120
+ end
121
+
122
+ test "certificate returns the certificate" do
123
+ domain_id = "bingo.pizza"
124
+ certificate_id = 101967
125
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}})
126
+ .to_return(read_http_fixture("getCertificate/success.http"))
127
+
128
+ response = @subject.certificate(@account_id, domain_id, certificate_id)
129
+
130
+ assert_kind_of(Dnsimple::Response, response)
131
+
132
+ result = response.data
133
+
134
+ assert_kind_of(Dnsimple::Struct::Certificate, result)
135
+ assert_equal(101967, result.id)
136
+ assert_equal(289333, result.domain_id)
137
+ assert_equal(2511, result.contact_id)
138
+ assert_equal("www.bingo.pizza", result.common_name)
139
+ assert_empty(result.alternate_names)
140
+ assert_equal(1, result.years)
141
+ assert_equal("-----BEGIN CERTIFICATE REQUEST-----\nMIICmTCCAYECAQAwGjEYMBYGA1UEAwwPd3d3LmJpbmdvLnBpenphMIIBIjANBgkq\nhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw4+KoZ9IDCK2o5qAQpi+Icu5kksmjQzx\n5o5g4B6XhRxhsfHlK/i3iU5hc8CONjyVv8j82835RNsiKrflnxGa9SH68vbQfcn4\nIpbMz9c+Eqv5h0Euqlc3A4DBzp0unEu5QAUhR6Xu1TZIWDPjhrBOGiszRlLQcp4F\nzy6fD6j5/d/ylpzTp5v54j+Ey31Bz86IaBPtSpHI+Qk87Hs8DVoWxZk/6RlAkyur\nXDGWnPu9n3RMfs9ag5anFhggLIhCNtVN4+0vpgPQ59pqwYo8TfdYzK7WSKeL7geu\nCqVE3bHAqU6dLtgHOZfTkLwGycUh4p9aawuc6fsXHHYDpIL8s3vAvwIDAQABoDow\nOAYJKoZIhvcNAQkOMSswKTAnBgNVHREEIDAeggtiaW5nby5waXp6YYIPd3d3LmJp\nbmdvLnBpenphMA0GCSqGSIb3DQEBCwUAA4IBAQBwOLKv+PO5hSJkgqS6wL/wRqLh\nQ1zbcHRHAjRjnpRz06cDvN3X3aPI+lpKSNFCI0A1oKJG7JNtgxX3Est66cuO8ESQ\nPIb6WWN7/xlVlBCe7ZkjAFgN6JurFdclwCp/NI5wBCwj1yb3Ar5QQMFIZOezIgTI\nAWkQSfCmgkB96d6QlDWgidYDDjcsXugQveOQRPlHr0TsElu47GakxZdJCFZU+WPM\nodQQf5SaqiIK2YaH1dWO//4KpTS9QoTy1+mmAa27apHcmz6X6+G5dvpHZ1qH14V0\nJoMWIK+39HRPq6mDo1UMVet/xFUUrG/H7/tFlYIDVbSpVlpVAFITd/eQkaW/\n-----END CERTIFICATE REQUEST-----\n", result.csr)
142
+ assert_equal("issued", result.state)
143
+ assert_equal("letsencrypt", result.authority_identifier)
144
+ refute(result.auto_renew)
145
+ assert_equal("2020-06-18T18:54:17Z", result.created_at)
146
+ assert_equal("2020-06-18T19:10:14Z", result.updated_at)
147
+ assert_equal("2020-09-16T18:10:13Z", result.expires_at)
148
+ end
149
+
150
+ test "certificate raises NotFoundError when the certificate does not exist" do
151
+ domain_id = "bingo.pizza"
152
+ certificate_id = 101967
153
+ stub_request(:get, %r{/v2})
154
+ .to_return(read_http_fixture("notfound-certificate.http"))
155
+
156
+ assert_raises(Dnsimple::NotFoundError) do
157
+ @subject.certificate(@account_id, domain_id, certificate_id)
158
+ end
159
+ end
160
+
161
+
162
+ test "download_certificate builds the correct request" do
163
+ domain_id = "weppos.net"
164
+ certificate_id = 1
165
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/download})
166
+ .to_return(read_http_fixture("downloadCertificate/success.http"))
167
+
168
+ @subject.download_certificate(@account_id, domain_id, certificate_id)
169
+
170
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/download",
171
+ headers: { "Accept" => "application/json" })
172
+ end
173
+
174
+ test "download_certificate supports extra request options" do
175
+ domain_id = "weppos.net"
176
+ certificate_id = 1
177
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/download})
178
+ .to_return(read_http_fixture("downloadCertificate/success.http"))
179
+
180
+ @subject.download_certificate(@account_id, domain_id, certificate_id, query: { foo: "bar" })
181
+
182
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/download?foo=bar")
183
+ end
184
+
185
+ test "download_certificate returns the certificate bundle" do
186
+ domain_id = "weppos.net"
187
+ certificate_id = 1
188
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/download})
189
+ .to_return(read_http_fixture("downloadCertificate/success.http"))
190
+
191
+ response = @subject.download_certificate(@account_id, domain_id, certificate_id)
192
+
193
+ assert_kind_of(Dnsimple::Response, response)
194
+
195
+ result = response.data
196
+
197
+ assert_kind_of(Dnsimple::Struct::CertificateBundle, result)
198
+ assert_nil(result.private_key)
199
+ assert_equal("-----BEGIN CERTIFICATE-----\nMIIE7TCCA9WgAwIBAgITAPpTe4O3vjuQ9L4gLsogi/ukujANBgkqhkiG9w0BAQsF\nADAiMSAwHgYDVQQDDBdGYWtlIExFIEludGVybWVkaWF0ZSBYMTAeFw0xNjA2MTEx\nNzQ4MDBaFw0xNjA5MDkxNzQ4MDBaMBkxFzAVBgNVBAMTDnd3dy53ZXBwb3MubmV0\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtzCcMfWoQRt5AMEY0HUb\n2GaraL1GsWOo6YXdPfe+YDvtnmDw23NcoTX7VSeCgU9M3RKs19AsCJcRNTLJ2dmD\nrAuyCTud9YTAaXQcTOLUhtO8T8+9AFVIva2OmAlKCR5saBW3JaRxW7V2aHEd/d1s\ns1CvNOO7jNppc9NwGSnDHcn3rqNv/U3MaU0gpJJRqsKkvcLU6IHJGgxyQ6AbpwJD\nIqBnzkjHu2IuhGEbRuMjyWLA2qtsjyVlfPotDxUdVouUQpz7dGHUFrLR7ma8QAYu\nOfl1ZMyrc901HGMa7zwbnFWurs3fed7vAosTRZIjnn72/3Wo7L9RiMB+vwr3NX7c\n9QIDAQABo4ICIzCCAh8wDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUF\nBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRh9q/3Zxbk4yA/\nt7j+8xA+rkiZBTAfBgNVHSMEGDAWgBTAzANGuVggzFxycPPhLssgpvVoOjB4Bggr\nBgEFBQcBAQRsMGowMwYIKwYBBQUHMAGGJ2h0dHA6Ly9vY3NwLnN0Zy1pbnQteDEu\nbGV0c2VuY3J5cHQub3JnLzAzBggrBgEFBQcwAoYnaHR0cDovL2NlcnQuc3RnLWlu\ndC14MS5sZXRzZW5jcnlwdC5vcmcvMCUGA1UdEQQeMByCCndlcHBvcy5uZXSCDnd3\ndy53ZXBwb3MubmV0MIH+BgNVHSAEgfYwgfMwCAYGZ4EMAQIBMIHmBgsrBgEEAYLf\nEwEBATCB1jAmBggrBgEFBQcCARYaaHR0cDovL2Nwcy5sZXRzZW5jcnlwdC5vcmcw\ngasGCCsGAQUFBwICMIGeDIGbVGhpcyBDZXJ0aWZpY2F0ZSBtYXkgb25seSBiZSBy\nZWxpZWQgdXBvbiBieSBSZWx5aW5nIFBhcnRpZXMgYW5kIG9ubHkgaW4gYWNjb3Jk\nYW5jZSB3aXRoIHRoZSBDZXJ0aWZpY2F0ZSBQb2xpY3kgZm91bmQgYXQgaHR0cHM6\nLy9sZXRzZW5jcnlwdC5vcmcvcmVwb3NpdG9yeS8wDQYJKoZIhvcNAQELBQADggEB\nAEqMdWrmdIyQxthWsX3iHmM2h/wXwEesD0VIaA+Pq4mjwmKBkoPSmHGQ/O4v8RaK\nB6gl8v+qmvCwwqC1SkBmm+9C2yt/P6WhAiA/DD+WppYgJWfcz2lEKrgufFlHPukB\nDzE0mJDuXm09QTApWlaTZWYfWKY50T5uOT/rs+OwGFFCO/8o7v5AZRAHos6uzjvq\nAtFZj/FEnXXMjSSlQ7YKTXToVpnAYH4e3/UMsi6/O4orkVz82ZfhKwMWHV8dXlRw\ntQaemFWTjGPgSLXJAtQO30DgNJBHX/fJEaHv6Wy8TF3J0wOGpzGbOwaTX8YAmEzC\nlzzjs+clg5MN5rd1g4POJtU=\n-----END CERTIFICATE-----\n", result.server_certificate)
200
+ assert_nil(result.root_certificate)
201
+ assert_equal(["-----BEGIN CERTIFICATE-----\nMIIEqzCCApOgAwIBAgIRAIvhKg5ZRO08VGQx8JdhT+UwDQYJKoZIhvcNAQELBQAw\nGjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDUyMzIyMDc1OVoXDTM2\nMDUyMzIyMDc1OVowIjEgMB4GA1UEAwwXRmFrZSBMRSBJbnRlcm1lZGlhdGUgWDEw\nggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtWKySDn7rWZc5ggjz3ZB0\n8jO4xti3uzINfD5sQ7Lj7hzetUT+wQob+iXSZkhnvx+IvdbXF5/yt8aWPpUKnPym\noLxsYiI5gQBLxNDzIec0OIaflWqAr29m7J8+NNtApEN8nZFnf3bhehZW7AxmS1m0\nZnSsdHw0Fw+bgixPg2MQ9k9oefFeqa+7Kqdlz5bbrUYV2volxhDFtnI4Mh8BiWCN\nxDH1Hizq+GKCcHsinDZWurCqder/afJBnQs+SBSL6MVApHt+d35zjBD92fO2Je56\ndhMfzCgOKXeJ340WhW3TjD1zqLZXeaCyUNRnfOmWZV8nEhtHOFbUCU7r/KkjMZO9\nAgMBAAGjgeMwgeAwDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAw\nHQYDVR0OBBYEFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHoGCCsGAQUFBwEBBG4wbDA0\nBggrBgEFBQcwAYYoaHR0cDovL29jc3Auc3RnLXJvb3QteDEubGV0c2VuY3J5cHQu\nb3JnLzA0BggrBgEFBQcwAoYoaHR0cDovL2NlcnQuc3RnLXJvb3QteDEubGV0c2Vu\nY3J5cHQub3JnLzAfBgNVHSMEGDAWgBTBJnSkikSg5vogKNhcI5pFiBh54DANBgkq\nhkiG9w0BAQsFAAOCAgEABYSu4Il+fI0MYU42OTmEj+1HqQ5DvyAeyCA6sGuZdwjF\nUGeVOv3NnLyfofuUOjEbY5irFCDtnv+0ckukUZN9lz4Q2YjWGUpW4TTu3ieTsaC9\nAFvCSgNHJyWSVtWvB5XDxsqawl1KzHzzwr132bF2rtGtazSqVqK9E07sGHMCf+zp\nDQVDVVGtqZPHwX3KqUtefE621b8RI6VCl4oD30Olf8pjuzG4JKBFRFclzLRjo/h7\nIkkfjZ8wDa7faOjVXx6n+eUQ29cIMCzr8/rNWHS9pYGGQKJiY2xmVC9h12H99Xyf\nzWE9vb5zKP3MVG6neX1hSdo7PEAb9fqRhHkqVsqUvJlIRmvXvVKTwNCP3eCjRCCI\nPTAvjV+4ni786iXwwFYNz8l3PmPLCyQXWGohnJ8iBm+5nk7O2ynaPVW0U2W+pt2w\nSVuvdDM5zGv2f9ltNWUiYZHJ1mmO97jSY/6YfdOUH66iRtQtDkHBRdkNBsMbD+Em\n2TgBldtHNSJBfB3pm9FblgOcJ0FSWcUDWJ7vO0+NTXlgrRofRT6pVywzxVo6dND0\nWzYlTWeUVsO40xJqhgUQRER9YLOLxJ0O6C8i0xFxAMKOtSdodMB3RIwt7RFQ0uyt\nn5Z5MqkYhlMI3J1tPRTp1nEt9fyGspBOO05gi148Qasp+3N+svqKomoQglNoAxU=\n-----END CERTIFICATE-----"], result.intermediate_certificates)
202
+ end
203
+
204
+ test "download_certificate raises NotFoundError when the certificate does not exist" do
205
+ domain_id = "weppos.net"
206
+ certificate_id = 1
207
+ stub_request(:get, %r{/v2})
208
+ .to_return(read_http_fixture("notfound-certificate.http"))
209
+
210
+ assert_raises(Dnsimple::NotFoundError) do
211
+ @subject.download_certificate(@account_id, domain_id, certificate_id)
212
+ end
213
+ end
214
+
215
+
216
+ test "certificate_private_key builds the correct request" do
217
+ domain_id = "weppos.net"
218
+ certificate_id = 1
219
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/private_key})
220
+ .to_return(read_http_fixture("getCertificatePrivateKey/success.http"))
221
+
222
+ @subject.certificate_private_key(@account_id, domain_id, certificate_id)
223
+
224
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/private_key",
225
+ headers: { "Accept" => "application/json" })
226
+ end
227
+
228
+ test "certificate_private_key supports extra request options" do
229
+ domain_id = "weppos.net"
230
+ certificate_id = 1
231
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/private_key})
232
+ .to_return(read_http_fixture("getCertificatePrivateKey/success.http"))
233
+
234
+ @subject.certificate_private_key(@account_id, domain_id, certificate_id, query: { foo: "bar" })
235
+
236
+ assert_requested(:get, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/private_key?foo=bar")
237
+ end
238
+
239
+ test "certificate_private_key returns the certificate bundle" do
240
+ domain_id = "weppos.net"
241
+ certificate_id = 1
242
+ stub_request(:get, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/#{certificate_id}/private_key})
243
+ .to_return(read_http_fixture("getCertificatePrivateKey/success.http"))
244
+
245
+ response = @subject.certificate_private_key(@account_id, domain_id, certificate_id)
246
+
247
+ assert_kind_of(Dnsimple::Response, response)
248
+
249
+ result = response.data
250
+
251
+ assert_kind_of(Dnsimple::Struct::CertificateBundle, result)
252
+ assert_equal("-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAtzCcMfWoQRt5AMEY0HUb2GaraL1GsWOo6YXdPfe+YDvtnmDw\n23NcoTX7VSeCgU9M3RKs19AsCJcRNTLJ2dmDrAuyCTud9YTAaXQcTOLUhtO8T8+9\nAFVIva2OmAlKCR5saBW3JaRxW7V2aHEd/d1ss1CvNOO7jNppc9NwGSnDHcn3rqNv\n/U3MaU0gpJJRqsKkvcLU6IHJGgxyQ6AbpwJDIqBnzkjHu2IuhGEbRuMjyWLA2qts\njyVlfPotDxUdVouUQpz7dGHUFrLR7ma8QAYuOfl1ZMyrc901HGMa7zwbnFWurs3f\ned7vAosTRZIjnn72/3Wo7L9RiMB+vwr3NX7c9QIDAQABAoIBAEQx32OlzK34GTKT\nr7Yicmw7xEGofIGa1Q2h3Lut13whsxKLif5X0rrcyqRnoeibacS+qXXrJolIG4rP\nTl8/3wmUDQHs5J+6fJqFM+fXZUCP4AFiFzzhgsPBsVyd0KbWYYrZ0qU7s0ttoRe+\nTGjuHgIe3ip1QKNtx2Xr50YmytDydknmro79J5Gfrub1l2iA8SDm1eBrQ4SFaNQ2\nU709pHeSwX8pTihUX2Zy0ifpr0O1wYQjGLneMoG4rrNQJG/z6iUdhYczwwt1kDRQ\n4WkM2sovFOyxbBfoCQ3Gy/eem7OXfjNKUe47DAVLnPkKbqL/3Lo9FD7kcB8K87Ap\nr/vYrl0CgYEA413RAk7571w5dM+VftrdbFZ+Yi1OPhUshlPSehavro8kMGDEG5Ts\n74wEz2X3cfMxauMpMrBk/XnUCZ20AnWQClK73RB5fzPw5XNv473Tt/AFmt7eLOzl\nOcYrhpEHegtsD/ZaljlGtPqsjQAL9Ijhao03m1cGB1+uxI7FgacdckcCgYEAzkKP\n6xu9+WqOol73cnlYPS3sSZssyUF+eqWSzq2YJGRmfr1fbdtHqAS1ZbyC5fZVNZYV\nml1vfXi2LDcU0qS04JazurVyQr2rJZMTlCWVET1vhik7Y87wgCkLwKpbwamPDmlI\n9GY+fLNEa4yfAOOpvpTJpenUScxyKWH2cdYFOOMCgYBhrJnvffINC/d64Pp+BpP8\nyKN+lav5K6t3AWd4H2rVeJS5W7ijiLTIq8QdPNayUyE1o+S8695WrhGTF/aO3+ZD\nKQufikZHiQ7B43d7xL7BVBF0WK3lateGnEVyh7dIjMOdj92Wj4B6mv2pjQ2VvX/p\nAEWVLCtg24/+zL64VgxmXQKBgGosyXj1Zu2ldJcQ28AJxup3YVLilkNje4AXC2No\n6RCSvlAvm5gpcNGE2vvr9lX6YBKdl7FGt8WXBe/sysNEFfgmm45ZKOBCUn+dHk78\nqaeeQHKHdxMBy7utZWdgSqt+ZS299NgaacA3Z9kVIiSLDS4V2VeW7riujXXP/9TJ\nnxaRAoGBAMWXOfNVzfTyrKff6gvDWH+hqNICLyzvkEn2utNY9Q6WwqGuY9fvP/4Z\nXzc48AOBzUr8OeA4sHKJ79sJirOiWHNfD1swtvyVzsFZb6moiNwD3Ce/FzYCa3lQ\nU8blTH/uqpR2pSC6whzJ/lnSdqHUqhyp00000000000000000000\n-----END RSA PRIVATE KEY-----\n", result.private_key)
253
+ assert_nil(result.server_certificate)
254
+ assert_nil(result.root_certificate)
255
+ assert_nil(result.intermediate_certificates)
256
+ end
257
+
258
+ test "certificate_private_key raises NotFoundError when the certificate does not exist" do
259
+ domain_id = "weppos.net"
260
+ certificate_id = 1
261
+ stub_request(:get, %r{/v2})
262
+ .to_return(read_http_fixture("notfound-certificate.http"))
263
+
264
+ assert_raises(Dnsimple::NotFoundError) do
265
+ @subject.certificate_private_key(@account_id, domain_id, certificate_id)
266
+ end
267
+ end
268
+
269
+
270
+ test "purchase_letsencrypt_certificate builds the correct request" do
271
+ domain_id = "bingo.pizza"
272
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt})
273
+ .to_return(read_http_fixture("purchaseLetsencryptCertificate/success.http"))
274
+
275
+ attributes = {}
276
+ @subject.purchase_letsencrypt_certificate(@account_id, domain_id, attributes)
277
+
278
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt",
279
+ body: attributes,
280
+ headers: { "Accept" => "application/json" })
281
+ end
282
+
283
+ test "purchase_letsencrypt_certificate passes extra attributes" do
284
+ domain_id = "bingo.pizza"
285
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt})
286
+ .to_return(read_http_fixture("purchaseLetsencryptCertificate/success.http"))
287
+
288
+ attributes = { name: "www", auto_renew: true, alternate_names: ["api.example.com"] }
289
+ @subject.purchase_letsencrypt_certificate(@account_id, domain_id, attributes)
290
+
291
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt",
292
+ body: attributes,
293
+ headers: { "Accept" => "application/json" })
294
+ end
295
+
296
+ test "purchase_letsencrypt_certificate returns the certificate purchase" do
297
+ domain_id = "bingo.pizza"
298
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt})
299
+ .to_return(read_http_fixture("purchaseLetsencryptCertificate/success.http"))
300
+
301
+ response = @subject.purchase_letsencrypt_certificate(@account_id, domain_id)
302
+
303
+ assert_kind_of(Dnsimple::Response, response)
304
+
305
+ result = response.data
306
+
307
+ assert_kind_of(Dnsimple::Struct::CertificatePurchase, result)
308
+
309
+ assert_equal(101967, result.id)
310
+ assert_equal(101967, result.certificate_id)
311
+ assert_equal("new", result.state)
312
+ refute(result.auto_renew)
313
+ end
314
+
315
+ test "purchase_letsencrypt_certificate raises NotFoundError when the domain does not exist" do
316
+ domain_id = "bingo.pizza"
317
+ stub_request(:post, %r{/v2})
318
+ .to_return(read_http_fixture("notfound-domain.http"))
319
+
320
+ assert_raises(Dnsimple::NotFoundError) do
321
+ @subject.purchase_letsencrypt_certificate(@account_id, domain_id)
322
+ end
323
+ end
324
+
325
+
326
+ test "issue_letsencrypt_certificate builds the correct request" do
327
+ domain_id = "bingo.pizza"
328
+ certificate_id = 101967
329
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/issue})
330
+ .to_return(read_http_fixture("issueLetsencryptCertificate/success.http"))
331
+
332
+ @subject.issue_letsencrypt_certificate(@account_id, domain_id, certificate_id)
333
+
334
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/issue",
335
+ headers: { "Accept" => "application/json" })
336
+ end
337
+
338
+ test "issue_letsencrypt_certificate returns the certificate" do
339
+ domain_id = "bingo.pizza"
340
+ certificate_id = 101967
341
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/issue})
342
+ .to_return(read_http_fixture("issueLetsencryptCertificate/success.http"))
343
+
344
+ response = @subject.issue_letsencrypt_certificate(@account_id, domain_id, certificate_id)
345
+
346
+ assert_kind_of(Dnsimple::Response, response)
347
+
348
+ result = response.data
349
+
350
+ assert_kind_of(Dnsimple::Struct::Certificate, result)
351
+
352
+ assert_equal(101967, result.id)
353
+ assert_equal(289333, result.domain_id)
354
+ assert_equal("www.bingo.pizza", result.common_name)
355
+ assert_empty(result.alternate_names)
356
+ assert_equal(1, result.years)
357
+ assert_nil(result.csr)
358
+ assert_equal("requesting", result.state)
359
+ assert_equal("letsencrypt", result.authority_identifier)
360
+ refute(result.auto_renew)
361
+ end
362
+
363
+ test "issue_letsencrypt_certificate raises NotFoundError when the domain does not exist" do
364
+ domain_id = "bingo.pizza"
365
+ certificate_id = 101967
366
+ stub_request(:post, %r{/v2})
367
+ .to_return(read_http_fixture("notfound-domain.http"))
368
+
369
+ assert_raises(Dnsimple::NotFoundError) do
370
+ @subject.issue_letsencrypt_certificate(@account_id, domain_id, certificate_id)
371
+ end
372
+ end
373
+
374
+ test "issue_letsencrypt_certificate raises NotFoundError when the certificate does not exist" do
375
+ domain_id = "bingo.pizza"
376
+ certificate_id = 101967
377
+ stub_request(:post, %r{/v2})
378
+ .to_return(read_http_fixture("notfound-certificate.http"))
379
+
380
+ assert_raises(Dnsimple::NotFoundError) do
381
+ @subject.issue_letsencrypt_certificate(@account_id, domain_id, certificate_id)
382
+ end
383
+ end
384
+
385
+
386
+ test "purchase_letsencrypt_certificate_renewal builds the correct request" do
387
+ domain_id = "bingo.pizza"
388
+ certificate_id = 101967
389
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals})
390
+ .to_return(read_http_fixture("purchaseRenewalLetsencryptCertificate/success.http"))
391
+
392
+ @subject.purchase_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id)
393
+
394
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals",
395
+ headers: { "Accept" => "application/json" })
396
+ end
397
+
398
+ test "purchase_letsencrypt_certificate_renewal passes extra attributes" do
399
+ domain_id = "bingo.pizza"
400
+ certificate_id = 101967
401
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals})
402
+ .to_return(read_http_fixture("purchaseRenewalLetsencryptCertificate/success.http"))
403
+
404
+ attributes = { auto_renew: true }
405
+ @subject.purchase_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id, attributes)
406
+
407
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals",
408
+ body: attributes,
409
+ headers: { "Accept" => "application/json" })
410
+ end
411
+
412
+ test "purchase_letsencrypt_certificate_renewal returns the certificate renew" do
413
+ domain_id = "bingo.pizza"
414
+ certificate_id = 101967
415
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals})
416
+ .to_return(read_http_fixture("purchaseRenewalLetsencryptCertificate/success.http"))
417
+
418
+ response = @subject.purchase_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id)
419
+
420
+ assert_kind_of(Dnsimple::Response, response)
421
+
422
+ result = response.data
423
+
424
+ assert_kind_of(Dnsimple::Struct::CertificateRenewal, result)
425
+
426
+ assert_equal(65082, result.id)
427
+ assert_equal(certificate_id, result.old_certificate_id)
428
+ assert_equal(101972, result.new_certificate_id)
429
+ assert_equal("new", result.state)
430
+ end
431
+
432
+ test "purchase_letsencrypt_certificate_renewal raises NotFoundError when the domain does not exist" do
433
+ domain_id = "bingo.pizza"
434
+ certificate_id = 101967
435
+ stub_request(:post, %r{/v2})
436
+ .to_return(read_http_fixture("notfound-domain.http"))
437
+
438
+ assert_raises(Dnsimple::NotFoundError) do
439
+ @subject.purchase_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id)
440
+ end
441
+ end
442
+
443
+
444
+ test "issue_letsencrypt_certificate_renewal builds the correct request" do
445
+ domain_id = "bingo.pizza"
446
+ certificate_id = 101972
447
+ certificate_renewal_id = 65082
448
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals/#{certificate_renewal_id}/issue})
449
+ .to_return(read_http_fixture("issueRenewalLetsencryptCertificate/success.http"))
450
+
451
+ @subject.issue_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id, certificate_renewal_id)
452
+
453
+ assert_requested(:post, "https://api.dnsimple.test/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals/#{certificate_renewal_id}/issue",
454
+ headers: { "Accept" => "application/json" })
455
+ end
456
+
457
+ test "issue_letsencrypt_certificate_renewal returns the certificate" do
458
+ domain_id = "bingo.pizza"
459
+ certificate_id = 101972
460
+ certificate_renewal_id = 65082
461
+ stub_request(:post, %r{/v2/#{@account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals/#{certificate_renewal_id}/issue})
462
+ .to_return(read_http_fixture("issueRenewalLetsencryptCertificate/success.http"))
463
+
464
+ response = @subject.issue_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id, certificate_renewal_id)
465
+
466
+ assert_kind_of(Dnsimple::Response, response)
467
+
468
+ result = response.data
469
+
470
+ assert_kind_of(Dnsimple::Struct::Certificate, result)
471
+
472
+ assert_equal(101972, result.id)
473
+ assert_equal(289333, result.domain_id)
474
+ assert_equal("www.bingo.pizza", result.common_name)
475
+ assert_empty(result.alternate_names)
476
+ assert_equal(1, result.years)
477
+ assert_nil(result.csr)
478
+ assert_equal("requesting", result.state)
479
+ assert_equal("letsencrypt", result.authority_identifier)
480
+ refute(result.auto_renew)
481
+ end
482
+
483
+ test "issue_letsencrypt_certificate_renewal raises NotFoundError when the domain does not exist" do
484
+ domain_id = "bingo.pizza"
485
+ certificate_id = 101972
486
+ certificate_renewal_id = 65082
487
+ stub_request(:post, %r{/v2})
488
+ .to_return(read_http_fixture("notfound-domain.http"))
489
+
490
+ assert_raises(Dnsimple::NotFoundError) do
491
+ @subject.issue_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id, certificate_renewal_id)
492
+ end
493
+ end
494
+
495
+ test "issue_letsencrypt_certificate_renewal raises NotFoundError when the certificate does not exist" do
496
+ domain_id = "bingo.pizza"
497
+ certificate_id = 101972
498
+ certificate_renewal_id = 65082
499
+ stub_request(:post, %r{/v2})
500
+ .to_return(read_http_fixture("notfound-certificate.http"))
501
+
502
+ assert_raises(Dnsimple::NotFoundError) do
503
+ @subject.issue_letsencrypt_certificate_renewal(@account_id, domain_id, certificate_id, certificate_renewal_id)
504
+ end
505
+ end
506
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ClientServiceTest < Minitest::Test
6
+ test "loops all the pages" do
7
+ account_id = 1010
8
+ item_class = Class.new(Dnsimple::Struct::Base) do
9
+ attr_accessor :id
10
+ end
11
+
12
+ service_class = Class.new(Dnsimple::Client::ClientService) do
13
+ define_method(:list) do |account_id, options = {}|
14
+ response = client.get(Dnsimple::Client.versioned("/%s/list" % [account_id]), options)
15
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| item_class.new(r) })
16
+ end
17
+ end
18
+ subject = service_class.new(Dnsimple::Client.new(base_url: "https://api.example.com/", access_token: "a1b2c3"))
19
+
20
+ stub_request(:get, %r{/v2/#{account_id}/list\?page=1&per_page=100})
21
+ .to_return(read_http_fixture("pages-1of3.http"))
22
+ stub_request(:get, %r{/v2/#{account_id}/list\?page=2&per_page=100})
23
+ .to_return(read_http_fixture("pages-2of3.http"))
24
+ stub_request(:get, %r{/v2/#{account_id}/list\?page=3&per_page=100})
25
+ .to_return(read_http_fixture("pages-3of3.http"))
26
+
27
+ results = subject.paginate(:list, account_id, {})
28
+
29
+ assert_equal(5, results.data.size)
30
+ assert_equal([1, 2, 3, 4, 5], results.data.map(&:id))
31
+ end
32
+ end