gandi_v5 0.6.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -5
  3. data/README.md +65 -14
  4. data/lib/gandi_v5.rb +139 -70
  5. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  6. data/lib/gandi_v5/data.rb +3 -2
  7. data/lib/gandi_v5/data/converter.rb +3 -2
  8. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  9. data/lib/gandi_v5/data/converter/integer.rb +3 -2
  10. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  11. data/lib/gandi_v5/data/converter/time.rb +3 -2
  12. data/lib/gandi_v5/domain.rb +55 -18
  13. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  14. data/lib/gandi_v5/domain/contact.rb +5 -5
  15. data/lib/gandi_v5/domain/tld.rb +2 -2
  16. data/lib/gandi_v5/domain/transfer_in.rb +172 -0
  17. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  18. data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
  19. data/lib/gandi_v5/email.rb +3 -0
  20. data/lib/gandi_v5/email/forward.rb +3 -9
  21. data/lib/gandi_v5/email/mailbox.rb +5 -11
  22. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  23. data/lib/gandi_v5/live_dns.rb +2 -12
  24. data/lib/gandi_v5/live_dns/domain.rb +340 -29
  25. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
  26. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  27. data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
  28. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
  29. data/lib/gandi_v5/sharing_space.rb +27 -0
  30. data/lib/gandi_v5/simple_hosting.rb +13 -0
  31. data/lib/gandi_v5/simple_hosting/instance.rb +251 -0
  32. data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
  33. data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
  34. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  35. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
  36. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +272 -0
  37. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
  38. data/lib/gandi_v5/template.rb +271 -0
  39. data/lib/gandi_v5/template/dispatch.rb +109 -0
  40. data/lib/gandi_v5/template/payload.rb +64 -0
  41. data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
  42. data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
  43. data/lib/gandi_v5/version.rb +1 -1
  44. data/spec/.rubocop.yml +9 -9
  45. data/spec/features/list_domain_renewals_spec.rb +16 -0
  46. data/spec/features/list_email_addresses_spec.rb +39 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  49. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
  50. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
  51. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  52. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  53. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  55. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  56. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  57. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  58. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  59. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  60. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  61. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  62. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  63. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  64. data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
  65. data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
  66. data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
  67. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  68. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  69. data/spec/spec_helper.rb +8 -7
  70. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  71. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  72. data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
  73. data/spec/units/gandi_v5/domain_spec.rb +56 -37
  74. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  75. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  76. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  77. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  78. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  79. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  80. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  81. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  82. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  83. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  84. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +324 -0
  85. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +190 -0
  86. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  87. data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
  88. data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
  89. data/spec/units/gandi_v5/template_spec.rb +341 -0
  90. data/spec/units/gandi_v5_spec.rb +111 -14
  91. metadata +226 -79
  92. data/.gitignore +0 -26
  93. data/.rspec +0 -3
  94. data/.rubocop.yml +0 -30
  95. data/.travis.yml +0 -38
  96. data/FUNDING.yml +0 -10
  97. data/Gemfile +0 -6
  98. data/Guardfile +0 -39
  99. data/Rakefile +0 -3
  100. data/bin/console +0 -13
  101. data/gandi_v5.gemspec +0 -42
  102. data/lib/gandi_v5/domain/sharing_space.rb +0 -29
  103. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  104. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  105. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  106. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  107. data/spec/features/domain_spec.rb +0 -45
  108. data/spec/features/livedns_domain_spec.rb +0 -8
  109. data/spec/features/livedns_zone_spec.rb +0 -44
  110. data/spec/features/mailbox_spec.rb +0 -18
  111. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  112. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  113. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  114. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  115. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  116. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  117. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  118. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  119. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  120. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  121. data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
  122. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
  123. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
  124. data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
  125. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
  126. data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
  127. data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
  128. data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
  129. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  130. data/spec/units/gandi_v5/error_spec.rb +0 -4
  131. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  132. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Domain::WebForwarding do
