gandi_v5 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,133 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.gandi.net/v5/domain/domains/example.net
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- Authorization:
13
- - Apikey abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: |-
26
- {
27
- "status": [
28
- "clientTransferProhibited"
29
- ],
30
- "dates": {
31
- "created_at": "2019-02-13T11:04:18Z",
32
- "deletes_at": "2021-03-30T00:04:18Z",
33
- "hold_begins_at": "2021-02-13T10:04:18Z",
34
- "hold_ends_at": "2021-03-30T10:04:18Z",
35
- "pending_delete_ends_at": "2021-05-04T10:04:18Z",
36
- "registry_created_at": "2019-02-13T10:04:18Z",
37
- "registry_ends_at": "2021-02-13T10:04:18Z",
38
- "renew_begins_at": "2012-01-01T00:00:00Z",
39
- "restore_ends_at": "2021-04-29T10:04:18Z",
40
- "updated_at": "2019-02-25T16:20:49Z",
41
- "authinfo_expires_at": "2020-02-25T16:20:49Z"
42
- },
43
- "can_tld_lock": true,
44
- "tags": [],
45
- "nameservers": [
46
- "ns-25-a.gnadi.net",
47
- "ns-113-b.gnadi.net",
48
- "ns-58-c.gnadi.net"
49
- ],
50
- "contacts": {
51
- "owner": {
52
- "city": "Paris",
53
- "given": "Alice",
54
- "reachability": "pending",
55
- "family": "Doe",
56
- "zip": "75001",
57
- "extra_parameters": {
58
- "birth_date": "",
59
- "birth_department": "",
60
- "birth_city": "",
61
- "birth_country": ""
62
- },
63
- "country": "FR",
64
- "streetaddr": "5 rue neuve",
65
- "data_obfuscated": true,
66
- "mail_obfuscated": true,
67
- "phone": "+33.123456789",
68
- "state": "FR-J",
69
- "validation": "none",
70
- "type": 0,
71
- "email": "alice@example.org"
72
- }
73
- },
74
- "fqdn": "example.net",
75
- "autorenew": {
76
- "dates": [
77
- "2021-01-13T09:04:18Z",
78
- "2021-01-29T10:04:18Z",
79
- "2021-02-12T10:04:18Z"
80
- ],
81
- "org_id": "fe0b931c-18c5-11e9-b9b5-00163ec4cb00",
82
- "duration": 1,
83
- "href": "http://api.test/v5/domain/domains/example.net/autorenew",
84
- "enabled": false
85
- },
86
- "authinfo": "8vyhljvJg+",
87
- "sharing_space": {
88
- "id": "fe0b931c-18c5-11e9-b9b5-00163ec4cb00",
89
- "name": "alice_doe"
90
- },
91
- "tld": "net",
92
- "services": [
93
- "gandilivedns",
94
- "mailboxv2"
95
- ],
96
- "id": "ba1167be-2f76-11e9-9dfb-00163ec4cb00",
97
- "trustee_roles": [],
98
- "href": "http://api.test/v5/domain/domains/example.net",
99
- "fqdn_unicode": "example.net"
100
- }
101
- http_version:
102
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
103
-
104
- - request:
105
- method: post
106
- uri: https://api.gandi.net/v5/domain/domains/example.net/renew
107
- body:
108
- encoding: US-ASCII
109
- string: '{"duration":2}'
110
- headers:
111
- Accept:
112
- - application/json
113
- Authorization:
114
- - Apikey abdce12345
115
- Host:
116
- - api.gandi.net
117
- response:
118
- status:
119
- code: 200
120
- message: OK
121
- headers:
122
- Content-Type:
123
- - application/json; charset=utf-8
124
- body:
125
- encoding: UTF-8
126
- string: |-
127
- {
128
- "message":"Domain renewed."
129
- }
130
- http_version:
131
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
132
-
133
- recorded_with: VCR 4.0.0
@@ -1,32 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://dns.api.gandi.net/api/v5/domains
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- Authorization:
13
- - Apikey abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: |-
26
- [
27
- {"fqdn":"example.com"},
28
- {"fqdn":"example.net"}
29
- ]
30
- http_version:
31
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
32
- recorded_with: VCR 4.0.0
@@ -1,42 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://dns.api.gandi.net/api/v5/zones
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- X-Api-Key:
13
- - abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: |-
26
- [
27
- {
28
- "retry": 3600,
29
- "uuid": "uuid-of-zone",
30
- "minimum": 10800,
31
- "refresh": 10800,
32
- "expire": 604800,
33
- "serial": 1432798405,
34
- "user_uuid": "uuid-of-user",
35
- "email": "hostmaster.gandi.net.",
36
- "primary_ns": "a.dns.gandi.net.",
37
- "name": "Zone Name"
38
- }
39
- ]
40
- http_version:
41
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
42
- recorded_with: VCR 4.0.0
@@ -1,72 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- X-Api-Key:
13
- - abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: |-
26
- {
27
- "message": "Zone Snapshot Created",
28
- "uuid": "snapshot-uuid"
29
- }
30
- http_version:
31
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
32
-
33
- - request:
34
- method: get
35
- uri: https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid
36
- body:
37
- encoding: US-ASCII
38
- string: ''
39
- headers:
40
- Accept:
41
- - text/plain
42
- X-Api-Key:
43
- - abdce12345
44
- Host:
45
- - api.gandi.net
46
- response:
47
- status:
48
- code: 200
49
- message: OK
50
- headers:
51
- Content-Type:
52
- - application/json; charset=utf-8
53
- body:
54
- encoding: UTF-8
55
- string: |-
56
- {
57
- "date_created": "2016-12-16T16:51:26Z",
58
- "uuid": "snapshot-uuid",
59
- "zone_uuid": "zone-uuid",
60
- "zone_data": [
61
- {
62
- "rrset_type": "A",
63
- "rrset_ttl": 10800,
64
- "rrset_name": "www",
65
- "rrset_values": ["10.0.1.42"]
66
- }
67
- ]
68
- }
69
- http_version:
70
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
71
-
72
- recorded_with: VCR 4.0.0
@@ -1,28 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://dns.api.gandi.net/api/v5/zones/zone-uuid/records
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - text/plain
12
- X-Api-Key:
13
- - abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - text/plain; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: "Contents of zone file.\n"
26
- http_version:
27
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
28
- recorded_with: VCR 4.0.0
@@ -1,39 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.gandi.net/v5/email/mailboxes/example.net?page=1
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept:
11
- - application/json
12
- Authorization:
13
- - Apikey abdce12345
14
- Host:
15
- - api.gandi.net
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=utf-8
23
- body:
24
- encoding: UTF-8
25
- string: |-
26
- [
27
- {
28
- "domain": "example.net",
29
- "login": "alice",
30
- "address": "alice@example.net",
31
- "id": "066743e5-96e4-4a1d-9195-8b8a700a8a79",
32
- "mailbox_type": "standard",
33
- "quota_used": 1200,
34
- "href": "https://api.test/api/v5/email/example.net/066743e5-96e4-4a1d-9195-8b8a700a8a79"
35
- }
36
- ]
37
- http_version:
38
- recorded_at: Thu, 30 May 2019 06:22:02 GMT
39
- recorded_with: VCR 4.0.0
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe GandiV5::LiveDNS::Zone::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
- zone_uuid: 'zone-uuid',
9
- records: []
10
- )
11
- end
12
-
13
- it '#delete' do
14
- expect(GandiV5).to receive(:delete).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
15
- .and_return([nil, { 'message' => 'Confirmation message.' }])
16
- expect(subject.delete).to eq 'Confirmation message.'
17
- end
18
-
19
- it '#fetch_zone' do
20
- returns = double GandiV5::LiveDNS::Zone
21
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid')
22
- .and_return(returns)
23
- expect(subject.fetch_zone).to be returns
24
- end
25
-
26
- describe '#zone' do
27
- it 'Not previously fetched' do
28
- returns = double GandiV5::LiveDNS::Zone
29
- expect(subject).to receive(:fetch_zone).and_return(returns)
30
- expect(subject.zone).to be returns
31
- end
32
-
33
- it 'Previously fetched' do
34
- returns = double GandiV5::LiveDNS::Zone
35
- subject.instance_exec { @zone = returns }
36
- expect(subject).to_not receive(:fetch_zone)
37
- expect(subject.zone).to be returns
38
- end
39
- end
40
-
41
- it '.list' do
42
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'list.yml'))
43
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots')
44
- .and_return([nil, YAML.load_file(body_fixture)])
45
- expect(described_class.list('zone-uuid')).to eq('snapshot-uuid' => Time.new(2016, 12, 16, 16, 51, 26, 0))
46
- end
47
-
48
- describe '.fetch' do
49
- subject { described_class.fetch 'zone-uuid', 'snapshot-uuid' }
50
-
51
- before :each do
52
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'fetch.yml'))
53
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
54
- .and_return([nil, YAML.load_file(body_fixture)])
55
- end
56
-
57
- its('created_at') { should eq Time.new(2016, 12, 16, 16, 51, 26, 0) }
58
- its('uuid') { should eq 'snapshot-uuid' }
59
- its('zone_uuid') { should eq 'zone-uuid' }
60
- its('records.count') { should eq 1 }
61
- its('records.first.type') { should eq 'A' }
62
- its('records.first.ttl') { should eq 10_800 }
63
- its('records.first.name') { should eq 'www' }
64
- its('records.first.values') { should match_array ['10.0.1.42'] }
65
- end
66
- end
@@ -1,347 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe GandiV5::LiveDNS::Zone do
4
- subject do
5
- described_class.new(
6
- name: 'Zone Name',
7
- uuid: 'zone-uuid',
8
- soa_retry: 1,
9
- soa_minimum: 2,
10
- soa_refresh: 3,
11
- soa_expire: 4,
12
- soa_serial: 5,
13
- soa_email: 'admin.example.com',
14
- soa_primary_ns: '192.168.0.1'
15
- )
16
- end
17
-
18
- it '#to_s' do
19
- expect(subject.to_s).to eq [
20
- '@ IN SOA 192.168.0.1 admin.example.com (',
21
- "\t5\t;Serial",
22
- "\t3\t\t;Refresh",
23
- "\t1\t\t;Retry",
24
- "\t4\t\t;Expire",
25
- "\t2\t\t;Minimum & Negative TTL",
26
- ')'
27
- ].join("\n")
28
- end
29
-
30
- describe '#fetch_records' do
31
- it 'All of them' do
32
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/records')
33
- .and_return([nil, []])
34
-
35
- expect(subject.fetch_records).to eq []
36
- end
37
-
38
- it 'All for a name' do
39
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name')
40
- .and_return([nil, []])
41
-
42
- expect(subject.fetch_records('name')).to eq []
43
- end
44
-
45
- it 'A type for a name' do
46
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name/TXT')
47
- .and_return(
48
- [
49
- nil,
50
- [
51
- {
52
- 'rrset_type' => 'TXT',
53
- 'rrset_name' => 'name',
54
- 'rrset_ttl' => 600,
55
- 'rrset_values' => %w[a b]
56
- }
57
- ]
58
- ]
59
- )
60
-
61
- records = subject.fetch_records('name', 'TXT')
62
- expect(records.count).to eq 1
63
- expect(records.first.type).to eq 'TXT'
64
- expect(records.first.ttl).to eq 600
65
- expect(records.first.name).to eq 'name'
66
- expect(records.first.values).to match_array %w[a b]
67
- end
68
-
69
- it 'Invalid type' do
70
- expect { subject.fetch_records 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
71
- end
72
- end
73
-
74
- describe '#fetch_zone_lines' do
75
- it 'All of them' do
76
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records'
77
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
78
- expect(subject.fetch_zone_lines).to eq 'returned'
79
- end
80
-
81
- it 'All for a name' do
82
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name'
83
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
84
- expect(subject.fetch_zone_lines('name')).to eq 'returned'
85
- end
86
-
87
- it 'A type for a name' do
88
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name/TXT'
89
- expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
90
- expect(subject.fetch_zone_lines('name', 'TXT')).to eq 'returned'
91
- end
92
-
93
- it 'Invalid type' do
94
- expect { subject.fetch_zone_lines 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
95
- end
96
- end
97
-
98
- describe '#add_record' do
99
- it 'Success' do
100
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records'
101
- body = '{"rrset_name":"name","rrset_type":"TXT","rrset_ttl":900,"rrset_values":["a","b"]}'
102
- expect(GandiV5).to receive(:post).with(url, body).and_return([nil, { 'message' => 'Confirmation message.' }])
103
- expect(subject.add_record('name', 'TXT', 900, 'a', 'b')).to eq 'Confirmation message.'
104
- end
105
-
106
- it 'Bad type' do
107
- expect { subject.add_record 'name', 'INVALID-TYPE', 900, 'a' }.to raise_error ArgumentError
108
- end
109
-
110
- it 'Bad TTL' do
111
- expect { subject.add_record 'name', 'TXT', -900, 'a' }.to raise_error(
112
- ArgumentError,
113
- 'ttl must be positive and non-zero'
114
- )
115
- end
116
-
117
- it 'No values' do
118
- expect { subject.add_record 'name', 'TXT', 900 }.to raise_error(
119
- ArgumentError,
120
- 'there must be at least one value'
121
- )
122
- end
123
- end
124
-
125
- describe '#delete_records' do
126
- it 'All of them' do
127
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records'
128
- expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
129
- subject.delete_records
130
- end
131
-
132
- it 'All for a name' do
133
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name'
134
- expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
135
- subject.delete_records 'name'
136
- end
137
-
138
- it 'A type for a name' do
139
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name/TXT'
140
- expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
141
- subject.delete_records 'name', 'TXT'
142
- end
143
-
144
- it 'Invalid type' do
145
- expect { subject.delete_records 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
146
- end
147
- end
148
-
149
- describe '#replace_records' do
150
- it 'Given array of GandiV5::LiveDNS::RecordSet' do
151
- records = [
152
- { name: 'name', ttl: 600, type: 'TXT', values: ['a'] }
153
- ]
154
-
155
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records'
156
- body = '{"items":[{"rrset_name":"name","rrset_ttl":600,"rrset_type":"TXT","rrset_values":["a"]}]}'
157
- expect(GandiV5).to receive(:put).with(url, body)
158
- .and_return([nil, { 'message' => 'Confirmation message.' }])
159
- expect(subject.replace_records(records: records)).to eq 'Confirmation message.'
160
- end
161
-
162
- it 'Given string' do
163
- records = [
164
- '@ 86400 IN A 192.168.0.1',
165
- '* 86400 IN A 192.168.0.1'
166
- ].join("\n")
167
-
168
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records'
169
- expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
170
- .and_return([nil, { 'message' => 'Confirmation message.' }])
171
- expect(subject.replace_records(text: records)).to eq 'Confirmation message.'
172
- end
173
-
174
- it 'Given both' do
175
- expect { subject.replace_records text: '', records: [] }.to raise_error(
176
- ArgumentError,
177
- 'you must pass ONE of records: or text:'
178
- )
179
- end
180
-
181
- it 'Given nothing' do
182
- expect { subject.replace_records }.to raise_error ArgumentError, 'you must pass ONE of records: or text:'
183
- end
184
- end
185
-
186
- describe '#replace_records_for' do
187
- it 'Given no type or ttl' do
188
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name'
189
- body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
190
- expect(GandiV5).to receive(:put).with(url, body)
191
- .and_return([nil, { 'message' => 'Confirmation message.' }])
192
- records = [{ type: 'TXT', values: ['a'] }]
193
- expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
194
- end
195
-
196
- it 'Given type and ttl' do
197
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name/TXT'
198
- body = '{"rrset_values":["a"],"rrset_ttl":600}'
199
- expect(GandiV5).to receive(:put).with(url, body)
200
- .and_return([nil, { 'message' => 'Confirmation message.' }])
201
- expect(subject.replace_records_for('name', ['a'], type: 'TXT', ttl: 600)).to eq 'Confirmation message.'
202
- end
203
-
204
- it 'Given type but no ttl' do
205
- url = 'https://dns.api.gandi.net/api/v5/zones/zone-uuid/records/name/TXT'
206
- body = '{"rrset_values":["a"],"rrset_ttl":null}'
207
- expect(GandiV5).to receive(:put).with(url, body)
208
- .and_return([nil, { 'message' => 'Confirmation message.' }])
209
- expect(subject.replace_records_for('name', ['a'], type: 'TXT')).to eq 'Confirmation message.'
210
- end
211
-
212
- it 'Given ttl but no type' do
213
- expect(GandiV5).to_not receive(:put)
214
- expect { subject.replace_records_for 'name', 'a', ttl: 600 }.to raise_error ArgumentError, 'missing keyword: type'
215
- end
216
- end
217
-
218
- it '#list_domains' do
219
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/domains')
220
- .and_return([nil, [{ 'fqdn' => 'example.com' }]])
221
- expect(subject.list_domains).to match_array ['example.com']
222
- end
223
-
224
- describe '#attach_domain' do
225
- it 'Given a fqdn' do
226
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
227
- body = '{"zone_uuid":"zone-uuid"}'
228
- expect(GandiV5).to receive(:patch).with(url, body)
229
- .and_return([nil, { 'message' => 'Confirmation message.' }])
230
- expect(subject.attach_domain('example.com')).to eq 'Confirmation message.'
231
- end
232
-
233
- it 'Given something with a fqdn method' do
234
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
235
- body = '{"zone_uuid":"zone-uuid"}'
236
- expect(GandiV5).to receive(:patch).with(url, body)
237
- .and_return([nil, { 'message' => 'Confirmation message.' }])
238
- domain = double GandiV5::LiveDNS::Domain, fqdn: 'example.com'
239
- expect(subject.attach_domain(domain)).to eq 'Confirmation message.'
240
- end
241
- end
242
-
243
- it '#snapshots' do
244
- returns = double Hash
245
- expect(GandiV5::LiveDNS::Zone::Snapshot).to receive(:list).with('zone-uuid')
246
- .and_return(returns)
247
- expect(subject.snapshots).to be returns
248
- end
249
-
250
- it '#snapshot' do
251
- returns = double GandiV5::LiveDNS::Zone::Snapshot
252
- expect(GandiV5::LiveDNS::Zone::Snapshot).to receive(:fetch).with('zone-uuid', 'snapshot-uuid')
253
- .and_return(returns)
254
- expect(subject.snapshot('snapshot-uuid')).to be returns
255
- end
256
-
257
- it '#take_snapshot' do
258
- returns = double GandiV5::LiveDNS::Zone::Snapshot
259
- expect(GandiV5).to receive(:post).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots')
260
- .and_return([nil, { 'message' => 'Confirmation message.', 'uuid' => 'snapshot-uuid' }])
261
- expect(GandiV5::LiveDNS::Zone::Snapshot).to receive(:fetch).with('zone-uuid', 'snapshot-uuid')
262
- .and_return(returns)
263
- expect(subject.take_snapshot).to be returns
264
- end
265
-
266
- it '#update' do
267
- body = '{"name":"new-name"}'
268
- expect(GandiV5).to receive(:patch).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid', body)
269
- .and_return([nil, { 'message' => 'Confirmation message.' }])
270
- expect(subject.update(name: 'new-name')).to eq 'Confirmation message.'
271
- end
272
-
273
- it '#delete' do
274
- expect(GandiV5).to receive(:delete).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid')
275
- subject.delete
276
- end
277
-
278
- describe '.create' do
279
- let(:created_response) do
280
- double(
281
- RestClient::Response,
282
- headers: { location: 'https://dns.api.gandi.net/v5/zones/created-zone-uuid' }
283
- )
284
- end
285
- let(:created_zone) { double GandiV5::LiveDNS::Zone }
286
-
287
- it 'With sharing-id' do
288
- body = '{"name":"Name"}'
289
- params = { sharing_id: 'sharing-id' }
290
- expect(GandiV5).to receive(:post).with('https://dns.api.gandi.net/api/v5/zones', body, params: params)
291
- .and_return([created_response, { 'message' => 'Confirmation message.' }])
292
- expect(described_class).to receive(:fetch).with('created-zone-uuid').and_return(created_zone)
293
- expect(described_class.create('Name', sharing_id: 'sharing-id')).to be created_zone
294
- end
295
-
296
- it 'Without sharing-id' do
297
- body = '{"name":"Name"}'
298
- expect(GandiV5).to receive(:post).with('https://dns.api.gandi.net/api/v5/zones', body, params: {})
299
- .and_return([created_response, { 'message' => 'Confirmation message.' }])
300
- expect(described_class).to receive(:fetch).with('created-zone-uuid').and_return(created_zone)
301
- expect(described_class.create('Name')).to be created_zone
302
- end
303
- end
304
-
305
- describe '.list' do
306
- subject { described_class.list }
307
-
308
- before :each do
309
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone', 'list.yml'))
310
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones')
311
- .and_return([nil, YAML.load_file(body_fixture)])
312
- end
313
-
314
- its('count') { should eq 1 }
315
- its('first.uuid') { should eq 'zone-uuid' }
316
- its('first.name') { should eq 'Name' }
317
- its('first.sharing_uuid') { should be nil }
318
- its('first.soa_retry') { should eq 3_600 }
319
- its('first.soa_minimum') { should eq 900 }
320
- its('first.soa_refresh') { should eq 10_800 }
321
- its('first.soa_expire') { should eq 604_800 }
322
- its('first.soa_serial') { should eq 1_432_798_405 }
323
- its('first.soa_email') { should eq 'hostmaster.gandi.net.' }
324
- its('first.soa_primary_ns') { should eq 'a.dns.gandi.net.' }
325
- end
326
-
327
- describe '.fetch' do
328
- subject { described_class.fetch 'zone-uuid' }
329
-
330
- before :each do
331
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone', 'fetch.yml'))
332
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid')
333
- .and_return([nil, YAML.load_file(body_fixture)])
334
- end
335
-
336
- its('uuid') { should eq 'zone-uuid' }
337
- its('name') { should eq 'Name' }
338
- its('sharing_uuid') { should be nil }
339
- its('soa_retry') { should eq 3_600 }
340
- its('soa_minimum') { should eq 900 }
341
- its('soa_refresh') { should eq 10_800 }
342
- its('soa_expire') { should eq 604_800 }
343
- its('soa_serial') { should eq 1_432_798_405 }
344
- its('soa_email') { should eq 'hostmaster.gandi.net.' }
345
- its('soa_primary_ns') { should eq 'a.dns.gandi.net.' }
346
- end
347
- end