gandi_v5 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +3 -2
  4. data/lib/gandi_v5.rb +34 -13
  5. data/lib/gandi_v5/domain.rb +2 -8
  6. data/lib/gandi_v5/email/forward.rb +2 -8
  7. data/lib/gandi_v5/email/mailbox.rb +2 -8
  8. data/lib/gandi_v5/live_dns.rb +0 -12
  9. data/lib/gandi_v5/live_dns/domain.rb +313 -29
  10. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
  11. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  12. data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
  13. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
  14. data/lib/gandi_v5/version.rb +1 -1
  15. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  16. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  17. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  18. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  19. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  20. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  21. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  22. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  23. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  24. data/spec/units/gandi_v5/domain_spec.rb +6 -37
  25. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  26. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  27. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  28. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  29. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  30. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  31. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  32. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  33. data/spec/units/gandi_v5_spec.rb +111 -14
  34. metadata +18 -24
  35. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  36. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  37. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  38. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  39. data/spec/features/domain_spec.rb +0 -45
  40. data/spec/features/livedns_domain_spec.rb +0 -8
  41. data/spec/features/livedns_zone_spec.rb +0 -44
  42. data/spec/features/mailbox_spec.rb +0 -18
  43. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  44. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  45. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  46. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  47. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  48. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  49. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  50. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  51. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  52. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  53. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  54. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -2,51 +2,53 @@
2
2
 
3
3
  describe GandiV5::LiveDNS::Domain do
4
4
  subject do
5
- described_class.new fqdn: 'example.com', zone_uuid: 'zone-uuid'
5
+ described_class.new fqdn: 'example.com', automatic_snapshots: false
6
6
  end
7
7
 
8
8
  describe '#refresh' do
9
9
  before :each do
10
10
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'fetch.yml'))
11
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
11
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com')
12
12
  .and_return([nil, YAML.load_file(body_fixture)])
13
13
  subject.refresh
14
14
  end
15
15
 
16
16
  its('fqdn') { should eq 'example.com' }
17
- its('zone_uuid') { should eq 'zone-uuid' }
17
+ its('automatic_snapshots') { should be true }
18
+ end
19
+
20
+ it '#update' do
21
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com'
22
+ body = '{"automatic_snapshots":true}'
23
+ expect(GandiV5).to receive(:patch).with(url, body)
24
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
25
+ expect(subject.update(automatic_snapshots: true)).to eq 'Confirmation message.'
26
+ expect(subject.automatic_snapshots).to be true
18
27
  end
19
28
 
20
29
  describe '#fetch_records' do
30
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/records' }
21
31
  it 'All of them' do
22
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records')
23
- .and_return([nil, []])
24
-
32
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100)
33
+ .and_yield([])
25
34
  expect(subject.fetch_records).to eq []
26
35
  end
27
36
 
28
37
  it 'All for a name' do
29
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name')
30
- .and_return([nil, []])
31
-
38
+ expect(GandiV5).to receive(:paginated_get).with("#{url}/name", (1..), 100)
39
+ .and_yield([])
32
40
  expect(subject.fetch_records('name')).to eq []
33
41
  end
34
42
 
35
43
  it 'A type for a name' do
36
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT')
37
- .and_return(
38
- [
39
- nil,
40
- [
41
- {
42
- 'rrset_type' => 'TXT',
43
- 'rrset_name' => 'name',
44
- 'rrset_ttl' => 600,
45
- 'rrset_values' => %w[a b]
46
- }
47
- ]
48
- ]
49
- )
44
+ record = {
45
+ 'rrset_type' => 'TXT',
46
+ 'rrset_name' => 'name',
47
+ 'rrset_ttl' => 600,
48
+ 'rrset_values' => %w[a b]
49
+ }
50
+ expect(GandiV5).to receive(:paginated_get).with("#{url}/name/TXT", (1..), 100)
51
+ .and_yield([record])
50
52
 
51
53
  records = subject.fetch_records('name', 'TXT')
52
54
  expect(records.count).to eq 1
@@ -63,19 +65,19 @@ describe GandiV5::LiveDNS::Domain do
63
65
 
64
66
  describe '#fetch_zone_lines' do
65
67
  it 'All of them' do
66
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
68
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
67
69
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
68
70
  expect(subject.fetch_zone_lines).to eq 'returned'
69
71
  end
70
72
 
71
73
  it 'All for a name' do
72
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
74
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
73
75
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
74
76
  expect(subject.fetch_zone_lines('name')).to eq 'returned'
75
77
  end
76
78
 
77
79
  it 'A type for a name' do