4
+ subject { described_class.new fqdn: 'host.example.com' }
5
+
6
+ describe '#update' do
7
+ let(:url) { 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com' }
8
+ let(:updated_forwarding) { double GandiV5::Domain::WebForwarding }
9
+
10
+ before :each do
11
+ expect(subject).to receive(:refresh).and_return(updated_forwarding)
12
+ subject.instance_exec { @domain = 'example.com' }
13
+ end
14
+
15
+ it 'nothing' do
16
+ expect(GandiV5).to receive(:patch).with(url, '{}')
17
+ expect(subject.update).to be updated_forwarding
18
+ end
19
+
20
+ it 'target' do
21
+ expect(GandiV5).to receive(:patch).with(url, '{"url":"new"}')
22
+ expect(subject.update(target: 'new')).to be updated_forwarding
23
+ end
24
+
25
+ it 'override' do
26
+ expect(GandiV5).to receive(:patch).with(url, '{"override":false}')
27
+ expect(subject.update(override: false)).to be updated_forwarding
28
+ end
29
+
30
+ it 'protocol' do
31
+ expect(GandiV5).to receive(:patch).with(url, '{"protocol":"httpsonly"}')
32
+ expect(subject.update(protocol: :httpsonly)).to be updated_forwarding
33
+ end
34
+
35
+ it 'type' do
36
+ expect(GandiV5).to receive(:patch).with(url, '{"type":"http302"}')
37
+ expect(subject.update(type: :http302)).to be updated_forwarding
38
+ end
39
+ end
40
+
41
+ it '#delete' do
42
+ url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com'
43
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, { 'message' => 'Confirmation message.' }])
44
+ subject.instance_exec { @domain = 'example.com' }
45
+ expect(subject.delete).to eq 'Confirmation message.'
46
+ end
47
+
48
+ describe 'helper methods' do
49
+ context 'an HTTP 301 redirect' do
50
+ subject { described_class.new type: :http301 }
51
+ it('#permanent?') { expect(subject.permanent?).to be true }
52
+ it('#http301?') { expect(subject.http301?).to be true }
53
+ it('#temporary?') { expect(subject.temporary?).to be false }
54
+ it('#http302?') { expect(subject.http302?).to be false }
55
+ it('#found?') { expect(subject.found?).to be false }
56
+ end
57
+
58
+ context 'an HTTP 302 redirect' do
59
+ subject { described_class.new type: :http302 }
60
+ it('#permanent?') { expect(subject.permanent?).to be false }
61
+ it('#http301?') { expect(subject.http301?).to be false }
62
+ it('#temporary?') { expect(subject.temporary?).to be true }
63
+ it('#http302?') { expect(subject.http302?).to be true }
64
+ it('#found?') { expect(subject.found?).to be true }
65
+ end
66
+
67
+ context 'an http endpoint' do
68
+ subject { described_class.new protocol: :http }
69
+ it('#http?') { expect(subject.http?).to be true }
70
+ it('#https?') { expect(subject.https?).to be false }
71
+ it('#https_only?') { expect(subject.https_only?).to be false }
72
+ end
73
+
74
+ context 'an https endpoint' do
75
+ subject { described_class.new protocol: :https }
76
+ it('#http?') { expect(subject.http?).to be true }
77
+ it('#https?') { expect(subject.https?).to be true }
78
+ it('#https_only?') { expect(subject.https_only?).to be false }
79
+ end
80
+
81
+ context 'an https_only endpoint' do
82
+ subject { described_class.new protocol: :https_only }
83
+ it('#http?') { expect(subject.http?).to be false }
84
+ it('#https?') { expect(subject.https?).to be true }
85
+ it('#https_only?') { expect(subject.https_only?).to be true }
86
+ end
87
+ end
88
+
89
+ describe '.fetch' do
90
+ subject { described_class.fetch 'example.com', 'host' }
91
+
92
+ before :each do
93
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_WebForwarding', 'fetch.yml'))
94
+ url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com'
95
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
96
+ end
97
+
98
+ its('created_at') { should eq Time.new(2020, 11, 29, 14, 57, 14) }
99
+ its('updated_at') { should eq Time.new(2020, 11, 29, 14, 57, 15) }
100
+ its('type') { should eq :http301 }
101
+ its('fqdn') { should eq 'here.example.com' }
102
+ its('protocol') { should eq :https }
103
+ its('target') { should eq 'https://example.com/here' }
104
+ its('cert_status') { should eq '?' }
105
+ its('cert_uuid') { should eq 'cert-uuid' }
106
+ end
107
+
108
+ describe '.list' do
109
+ subject { described_class.list 'example.com' }
110
+
111
+ before :each do
112
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_WebForwarding', 'list.yml'))
113
+ url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs'
114
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100)
115
+ .and_yield(YAML.load_file(body_fixture))
116
+ end
117
+
118
+ its('count') { should eq 1 }
119
+ its('first.created_at') { should eq Time.new(2020, 11, 29, 14, 57, 14) }
120
+ its('first.updated_at') { should eq Time.new(2020, 11, 29, 14, 57, 15) }
121
+ its('first.type') { should eq :http301 }
122
+ its('first.fqdn') { should eq 'here.example.com' }
123
+ its('first.protocol') { should eq :https }
124
+ its('first.target') { should eq 'https://example.com/here' }
125
+ its('first.cert_status') { should eq '?' }
126
+ its('first.cert_uuid') { should eq 'cert-uuid' }
127
+ end
128
+
129
+ it '.create' do
130
+ url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs'
131
+ body = '{"host":"host","protocol":"httpsonly","type":"http302","url":"example.com","override":true}'
132
+ response = double(
133
+ RestClient::Response,
134
+ headers: { location: ' https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com' }
135
+ )
136
+ created_forwarding = double GandiV5::Domain::WebForwarding
137
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
138
+ expect(described_class).to receive(:fetch).with('example.com', 'host').and_return(created_forwarding)
139
+
140
+ create = {
141
+ domain: 'example.com',
142
+ host: 'host',
143
+ target: 'example.com',
144
+ protocol: :https_only,
145
+ type: :http302,
146
+ override: true
147
+ }
148
+ expect(described_class.create(**create)).to be created_forwarding
149
+ end
150
+ end
@@ -5,14 +5,14 @@ describe GandiV5::Domain do
5
5
 
