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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +3 -2
- data/lib/gandi_v5.rb +34 -13
- data/lib/gandi_v5/domain.rb +2 -8
- data/lib/gandi_v5/email/forward.rb +2 -8
- data/lib/gandi_v5/email/mailbox.rb +2 -8
- 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/version.rb +1 -1
- 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/units/gandi_v5/domain_spec.rb +6 -37
- data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
- data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
- 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_spec.rb +111 -14
- metadata +18 -24
- 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 -44
- 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/live_dns/zone/snapshot_spec.rb +0 -66
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -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
|
-
|
14
|
-
|
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
|
48
|
+
%i[fqdn sort_by tld].each do |param|
|
77
49
|
it param.to_s do
|
78
|
-
|
79
|
-
|
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
|
@@ -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
|
@@ -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
|
-
|
404
|
-
|
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
|
-
|
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
|
@@ -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
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GandiV5::LiveDNS::Domain::TsigKey do
|
4
|
+
subject do
|
5
|
+
described_class.new(
|
6
|
+
uuid: 'key-uuid',
|
7
|
+
name: 'key-name',
|
8
|
+
secret: 'key-secret',
|
9
|
+
config_examples: { test: 'test config sample' }
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.create' do
|
14
|
+
it 'Without sharing_id' do
|
15
|
+
url = 'https://api.gandi.net/v5/livedns/axfr/tsig'
|
16
|
+
created = { 'href' => '', 'id' => 'created-key-uuid', 'key_name' => 'based on id' }
|
17
|
+
returns = double described_class
|
18
|
+
|
19
|
+
expect(GandiV5).to receive(:post).with(url).and_return([nil, created])
|
20
|
+
expect(described_class).to receive(:fetch).with('created-key-uuid')
|
21
|
+
.and_return(returns)
|
22
|
+
expect(described_class.create).to be returns
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'With sharing_id' do
|
26
|
+
url = 'https://api.gandi.net/v5/livedns/axfr/tsig?sharing_id=sharing-id'
|
27
|
+
created = { 'href' => '', 'id' => 'created-key-uuid', 'key_name' => 'based on id' }
|
28
|
+
returns = double described_class
|
29
|
+
|
30
|
+
expect(GandiV5).to receive(:post).with(url).and_return([nil, created])
|
31
|
+
expect(described_class).to receive(:fetch).with('created-key-uuid')
|
32
|
+
.and_return(returns)
|
33
|
+
expect(described_class.create('sharing-id')).to be returns
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it '.list' do
|
38
|
+
body_fixture = File.expand_path(
|
39
|
+
File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_TsigKey', 'list.yml')
|
40
|
+
)
|
41
|
+
url = 'https://api.gandi.net/v5/livedns/axfr/tsig'
|
42
|
+
|
43
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
|
44
|
+
results = described_class.list
|
45
|
+
result = results.first
|
46
|
+
expect(results.count).to eq 1
|
47
|
+
expect(result.uuid).to eq 'key-uuid'
|
48
|
+
expect(result.name).to eq 'key-name'
|
49
|
+
expect(result.secret).to eq 'key-secret'
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.fetch' do
|
53
|
+
subject { described_class.fetch 'key-uuid' }
|
54
|
+
|
55
|
+
before :each do
|
56
|
+
body_fixture = File.expand_path(
|
57
|
+
File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_TsigKey', 'fetch.yml')
|
58
|
+
)
|
59
|
+
url = 'https://api.gandi.net/v5/livedns/axfr/tsig/key-uuid'
|
60
|
+
expect(GandiV5).to receive(:get).with(url)
|
61
|
+
.and_return([nil, YAML.load_file(body_fixture)])
|
62
|
+
end
|
63
|
+
|
64
|
+
its('uuid') { should eq 'key-uuid' }
|
65
|
+
its('name') { should eq 'key-name' }
|
66
|
+
its('secret') { should eq 'key-secret' }
|
67
|
+
its('config_examples') do
|
68
|
+
should eq(
|
69
|
+
{
|
70
|
+
bind: 'bind-sample',
|
71
|
+
knot: 'knot-sample',
|
72
|
+
nsd: 'nsd-sample',
|
73
|
+
powerdns: 'powerdns-sample'
|
74
|
+
}
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|