78
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
80
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
79
81
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
80
82
  expect(subject.fetch_zone_lines('name', 'TXT')).to eq 'returned'
81
83
  end
@@ -87,7 +89,7 @@ describe GandiV5::LiveDNS::Domain do
87
89
 
88
90
  describe '#add_record' do
89
91
  it 'Success' do
90
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
92
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
91
93
  body = '{"rrset_name":"name","rrset_type":"TXT","rrset_ttl":900,"rrset_values":["a","b"]}'
92
94
  expect(GandiV5).to receive(:post).with(url, body).and_return([nil, { 'message' => 'Confirmation message.' }])
93
95
  expect(subject.add_record('name', 'TXT', 900, 'a', 'b')).to eq 'Confirmation message.'
@@ -114,19 +116,19 @@ describe GandiV5::LiveDNS::Domain do
114
116
 
115
117
  describe '#delete_records' do
116
118
  it 'All of them' do
117
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
119
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
118
120
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
119
121
  subject.delete_records
120
122
  end
121
123
 
122
124
  it 'All for a name' do
123
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
125
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
124
126
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
125
127
  subject.delete_records 'name'
126
128
  end
127
129
 
128
130
  it 'A type for a name' do
129
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
131
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
130
132
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
131
133
  subject.delete_records 'name', 'TXT'
132
134
  end
@@ -137,129 +139,254 @@ describe GandiV5::LiveDNS::Domain do
137
139
  end
138
140
 
139
141
  describe '#replace_records' do
140
- it 'Given array of GandiV5::LiveDNS::RecordSet' do
141
- records = [
142
- { name: 'name', ttl: 600, type: 'TXT', values: ['a'] }
143
- ]
144
-
145
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
146
- body = '{"items":[{"rrset_name":"name","rrset_ttl":600,"rrset_type":"TXT","rrset_values":["a"]}]}'
142
+ it 'All of them' do
143
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
144
+ body = '{"items":[{"rrset_name":"name","rrset_type":"TXT","rrset_values":["a"]}]}'
147
145
  expect(GandiV5).to receive(:put).with(url, body)
148
146
  .and_return([nil, { 'message' => 'Confirmation message.' }])
149
- expect(subject.replace_records(records: records)).to eq 'Confirmation message.'
147
+ records = [{ name: 'name', type: 'TXT', values: ['a'] }]
148
+ expect(subject.replace_records(records)).to eq 'Confirmation message.'
150
149
  end
151
150
 
152
- it 'Given string' do
153
- records = [
154
- '@ 86400 IN A 192.168.0.1',
155
- '* 86400 IN A 192.168.0.1'
156
- ].join("\n")
151
+ it 'All for a name' do
152
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
153
+ body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
154
+ expect(GandiV5).to receive(:put).with(url, body)
155
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
156
+ records = [{ type: 'TXT', values: ['a'] }]
157
+ expect(subject.replace_records(records, name: 'name')).to eq 'Confirmation message.'
158
+ end
157
159
 
158
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
159
- expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
160
+ it 'All of a type for a name' do
161
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
162
+ body = '{"rrset_values":["a"]}'
163
+ expect(GandiV5).to receive(:put).with(url, body)
160
164
  .and_return([nil, { 'message' => 'Confirmation message.' }])
161
- expect(subject.replace_records(text: records)).to eq 'Confirmation message.'
165
+ expect(subject.replace_records(['a'], name: 'name', type: 'TXT')).to eq 'Confirmation message.'
162
166
  end
163
167
 
164
- it 'Given both' do
165
- expect { subject.replace_records text: '', records: [] }.to raise_error(
166
- ArgumentError,
167
- 'you must pass ONE of records: or text:'
168
- )
168
+ it 'Given type but no name' do
169
+ expect(GandiV5).to_not receive(:put)
170
+ expect { subject.replace_records(['a'], type: 'TXT') }.to raise_error ArgumentError, 'missing keyword: name'
171
+ end
172
+ end
173
+
174
+ it '#replace_zone_lines' do
175
+ records = [
176
+ '@ 86400 IN A 192.168.0.1',
177
+ '* 86400 IN A 192.168.0.1'
178
+ ].join("\n")
179
+
180
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
181
+ expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
182
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
183
+ expect(subject.replace_zone_lines(records)).to eq 'Confirmation message.'
184
+ end
185
+
186
+ describe '#name_servers' do
187
+ let(:nameservers) { double Array }
188
+
189
+ it 'Already fetched' do
190
+ subject.instance_exec(nameservers) { |ns| @name_servers = ns }
191
+ expect(subject).to_not receive(:fetch_name_servers)
192
+ expect(subject.name_servers).to be nameservers
169
193
  end