6
6
  describe '.list' do
7
7
  let(:body_fixture) { File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain', 'list.yml')) }
8
+ let(:url) { 'https://api.gandi.net/v5/domain/domains' }
8
9
 
9
10
  describe 'With default values' do
10
11
  subject { described_class.list }
11
12
 
12
13
  before :each do
13
- headers = { params: { page: 1, per_page: 100 } }
14
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers)
15
- .and_return([nil, YAML.load_file(body_fixture)])
14
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
15
+ .and_yield(YAML.load_file(body_fixture))
16
16
  end
17
17
 
18
18
  its('count') { should eq 1 }
@@ -44,42 +44,11 @@ describe GandiV5::Domain do
44
44
  its('first.contacts?') { should be false }
45
45
  end
46
46
 
47
- it 'Keeps fetching until no more to get' do
48
- headers1 = { params: { page: 1, per_page: 1 } }
49
- headers2 = { params: { page: 2, per_page: 1 } }
50
- # https://github.com/rubocop-hq/rubocop/issues/7088
51
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers1)
52
- .ordered
53
- .and_return([nil, YAML.load_file(body_fixture)])
54
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers2)
55
- .ordered
56
- .and_return([nil, []])
57
-
58
- expect(described_class.list(per_page: 1).count).to eq 1
59
- end
60
-
61
- it 'Given a range as page number' do
62
- headers1 = { params: { page: 1, per_page: 1 } }
63
- headers2 = { params: { page: 2, per_page: 1 } }
64
- # https://github.com/rubocop-hq/rubocop/issues/7088
65
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers1)
66
- .ordered
67
- .and_return([nil, YAML.load_file(body_fixture)])
68
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers2)
69
- .ordered
70
- .and_return([nil, []])
71
-
72
- expect(described_class.list(page: (1..2), per_page: 1).count).to eq 1
73
- end
74
-
75
47
  describe 'Passes optional query params' do
76
- %i[fqdn page per_page sort_by tld].each do |param|
48
+ %i[fqdn sort_by tld resellee_id].each do |param|
77
49
  it param.to_s do
78
- param = { param => 5 }
79
- headers = { params: { page: 1, per_page: 100 }.merge(param) }
80
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers)
81
- .and_return([nil, []])
82
- expect(described_class.list(**param)).to eq []
50
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 5 })
51
+ expect(described_class.list(param => 5)).to eq []
83
52
  end
84
53
  end
85
54
  end
@@ -239,6 +208,18 @@ describe GandiV5::Domain do
239
208
  expect(subject.email_forwards(param: :value)).to be returns
240
209
  end
241
210
 
