gandi_v5 0.3.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +56 -2
- data/.travis.yml +6 -1
- data/CHANGELOG.md +61 -0
- data/LICENSE.md +2 -6
- data/README.md +15 -9
- data/gandi_v5.gemspec +2 -2
- data/lib/gandi_v5.rb +40 -14
- data/lib/gandi_v5/data.rb +1 -2
- data/lib/gandi_v5/data/converter/integer.rb +26 -0
- data/lib/gandi_v5/domain.rb +13 -14
- data/lib/gandi_v5/email/forward.rb +2 -8
- data/lib/gandi_v5/email/mailbox.rb +57 -11
- data/lib/gandi_v5/email/slot.rb +11 -3
- data/lib/gandi_v5/live_dns.rb +0 -12
- data/lib/gandi_v5/live_dns/domain.rb +313 -29
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
- data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
- data/lib/gandi_v5/organization.rb +10 -0
- data/lib/gandi_v5/organization/customer.rb +90 -0
- data/lib/gandi_v5/sharing_space.rb +27 -0
- data/lib/gandi_v5/simple_hosting.rb +12 -0
- data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/spec/.rubocop.yml +56 -2
- data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
- data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
- data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
- data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
- data/spec/units/gandi_v5/domain_spec.rb +53 -43
- data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
- data/spec/units/gandi_v5/email/mailbox_spec.rb +119 -37
- data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
- data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
- data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
- data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
- data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
- data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
- data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
- data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
- data/spec/units/gandi_v5/organization_spec.rb +14 -0
- data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
- data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
- data/spec/units/gandi_v5_spec.rb +139 -30
- metadata +50 -31
- data/lib/gandi_v5/domain/sharing_space.rb +0 -21
- data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
- data/lib/gandi_v5/live_dns/record_set.rb +0 -79
- data/lib/gandi_v5/live_dns/zone.rb +0 -160
- data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
- data/spec/features/domain_spec.rb +0 -45
- data/spec/features/livedns_domain_spec.rb +0 -8
- data/spec/features/livedns_zone_spec.rb +0 -45
- data/spec/features/mailbox_spec.rb +0 -18
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
- data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
- data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
- data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
- data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
- data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
- data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -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
|
-
|
72
|
-
|
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: {
|
114
|
-
expect(GandiV5).to receive(:
|
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
|
@@ -87,6 +87,108 @@ describe GandiV5::Email::Mailbox do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
describe '#upgrade' do
|
91
|
+
let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid/type' }
|
92
|
+
|
93
|
+
context 'No sharing_id' do
|
94
|
+
it 'Is upgraded' do
|
95
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"premium"}', 'Dry-Run': 0)
|
96
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
97
|
+
expect(subject.upgrade).to be true
|
98
|
+
expect(subject.type).to be :premium
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'Is already premium' do
|
102
|
+
subject.instance_exec { @type = :premium }
|
103
|
+
expect(GandiV5).to_not receive(:patch)
|
104
|
+
expect(subject.upgrade).to be false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'With sharing_id' do
|
109
|
+
let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid/type?sharing_id=abc' }
|
110
|
+
|
111
|
+
it 'Is upgraded' do
|
112
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"premium"}', 'Dry-Run': 0)
|
113
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
114
|
+
expect(subject.upgrade(sharing_id: 'abc')).to be true
|
115
|
+
expect(subject.type).to be :premium
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'Is already premium' do
|
119
|
+
subject.instance_exec { @type = :premium }
|
120
|
+
expect(GandiV5).to_not receive(:patch)
|
121
|
+
expect(subject.upgrade(sharing_id: 'abc')).to be false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'Dry run' do
|
126
|
+
it 'Is upgraded' do
|
127
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"premium"}', 'Dry-Run': 1)
|
128
|
+
.and_return([nil, { 'status' => 'success' }])
|
129
|
+
expect(subject.upgrade(dry_run: true)).to eq('status' => 'success')
|
130
|
+
expect(subject.type).to be :standard
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'Is already premium' do
|
134
|
+
subject.instance_exec { @type = :premium }
|
135
|
+
expect(GandiV5).to_not receive(:patch)
|
136
|
+
expect(subject.upgrade(dry_run: true)).to be false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#downgrade' do
|
142
|
+
let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid/type' }
|
143
|
+
|
144
|
+
context 'No sharing_id' do
|
145
|
+
it 'Is downgraded' do
|
146
|
+
subject.instance_exec { @type = :premium }
|
147
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"standard"}', 'Dry-Run': 0)
|
148
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
149
|
+
expect(subject.downgrade).to be true
|
150
|
+
expect(subject.type).to be :standard
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'Is already premium' do
|
154
|
+
expect(GandiV5).to_not receive(:patch)
|
155
|
+
expect(subject.downgrade).to be false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'With sharing_id' do
|
160
|
+
let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid/type?sharing_id=abc' }
|
161
|
+
|
162
|
+
it 'Is downgraded' do
|
163
|
+
subject.instance_exec { @type = :premium }
|
164
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"standard"}', 'Dry-Run': 0)
|
165
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
166
|
+
expect(subject.downgrade(sharing_id: 'abc')).to be true
|
167
|
+
expect(subject.type).to be :standard
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'Is already premium' do
|
171
|
+
expect(GandiV5).to_not receive(:patch)
|
172
|
+
expect(subject.downgrade(sharing_id: 'abc')).to be false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'Dry run' do
|
177
|
+
it 'Is downgraded' do
|
178
|
+
subject.instance_exec { @type = :premium }
|
179
|
+
expect(GandiV5).to receive(:patch).with(url, '{"mailbox_type":"standard"}', 'Dry-Run': 1)
|
180
|
+
.and_return([nil, { 'status' => 'success' }])
|
181
|
+
expect(subject.downgrade(dry_run: true)).to eq('status' => 'success')
|
182
|
+
expect(subject.type).to be :premium
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'Is already premium' do
|
186
|
+
expect(GandiV5).to_not receive(:patch)
|
187
|
+
expect(subject.downgrade(dry_run: true)).to be false
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
90
192
|
it '#delete' do
|
91
193
|
url = 'https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid'
|
92
194
|
expect(GandiV5).to receive(:delete).with(url)
|
@@ -204,7 +306,7 @@ describe GandiV5::Email::Mailbox do
|
|
204
306
|
|
205
307
|
it 'No aliases and :standard type' do
|
206
308
|
body = '{"mailbox_type":"standard","login":"login","password":"crypted_password","aliases":[]}'
|
207
|
-
expect(GandiV5).to receive(:post).with(url, body)
|
309
|
+
expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
|
208
310
|
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
209
311
|
expect(described_class).to receive(:crypt_password).with(good_password).and_return('crypted_password')
|
210
312
|
expect(described_class).to receive(:fetch).with('example.com', 'created-mailbox-uuid').and_return(created_mailbox)
|
@@ -214,7 +316,7 @@ describe GandiV5::Email::Mailbox do
|
|
214
316
|
|
215
317
|
it 'With aliases' do
|
216
318
|
body = '{"mailbox_type":"standard","login":"login","password":"crypted_password","aliases":["alias-1"]}'
|
217
|
-
expect(GandiV5).to receive(:post).with(url, body)
|
319
|
+
expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
|
218
320
|
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
219
321
|
expect(described_class).to receive(:crypt_password).with(good_password).and_return('crypted_password')
|
220
322
|
expect(described_class).to receive(:fetch).with('example.com', 'created-mailbox-uuid').and_return(created_mailbox)
|
@@ -224,7 +326,7 @@ describe GandiV5::Email::Mailbox do
|
|
224
326
|
|
225
327
|
it 'With different type' do
|
226
328
|
body = '{"mailbox_type":"premium","login":"login","password":"crypted_password","aliases":[]}'
|
227
|
-
expect(GandiV5).to receive(:post).with(url, body)
|
329
|
+
expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
|
228
330
|
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
229
331
|
expect(described_class).to receive(:crypt_password).with(good_password).and_return('crypted_password')
|
230
332
|
expect(described_class).to receive(:fetch).with('example.com', 'created-mailbox-uuid').and_return(created_mailbox)
|
@@ -254,6 +356,16 @@ describe GandiV5::Email::Mailbox do
|
|
254
356
|
'no available standard slots'
|
255
357
|
)
|
256
358
|
end
|
359
|
+
|
360
|
+
it 'Doing a dry run' do
|
361
|
+
body = '{"mailbox_type":"standard","login":"login","password":"crypted_password","aliases":[]}'
|
362
|
+
expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 1)
|
363
|
+
.and_return([nil, { 'status' => 'success' }])
|
364
|
+
expect(described_class).to receive(:crypt_password).with(good_password).and_return('crypted_password')
|
365
|
+
expect(described_class).to_not receive(:fetch)
|
366
|
+
|
367
|
+
expect(described_class.create('example.com', 'login', good_password, dry_run: true)).to eq('status' => 'success')
|
368
|
+
end
|
257
369
|
end
|
258
370
|
|
259
371
|
describe '.fetch' do
|
@@ -283,14 +395,14 @@ describe GandiV5::Email::Mailbox do
|
|
283
395
|
let(:body_fixture) do
|
284
396
|
File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'list.yml'))
|
285
397
|
end
|
398
|
+
let(:url) { 'https://api.gandi.net/v5/email/mailboxes/example.com' }
|
286
399
|
|
287
400
|
describe 'With default values' do
|
288
401
|
subject { described_class.list 'example.com' }
|
289
402
|
|
290
403
|
before :each do
|
291
|
-
|
292
|
-
|
293
|
-
.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))
|
294
406
|
end
|
295
407
|
|
296
408
|
its('count') { should eq 1 }
|
@@ -302,43 +414,13 @@ describe GandiV5::Email::Mailbox do
|
|
302
414
|
its('first.quota_used') { should eq 1_000_000 }
|
303
415
|
end
|
304
416
|
|
305
|
-
it 'Keeps fetching until no more to get' do
|
306
|
-
headers1 = { params: { page: 1, per_page: 1 } }
|
307
|
-
headers2 = { params: { page: 2, per_page: 1 } }
|
308
|
-
# https://github.com/rubocop-hq/rubocop/issues/7088
|
309
|
-
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers1)
|
310
|
-
.ordered
|
311
|
-
.and_return([nil, YAML.load_file(body_fixture)])
|
312
|
-
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers2)
|
313
|
-
.ordered
|
314
|
-
.and_return([nil, []])
|
315
|
-
|
316
|
-
expect(described_class.list('example.com', per_page: 1).count).to eq 1
|
317
|
-
end
|
318
|
-
|
319
|
-
it 'Given a range as page number' do
|
320
|
-
headers1 = { params: { page: 1, per_page: 1 } }
|
321
|
-
headers2 = { params: { page: 2, per_page: 1 } }
|
322
|
-
# https://github.com/rubocop-hq/rubocop/issues/7088
|
323
|
-
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers1)
|
324
|
-
.ordered
|
325
|
-
.and_return([nil, YAML.load_file(body_fixture)])
|
326
|
-
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers2)
|
327
|
-
.ordered
|
328
|
-
.and_return([nil, []])
|
329
|
-
|
330
|
-
expect(described_class.list('example.com', page: (1..2), per_page: 1).count).to eq 1
|
331
|
-
end
|
332
|
-
|
333
417
|
describe 'Passes optional query params' do
|
334
418
|
{
|
335
419
|
login: '~login',
|
336
420
|
sort_by: :sort_by
|
337
421
|
}.each do |param, query_param|
|
338
422
|
it param.to_s do
|
339
|
-
|
340
|
-
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers)
|
341
|
-
.and_return([nil, []])
|
423
|
+
expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { query_param => 'value' })
|
342
424
|
expect(described_class.list('example.com', param => 'value')).to eq []
|
343
425
|
end
|
344
426
|
end
|
@@ -130,7 +130,7 @@ describe GandiV5::Email::Slot do
|
|
130
130
|
end
|
131
131
|
let(:created_slot) { double GandiV5::Email::Slot }
|
132
132
|
|
133
|
-
it 'With default type' do
|
133
|
+
it 'With default type and no sharingID' do
|
134
134
|
expect(GandiV5).to receive(:post).with(url, '{"mailbox_type":"standard"}')
|
135
135
|
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
136
136
|
expect(described_class).to receive(:fetch).with('example.com', 'created-slot-uuid').and_return(created_slot)
|
@@ -143,7 +143,15 @@ describe GandiV5::Email::Slot do
|
|
143
143
|
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
144
144
|
expect(described_class).to receive(:fetch).with('example.com', 'created-slot-uuid').and_return(created_slot)
|
145
145
|
|
146
|
-
expect(described_class.create('example.com', :premium)).to be created_slot
|
146
|
+
expect(described_class.create('example.com', type: :premium)).to be created_slot
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'With sharingID' do
|
150
|
+
expect(GandiV5).to receive(:post).with("#{url}?sharing_id=SHARING-ID", '{"mailbox_type":"standard"}')
|
151
|
+
.and_return([created_response, { 'message' => 'Confirmation message.' }])
|
152
|
+
expect(described_class).to receive(:fetch).with('example.com', 'created-slot-uuid').and_return(created_slot)
|
153
|
+
|
154
|
+
expect(described_class.create('example.com', sharing_id: 'SHARING-ID')).to be created_slot
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
@@ -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
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GandiV5::LiveDNS::Domain::Snapshot do
|
4
|
+
subject do
|
5
|
+
described_class.new(
|
6
|
+
created_at: Time.new(2016, 12, 16, 16, 51, 26, 0),
|
7
|
+
uuid: 'snapshot-uuid',
|
8
|
+
name: 'snapshot-name',
|
9
|
+
automatic: false,
|
10
|
+
records: [],
|
11
|
+
fqdn: 'example.com'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#update' do
|
16
|
+
url = 'https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid'
|
17
|
+
body = '{"name":"NEW NAME"}'
|
18
|
+
expect(GandiV5).to receive(:patch).with(url, body)
|
19
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
20
|
+
expect(subject.update(name: 'NEW NAME')).to eq 'Confirmation message.'
|
21
|
+
expect(subject.name).to eq 'NEW NAME'
|
22
|
+
end
|
23
|
+
|
24
|
+
it '#delete' do
|
25
|
+
expect(GandiV5).to receive(:delete).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
|
26
|
+
.and_return([nil, { 'message' => 'Confirmation message.' }])
|
27
|
+
expect(subject.delete).to eq 'Confirmation message.'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#records' do
|
31
|
+
it 'Returns existing if present' do
|
32
|
+
expect(GandiV5).to_not receive(:get)
|
33
|
+
expect(subject.records).to eq []
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'Fetches and saves if not present' do
|
37
|
+
subject = described_class.new fqdn: 'example.com', uuid: 'snapshot-uuid'
|
38
|
+
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
|
39
|
+
.and_return([nil, { 'zone_data' => [{ 'rrset_name' => 'HELLO' }] }])
|
40
|
+
expect(subject.records.count).to eq 1
|
41
|
+
expect(subject.records.first.name).to eq 'HELLO'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.list' do
|
46
|
+
let :body_fixture do
|
47
|
+
File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_Snapshot', 'list.yml'))
|
48
|
+
end
|
49
|
+
let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/snapshots' }
|
50
|
+
|
51
|
+
it 'With default parameters' do
|
52
|
+
expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
|
53
|
+
.and_yield(YAML.load_file(body_fixture))
|
54
|
+
results = described_class.list('example.com')
|
55
|
+
result = results.first
|
56
|
+
expect(results.count).to eq 1
|
57
|
+
expect(result.name).to eq 'snapshot-name'
|
58
|
+
expect(result.created_at).to eq Time.new(2016, 12, 16, 16, 51, 26, 0)
|
59
|
+
expect(result.uuid).to eq 'snapshot-uuid'
|
60
|
+
expect(result.automatic).to be true
|
61
|
+
expect(result.fqdn).to eq 'example.com'
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'Passes optional query params' do
|
65
|
+
describe 'automatic' do
|
66
|
+
it 'true' do
|
67
|
+
expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { automatic: true })
|
68
|
+
described_class.list('example.com', automatic: true)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'false' do
|
72
|
+
expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { automatic: false })
|
73
|
+
described_class.list('example.com', automatic: false)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '.fetch' do
|
80
|
+
subject { described_class.fetch 'example.com', 'snapshot-uuid' }
|
81
|
+
|
82
|
+
before :each do
|
83
|
+
body_fixture = File.expand_path(
|
84
|
+
File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_Snapshot', 'fetch.yml')
|
85
|
+
)
|
86
|
+
expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
|
87
|
+
.and_return([nil, YAML.load_file(body_fixture)])
|
88
|
+
end
|
89
|
+
|
90
|
+
its('created_at') { should eq Time.new(2016, 12, 16, 16, 51, 26, 0) }
|
91
|
+
its('uuid') { should eq 'snapshot-uuid' }
|
92
|
+
its('name') { should eq 'snapshot-name' }
|
93
|
+
its('automatic') { should be true }
|
94
|
+
its('fqdn') { should eq 'example.com' }
|
95
|
+
its('records.count') { should eq 1 }
|
96
|
+
its('records.first.type') { should eq 'A' }
|
97
|
+
its('records.first.ttl') { should eq 10_800 }
|
98
|
+
its('records.first.name') { should eq 'www' }
|
99
|
+
its('records.first.values') { should match_array ['10.0.1.42'] }
|
100
|
+
end
|
101
|
+
end
|