170
194
 
171
- it 'Given nothing' do
172
- expect { subject.replace_records }.to raise_error ArgumentError, 'you must pass ONE of records: or text:'
195
+ it 'Not already fetched' do
196
+ expect(subject).to receive(:fetch_name_servers).and_return(nameservers)
197
+ expect(subject.name_servers).to be nameservers
173
198
  end
174
199
  end
175
200
 
176
- describe '#replace_records_for' do
177
- it 'Given no type or ttl' do
178
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
179
- body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
180
- expect(GandiV5).to receive(:put).with(url, body)
181
- .and_return([nil, { 'message' => 'Confirmation message.' }])
182
- records = [{ type: 'TXT', values: ['a'] }]
183
- expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
201
+ it '#fetch_name_servers' do
202
+ body_fixture = File.expand_path(
203
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'nameservers.yml')
204
+ )
205
+
206
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/nameservers')
207
+ .and_return([nil, YAML.load_file(body_fixture)])
208
+
209
+ expect(subject.fetch_name_servers).to match_array ['a.example.com', 'b.example.com']
210
+ end
211
+
212
+ describe '#dnssec_keys' do
213
+ let(:dnsseckeys) { double Array }
214
+
215
+ it 'Already fetched' do
216
+ subject.instance_exec(dnsseckeys) { |k| @dnssec_keys = k }
217
+ expect(subject).to_not receive(:fetch_dnssec_keys)
218
+ expect(subject.dnssec_keys).to be dnsseckeys
184
219
  end
185
220
 
186
- it 'Given type and ttl' do
187
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
188
- body = '{"rrset_values":["a"],"rrset_ttl":600}'
189
- expect(GandiV5).to receive(:put).with(url, body)
190
- .and_return([nil, { 'message' => 'Confirmation message.' }])
191
- expect(subject.replace_records_for('name', ['a'], type: 'TXT', ttl: 600)).to eq 'Confirmation message.'
221
+ it 'Not already fetched' do
222
+ expect(subject).to receive(:fetch_dnssec_keys).and_return(dnsseckeys)
223
+ expect(subject.dnssec_keys).to be dnsseckeys
192
224
  end
225
+ end
193
226
 
194
- it 'Given type but no ttl' do
195
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
196
- body = '{"rrset_values":["a"],"rrset_ttl":null}'
197
- expect(GandiV5).to receive(:put).with(url, body)
198
- .and_return([nil, { 'message' => 'Confirmation message.' }])
199
- expect(subject.replace_records_for('name', ['a'], type: 'TXT')).to eq 'Confirmation message.'
227
+ it '#fetch_dnssec_keys' do
228
+ keys = double Array
229
+ expect(GandiV5::LiveDNS::Domain::DnssecKey).to receive(:list).with('example.com')
230
+ .and_return(keys)
231
+
232
+ expect(subject.fetch_dnssec_keys).to be keys
233
+ expect(subject.instance_exec { @dnssec_keys }).to be keys
234
+ end
235
+
236
+ describe '#tsig_keys' do
237
+ let(:tsigkeys) { double Array }
238
+
239
+ it 'Already fetched' do
240
+ subject.instance_exec(tsigkeys) { |k| @tsig_keys = k }
241
+ expect(subject).to_not receive(:fetch_tsig_keys)
242
+ expect(subject.tsig_keys).to be tsigkeys
200
243
  end
201
244
 
202
- it 'Given ttl but no type' do
203
- expect(GandiV5).to_not receive(:put)
204
- expect { subject.replace_records_for 'name', 'a', ttl: 600 }.to raise_error ArgumentError, 'missing keyword: type'
245
+ it 'Not already fetched' do
246
+ expect(subject).to receive(:fetch_tsig_keys).and_return(tsigkeys)
247
+ expect(subject.tsig_keys).to be tsigkeys
205
248
  end
206
249
  end
207
250
 