211
+ it '.webforwardings' do
212
+ returns = double Array
213
+ expect(GandiV5::Domain::WebForwarding).to receive(:list).with('example.com', param: :value).and_return(returns)
214
+ expect(subject.web_forwardings(param: :value)).to be returns
215
+ end
216
+
217
+ it '.webforwarding' do
218
+ returns = double Array
219
+ expect(GandiV5::Domain::WebForwarding).to receive(:fetch).with('example.com', 'host').and_return(returns)
220
+ expect(subject.web_forwarding('host')).to be returns
221
+ end
222
+
242
223
  describe '#to_s' do
243
224
  it 'Has identical fqdn and fqdn_unicode' do
244
225
  domain = described_class.new fqdn: 'example.com', fqdn_unicode: 'example.com'
@@ -525,6 +506,44 @@ describe GandiV5::Domain do
525
506
  end
526
507
  end
527
508
 
509
+ describe '#transfer_lock' do
510
+ it 'Passing nothing' do
511
+ expect(GandiV5).to receive(:patch).with(
512
+ 'https://api.gandi.net/v5/domain/domains/example.com/status',
513
+ '{"clientTransferProhibited":true}'
514
+ ).and_return([nil, { 'message' => 'Confirmation message.' }])
515
+ expect(subject.transfer_lock).to eq 'Confirmation message.'
516
+ expect(subject.status).to eq 'clientTransferProhibited'
517
+ end
518
+
519
+ it 'Passing true' do
520
+ expect(GandiV5).to receive(:patch).with(
521
+ 'https://api.gandi.net/v5/domain/domains/example.com/status',
522
+ '{"clientTransferProhibited":true}'
523
+ ).and_return([nil, { 'message' => 'Confirmation message.' }])
524
+ expect(subject.transfer_lock(true)).to eq 'Confirmation message.'
525
+ expect(subject.status).to eq 'clientTransferProhibited'
526
+ end
527
+
528
+ it 'Passing false' do
529
+ expect(GandiV5).to receive(:patch).with(
530
+ 'https://api.gandi.net/v5/domain/domains/example.com/status',
531
+ '{"clientTransferProhibited":false}'
532
+ ).and_return([nil, { 'message' => 'Confirmation message.' }])
533
+ expect(subject.transfer_lock(false)).to eq 'Confirmation message.'
534
+ expect(subject.status).to be nil
535
+ end
536
+ end
537
+
538
+ it '#transfer_unlock' do
539
+ expect(GandiV5).to receive(:patch).with(
540
+ 'https://api.gandi.net/v5/domain/domains/example.com/status',
541
+ '{"clientTransferProhibited":false}'
542
+ ).and_return([nil, { 'message' => 'Confirmation message.' }])
543
+ expect(subject.transfer_unlock).to eq 'Confirmation message.'
544
+ expect(subject.status).to be nil
545
+ end
546
+
528
547
  describe '#glue_records' do
529
548
  let(:glue_records) { double Hash }
530
549
 
@@ -63,14 +63,14 @@ describe GandiV5::Email::Forward do
63
63
  let(:body_fixture) do
64
64
  File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Forward', 'list.yml'))
65
65
  end
66
+ let(:url) { 'https://api.gandi.net/v5/email/forwards/example.com' }
66
67
 
67
68
  describe 'With default values' do
68
69
  subject { described_class.list 'example.com' }
69
70
 
70
71
  before :each do
71
- headers = { params: { page: 1 } }
72
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers)
73
- .and_return([nil, YAML.load_file(body_fixture)])
72
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
73
+ .and_yield(YAML.load_file(body_fixture))
74
74
  end
75
75
 
76
76
  its('count') { should eq 1 }
@@ -79,40 +79,11 @@ describe GandiV5::Email::Forward do
79
79
  its('first.fqdn') { should eq 'example.com' }
80
80
  end
81
81
 
82
- it 'Keeps fetching until no more to get' do
83
- headers1 = { params: { page: 1, per_page: 1 } }
84
- headers2 = { params: { page: 2, per_page: 1 } }
85
- # https://github.com/rubocop-hq/rubocop/issues/7088
86
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers1)
87
- .ordered
88
- .and_return([nil, YAML.load_file(body_fixture)])
89
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers2)
90
- .ordered
91
- .and_return([nil, []])
92
-
93
- expect(described_class.list('example.com', per_page: 1).count).to eq 1
94
- end
95
-
96
- it 'Given a range as page number' do
97
- headers1 = { params: { page: 1, per_page: 1 } }
98
- headers2 = { params: { page: 2, per_page: 1 } }
99
- # https://github.com/rubocop-hq/rubocop/issues/7088
100
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers1)
101
- .ordered
102
- .and_return([nil, YAML.load_file(body_fixture)])
103
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers2)
104
- .ordered
105
- .and_return([nil, []])
106
-
107
- expect(described_class.list('example.com', page: (1..2), per_page: 1).count).to eq 1
108
- end
109
-
110
82
  describe 'Passes optional query params' do
111
83
  %i[source sort_by].each do |param|
112
84
  it param.to_s do
113
- headers = { params: { page: 1 }.merge(param => 'value') }
114
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/forwards/example.com', headers)
115
- .and_return([nil, []])
85
+ headers = { params: { param => 'value' } }
86
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, **headers)
116
87
  expect(described_class.list('example.com', param => 'value')).to eq []
117
88
  end
118
89
  end
@@ -395,14 +395,14 @@ describe GandiV5::Email::Mailbox do
395
395
  let(:body_fixture) do
396
396
  File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'list.yml'))
397
397
  end
398
+ let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com' }
398
399
 
399
400
  describe 'With default values' do
400
401
  subject { described_class.list 'example.com' }
401
402
 
402
403
  before :each do
403
- headers = { params: { page: 1 } }
404
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers)
405
- .and_return([nil, YAML.load_file(body_fixture)])
404
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
405
+ .and_yield(YAML.load_file(body_fixture))
406
406
  end
407
407
 
408
408
  its('count') { should eq 1 }
@@ -414,43 +414,13 @@ describe GandiV5::Email::Mailbox do
414
414
  its('first.quota_used') { should eq 1_000_000 }
415
415
  end
416
416
 
417
- it 'Keeps fetching until no more to get' do
418
- headers1 = { params: { page: 1, per_page: 1 } }
419
- headers2 = { params: { page: 2, per_page: 1 } }
420
- # https://github.com/rubocop-hq/rubocop/issues/7088
421
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers1)
422
- .ordered
423
- .and_return([nil, YAML.load_file(body_fixture)])
424
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers2)
425
- .ordered
426
- .and_return([nil, []])
427
-
428
- expect(described_class.list('example.com', per_page: 1).count).to eq 1
429
- end
430
-
431
- it 'Given a range as page number' do
432
- headers1 = { params: { page: 1, per_page: 1 } }
433
- headers2 = { params: { page: 2, per_page: 1 } }
434
- # https://github.com/rubocop-hq/rubocop/issues/7088
435
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers1)
436
- .ordered
437
- .and_return([nil, YAML.load_file(body_fixture)])
438
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers2)
439
- .ordered
440
- .and_return([nil, []])
441
-
442
- expect(described_class.list('example.com', page: (1..2), per_page: 1).count).to eq 1
443
- end
444
-
445
417
  describe 'Passes optional query params' do
446
418
  {
447
419
  login: '~login',
448
420
  sort_by: :sort_by
449
421
  }.each do |param, query_param|
450
422
  it param.to_s do
451
- headers = { params: { page: 1 }.merge(query_param => 'value') }
452
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers)
453
- .and_return([nil, []])
423
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { query_param => 'value' })
454
424
  expect(described_class.list('example.com', param => 'value')).to eq []
455
425
  end
456
426
  end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::Domain::DnssecKey do