208
- describe '#change_zone' do
209
- it 'Given a uuid' do
210
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
211
- body = '{"zone_uuid":"zone-uuid"}'
212
- expect(GandiV5).to receive(:patch).with(url, body)
213
- .and_return([nil, { 'message' => 'Confirmation message.' }])
214
- expect(subject.change_zone('zone-uuid')).to eq 'Confirmation message.'
215
- expect(subject.zone_uuid).to eq 'zone-uuid'
216
- end
217
-
218
- it 'Given something with a uuid method' do
219
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
220
- body = '{"zone_uuid":"zone-uuid"}'
221
- expect(GandiV5).to receive(:patch).with(url, body)
222
- .and_return([nil, { 'message' => 'Confirmation message.' }])
223
- zone = double GandiV5::LiveDNS::Zone, uuid: 'zone-uuid'
224
- expect(subject.change_zone(zone)).to eq 'Confirmation message.'
225
- expect(subject.zone_uuid).to eq 'zone-uuid'
251
+ it '#fetch_tsig_keys' do
252
+ body_fixture = File.expand_path(
253
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list_tsig.yml')
254
+ )
255
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig'
256
+
257
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
258
+ results = subject.fetch_tsig_keys
259
+ result = results.first
260
+ expect(results.count).to eq 1
261
+ expect(result.uuid).to eq 'key-uuid'
262
+ expect(result.name).to eq 'key-name'
263
+ end
264
+
265
+ describe '#add_tsig_key' do
266
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig/key-uuid' }
267
+
268
+ it 'Passed a key' do
269
+ key = GandiV5::LiveDNS::Domain::TsigKey.new uuid: 'key-uuid'
270
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
271
+ subject.add_tsig_key key
272
+ end
273
+
274
+ it 'Passed a string' do
275
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
276
+ subject.add_tsig_key 'key-uuid'
277
+ end
278
+
279
+ it 'With sharing_id' do
280
+ expect(GandiV5).to receive(:put).with("#{url}?sharing_id=sharing-id").and_return([nil, nil])
281
+ subject.add_tsig_key 'key-uuid', sharing_id: 'sharing-id'
226
282
  end
227
283
  end
228
284
 
229
- it '#fetch_zone' do
230
- returns = double GandiV5::LiveDNS::Zone
231
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid')
232
- .and_return(returns)
233
- expect(subject.fetch_zone).to be returns
285
+ describe '#remove_tsig_key' do
286
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig/key-uuid' }
287
+
288
+ it 'Passed a key' do
289
+ key = GandiV5::LiveDNS::Domain::TsigKey.new uuid: 'key-uuid'
290
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
291
+ subject.remove_tsig_key key
292
+ end
293
+
294
+ it 'Passed a string' do
295
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
296
+ subject.remove_tsig_key 'key-uuid'
297
+ end
298
+
299
+ it 'With sharing_id' do
300
+ expect(GandiV5).to receive(:delete).with("#{url}?sharing_id=sharing-id").and_return([nil, nil])
301
+ subject.remove_tsig_key 'key-uuid', sharing_id: 'sharing-id'
302
+ end
234
303
  end
235
304
 
236
- describe '#zone' do
237
- it 'Not previously fetched' do
238
- returns = double GandiV5::LiveDNS::Zone
239
- expect(subject).to receive(:fetch_zone).and_return(returns)
240
- expect(subject.zone).to be returns
305
+ describe '#axfr_clients' do
306
+ let(:clients) { double Array }
307
+
308
+ it 'Already fetched' do
309
+ subject.instance_exec(clients) { |k| @axfr_clients = k }
310
+ expect(subject).to_not receive(:fetch_axfr_clients)
311
+ expect(subject.axfr_clients).to be clients
241
312
  end
242
313
 
243
- it 'Previously fetched' do
244
- returns = double GandiV5::LiveDNS::Zone
245
- subject.instance_exec { @zone = returns }
246
- expect(subject).to_not receive(:fetch_zone)
247
- expect(subject.zone).to be returns
314
+ it 'Not already fetched' do
315
+ expect(subject).to receive(:fetch_axfr_clients).and_return(clients)
316
+ expect(subject.axfr_clients).to be clients
248
317
  end
249
318
  end
250
319
 
320
+ it '#fetch_axfr_clients' do
321
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves'
322
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, ['1.2.3.4']])
323
+ expect(subject.fetch_axfr_clients).to match_array ['1.2.3.4']
324
+ end
325
+
326
+ it '#add_axfr_client' do
327
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves/1.2.3.4'
328
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
329
+ subject.add_axfr_client '1.2.3.4'
330
+ end
331
+
332
+ it '#remove_axfr_client' do
333
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves/1.2.3.4'
334
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
335
+ subject.remove_axfr_client '1.2.3.4'
336
+ end
337
+
251
338
  describe '.list' do
252
- subject { described_class.list }
339
+ let(:body_fixture) do
340
+ File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yml'))
341
+ end
342
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains' }
253
343
 
254
- before :each do
255
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yml'))
256
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains')
344
+ it 'With default parameters' do
345
+ headers = { params: { page: 1, per_page: 100 } }
346
+ expect(GandiV5).to receive(:get).with(url, headers)
257
347
  .and_return([nil, YAML.load_file(body_fixture)])
348
+
349
+ subject = described_class.list
350
+ expect(subject.count).to eq 1
351
+ expect(subject.first).to eq 'example.com'
258
352
  end
259
353
 
260
- its('count') { should eq 1 }
261
- its('first.fqdn') { should eq 'example.com' }
262
- its('first.zone_uuid') { should be nil }
354
+ it 'Keeps fetching until no more to get' do
355
+ headers1 = { params: { page: 1, per_page: 1 } }
356
+ headers2 = { params: { page: 2, per_page: 1 } }
357
+ expect(GandiV5).to receive(:get).with(url, headers1)
358
+ .ordered
359
+ .and_return([nil, YAML.load_file(body_fixture)])
360
+ expect(GandiV5).to receive(:get).with(url, headers2)
361
+ .ordered
362
+ .and_return([nil, []])
363
+
364
+ expect(described_class.list(per_page: 1).count).to eq 1
365
+ end
366
+
367
+ it 'Given a range as page number' do
368
+ headers = { params: { page: 1, per_page: 1 } }
369
+ expect(GandiV5).to receive(:get).with(url, headers)
370
+ .and_return([nil, YAML.load_file(body_fixture)])
371
+
372
+ described_class.list(page: (1..1), per_page: 1)
373
+ end
374
+
375
+ describe 'Passes optional query params' do
376
+ it 'per_page' do
377
+ headers = { params: { page: 1, per_page: 10 } }
378
+ expect(GandiV5).to receive(:get).with(url, headers)
379
+ .and_return([nil, []])
380
+ described_class.list(per_page: 10)
381
+ end
382
+
383
+ it 'sharing_id' do
384
+ headers = { params: { sharing_id: 'SHARING-UUID', page: 1, per_page: 100 } }
385
+ expect(GandiV5).to receive(:get).with(url, headers)
386
+ .and_return([nil, []])
387
+ described_class.list(sharing_id: 'SHARING-UUID')
388
+ end
389
+ end
263
390
  end
264
391
 
265
392
  describe '.fetch' do
@@ -267,11 +394,63 @@ describe GandiV5::LiveDNS::Domain do
267
394
 
268
395
  before :each do
269
396
  body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'fetch.yml'))
270
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
397
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com')
271
398
  .and_return([nil, YAML.load_file(body_fixture)])
272
399
  end
273
400
 
274
401
  its('fqdn') { should eq 'example.com' }
275
- its('zone_uuid') { should eq 'zone-uuid' }
402
+ its('automatic_snapshots') { should be true }
403
+ end
404
+
405
+ describe '.create' do
406
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains' }
407
+ let(:response) do
408
+ double RestClient::Response, headers: { location: 'https://api.gandi.net/v5/livedns/domains/example.com' }
409
+ end
410
+
411
+ it 'When passed only fqdn' do
412
+ returns = double described_class
413
+ body = '{"fqdn":"example.com","zone":{}}'
414
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
415
+ expect(described_class).to receive(:fetch).with('example.com').and_return(returns)
416
+ expect(described_class.create('example.com')).to be returns
417
+ end
418
+
419
+ it 'When passed soa_ttl' do
420
+ body = '{"fqdn":"example.com","zone":{"ttl":123}}'
421
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
422
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
423
+ described_class.create('example.com', soa_ttl: 123)
424
+ end
425
+
426
+ it 'When passed records' do
427
+ body = '{"fqdn":"example.com","zone":{"items":' \
428
+ '[{"rrset_type":"TXT","rrset_ttl":234,"rrset_name":"test","rrset_values":["value"]}]}}'
429
+ record = GandiV5::LiveDNS::Domain::Record.new name: 'test', type: 'TXT', ttl: 234, values: ['value']
430
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
431
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
432
+ described_class.create('example.com', [record])
433
+ end
434
+
435
+ it 'When passed sharing_id' do
436
+ body = '{"fqdn":"example.com","zone":{}}'
437
+ expect(GandiV5).to receive(:post).with("#{url}?sharing_id=organization_id", body).and_return([response, nil])
438
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
439
+ described_class.create('example.com', sharing_id: 'organization_id')
440
+ end
441
+ end
442
+
443
+ it '.record_types' do
444
+ list = double Array
445
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/dns/rrtypes')
446
+ .and_return([nil, list])
447
+ expect(described_class.record_types).to be list
448
+ end
449
+
450
+ it '.generic_name_servers' do
451
+ list = double Array
452
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/nameservers/example.com')
453
+ .and_return([nil, list])
454
+ expect(described_class.generic_name_servers('example.com')).to be list
276
455
  end
277
456
  end