4
+ subject do
5
+ described_class.new(
6
+ uuid: 'key-uuid',
7
+ status: 'status',
8
+ fqdn: 'example.com',
9
+ algorithm_id: 2,
10
+ algorithm_name: 'Diffie-Hellman',
11
+ deleted: false,
12
+ ds: 'ds-record',
13
+ flags: 256,
14
+ fingerprint: 'fp',
15
+ public_key: 'pub-key',
16
+ tag: 'tag'
17
+ )
18
+ end
19
+
20
+ it '#delete' do
21
+ expect(GandiV5).to receive(:delete).with('https://api.gandi.net/v5/livedns/domains/example.com/keys/key-uuid')
22
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
23
+ expect(subject.delete).to eq 'Confirmation message.'
24
+ expect(subject.deleted).to be true
25
+ end
26
+
27
+ it '#undelete' do
28
+ subject = described_class.new deleted: true, uuid: 'key-uuid', fqdn: 'example.com'
29
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/keys/key-uuid'
30
+ expect(GandiV5).to receive(:patch).with(url, '{"deleted":false}')
31
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
32
+ expect(subject.undelete).to eq 'Confirmation message.'
33
+ expect(subject.deleted).to be false
34
+ end
35
+
36
+ describe 'flags helper methods' do
37
+ describe '256 (zone signing key)' do
38
+ before(:each) { subject.instance_exec { @flags = 256 } }
39
+ its('zone_signing_key?') { should be true }
40
+ its('key_signing_key?') { should be false }
41
+ end
42
+
43
+ describe '257 (key signing key)' do
44
+ before(:each) { subject.instance_exec { @flags = 257 } }
45
+ its('zone_signing_key?') { should be false }
46
+ its('key_signing_key?') { should be true }
47
+ end
48
+ end
49
+
50
+ describe '.create' do
51
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/keys' }
52
+ let(:response) do
53
+ double RestClient::Response, headers: {
54
+ location: 'https://api.gandi.net/v5/livedns/domains/example.com/keys/created-key-uuid'
55
+ }
56
+ end
57
+
58
+ it 'Accepts integer for flags' do
59
+ returns = double described_class
60
+ expect(GandiV5).to receive(:post).with(url, '{"flags":256}').and_return([response, nil])
61
+ expect(described_class).to receive(:fetch).with('example.com', 'created-key-uuid')
62
+ .and_return(returns)
63
+ expect(described_class.create('example.com', :zone_signing_key)).to be returns
64
+ end
65
+
66
+ it 'Accepts :zone_signing_key for flags' do
67
+ expect(GandiV5).to receive(:post).with(url, '{"flags":256}').and_return([response, nil])
68
+ expect(described_class).to receive(:fetch)
69
+ described_class.create('example.com', :zone_signing_key)
70
+ end
71
+
72
+ it 'Accepts :key_signing_key for flags' do
73
+ expect(GandiV5).to receive(:post).with(url, '{"flags":257}').and_return([response, nil])
74
+ expect(described_class).to receive(:fetch)
75
+ described_class.create('example.com', :key_signing_key)
76
+ end
77
+
78
+ it 'Fails on invalid flags' do
79
+ expect { described_class.create('example.com', :invalid) }.to raise_error ArgumentError, 'flags is invalid'
80
+ expect { described_class.create('example.com', '0') }.to raise_error ArgumentError, 'flags is invalid'
81
+ end
82
+ end
83
+
84
+ it '.list' do
85
+ body_fixture = File.expand_path(
86
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_DnssecKey', 'list.yml')
87
+ )
88
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/keys'
89
+
90
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
91
+ results = described_class.list('example.com')
92
+ result = results.first
93
+ expect(results.count).to eq 1
94
+ expect(result.uuid).to eq 'key-uuid'
95
+ expect(result.status).to eq 'status'
96
+ expect(result.fqdn).to eq 'example.com'
97
+ expect(result.algorithm_id).to eq 2
98
+ expect(result.algorithm_name).to eq 'Diffie-Hellman'
99
+ expect(result.deleted).to be false
100
+ expect(result.ds).to eq 'ds-record'
101
+ expect(result.flags).to eq 256
102
+ end
103
+
104
+ describe '.fetch' do
105
+ subject { described_class.fetch 'example.com', 'key-uuid' }
106
+
107
+ before :each do
108
+ body_fixture = File.expand_path(
109
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_DnssecKey', 'fetch.yml')
110
+ )
111
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/keys/key-uuid'
112
+ expect(GandiV5).to receive(:get).with(url)
113
+ .and_return([nil, YAML.load_file(body_fixture)])
114
+ end
115
+
116
+ its('uuid') { should eq 'key-uuid' }
117
+ its('status') { should eq 'status' }
118
+ its('fqdn') { should eq 'example.com' }
119
+ its('algorithm_id') { should eq 2 }
120
+ its('algorithm_name') { should eq 'Diffie-Hellman' }
121
+ its('deleted') { should be false }
122
+ its('ds') { should eq 'ds-record' }
123
+ its('flags') { should eq 256 }
124
+ its('fingerprint') { should eq 'fp' }
125
+ its('public_key') { should eq 'pub-key' }
126
+ its('tag') { should eq 'tag' }
127
+ end
128
+ end