gandi_v5 0.2.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +13 -3
  4. data/.travis.yml +15 -1
  5. data/CHANGELOG.md +63 -0
  6. data/FUNDING.yml +10 -0
  7. data/LICENSE.md +2 -6
  8. data/README.md +16 -21
  9. data/gandi_v5.gemspec +3 -2
  10. data/lib/gandi_v5.rb +64 -24
  11. data/lib/gandi_v5/billing.rb +0 -2
  12. data/lib/gandi_v5/billing/info.rb +0 -2
  13. data/lib/gandi_v5/data.rb +1 -4
  14. data/lib/gandi_v5/data/converter.rb +0 -4
  15. data/lib/gandi_v5/data/converter/integer.rb +26 -0
  16. data/lib/gandi_v5/domain.rb +167 -28
  17. data/lib/gandi_v5/domain/availability.rb +0 -3
  18. data/lib/gandi_v5/domain/availability/product.rb +0 -3
  19. data/lib/gandi_v5/domain/live_dns.rb +42 -0
  20. data/lib/gandi_v5/domain/renewal_information.rb +0 -3
  21. data/lib/gandi_v5/domain/sharing_space.rb +10 -2
  22. data/lib/gandi_v5/email.rb +0 -4
  23. data/lib/gandi_v5/email/forward.rb +102 -0
  24. data/lib/gandi_v5/email/mailbox.rb +57 -13
  25. data/lib/gandi_v5/email/slot.rb +11 -3
  26. data/lib/gandi_v5/error.rb +0 -2
  27. data/lib/gandi_v5/live_dns.rb +0 -16
  28. data/lib/gandi_v5/live_dns/domain.rb +221 -80
  29. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
  30. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  31. data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
  32. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
  33. data/lib/gandi_v5/organization.rb +38 -5
  34. data/lib/gandi_v5/organization/customer.rb +90 -0
  35. data/lib/gandi_v5/version.rb +1 -1
  36. data/spec/.rubocop.yml +9 -2
  37. data/spec/fixtures/bodies/GandiV5_Billing/{info.yaml → info.yml} +0 -0
  38. data/spec/fixtures/bodies/GandiV5_Domain/{get.yaml → fetch.yml} +8 -0
  39. data/spec/fixtures/bodies/GandiV5_Domain/{fetch_contacts.yaml → fetch_contacts.yml} +0 -0
  40. data/spec/fixtures/bodies/GandiV5_Domain/fetch_glue_records.yml +7 -0
  41. data/spec/fixtures/bodies/GandiV5_Domain/fetch_livedns.yml +6 -0
  42. data/spec/fixtures/bodies/GandiV5_Domain/fetch_name_servers.yml +2 -0
  43. data/spec/fixtures/bodies/GandiV5_Domain/{renewal_info.yaml → fetch_renewal_info.yml} +0 -3
  44. data/spec/fixtures/bodies/GandiV5_Domain/{restore_info.yaml → fetch_restore_info.yml} +0 -0
  45. data/spec/fixtures/bodies/GandiV5_Domain/{list.yaml → list.yml} +1 -0
  46. data/spec/fixtures/bodies/GandiV5_Domain_Availability/{fetch.yaml → fetch.yml} +0 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TLD/{fetch.yaml → fetch.yml} +0 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_TLD/{list.yaml → list.yml} +0 -0
  49. data/spec/fixtures/bodies/GandiV5_Email_Forward/list.yml +6 -0
  50. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/{get.yaml → fetch.yml} +0 -0
  51. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/{list.yaml → list.yml} +0 -0
  52. data/spec/fixtures/bodies/GandiV5_Email_Slot/{get.yaml → fetch.yml} +0 -0
  53. data/spec/fixtures/bodies/GandiV5_Email_Slot/{list.yaml → list.yml} +0 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +3 -0
  55. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/{list.yaml → list.yml} +0 -0
  56. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  57. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  58. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  59. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  60. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot/fetch.yaml → GandiV5_LiveDNS_Domain_Snapshot/fetch.yml} +4 -3
  61. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  62. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  63. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  64. data/spec/fixtures/bodies/GandiV5_Organization/{get.yaml → fetch.yml} +0 -0
  65. data/spec/fixtures/bodies/GandiV5_Organization/list.yml +7 -0
  66. data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
  67. data/spec/spec_helper.rb +2 -2
  68. data/spec/units/gandi_v5/billing_spec.rb +2 -2
  69. data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
  70. data/spec/units/gandi_v5/domain/availability_spec.rb +1 -1
  71. data/spec/units/gandi_v5/domain/live_dns_spec.rb +45 -0
  72. data/spec/units/gandi_v5/domain/tld_spec.rb +2 -2
  73. data/spec/units/gandi_v5/domain_spec.rb +294 -65
  74. data/spec/units/gandi_v5/email/forward_spec.rb +92 -0
  75. data/spec/units/gandi_v5/email/mailbox_spec.rb +122 -40
  76. data/spec/units/gandi_v5/email/slot_spec.rb +13 -5
  77. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  78. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  79. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  80. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  81. data/spec/units/gandi_v5/live_dns/domain_spec.rb +299 -120
  82. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  83. data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
  84. data/spec/units/gandi_v5/organization_spec.rb +52 -1
  85. data/spec/units/gandi_v5_spec.rb +139 -30
  86. metadata +68 -95
  87. data/doc/GandiV5.html +0 -1183
  88. data/doc/GandiV5/Billing.html +0 -293
  89. data/doc/GandiV5/Billing/Info.html +0 -641
  90. data/doc/GandiV5/Billing/Info/Prepaid.html +0 -817
  91. data/doc/GandiV5/Data.html +0 -785
  92. data/doc/GandiV5/Data/ClassMethods.html +0 -223
  93. data/doc/GandiV5/Data/Converter.html +0 -433
  94. data/doc/GandiV5/Data/Converter/ArrayOf.html +0 -413
  95. data/doc/GandiV5/Data/Converter/Symbol.html +0 -322
  96. data/doc/GandiV5/Data/Converter/Time.html +0 -330
  97. data/doc/GandiV5/Domain.html +0 -16847
  98. data/doc/GandiV5/Domain/AutoRenew.html +0 -1237
  99. data/doc/GandiV5/Domain/Availability.html +0 -1020
  100. data/doc/GandiV5/Domain/Availability/Product.html +0 -988
  101. data/doc/GandiV5/Domain/Availability/Product/Period.html +0 -220
  102. data/doc/GandiV5/Domain/Availability/Product/Price.html +0 -1031
  103. data/doc/GandiV5/Domain/Availability/Tax.html +0 -440
  104. data/doc/GandiV5/Domain/Contact.html +0 -4459
  105. data/doc/GandiV5/Domain/Contract.html +0 -520
  106. data/doc/GandiV5/Domain/Dates.html +0 -1313
  107. data/doc/GandiV5/Domain/RenewalInformation.html +0 -1147
  108. data/doc/GandiV5/Domain/RestoreInformation.html +0 -339
  109. data/doc/GandiV5/Domain/SharingSpace.html +0 -437
  110. data/doc/GandiV5/Domain/TLD.html +0 -1565
  111. data/doc/GandiV5/Email.html +0 -144
  112. data/doc/GandiV5/Email/Mailbox.html +0 -6307
  113. data/doc/GandiV5/Email/Mailbox/Responder.html +0 -1560
  114. data/doc/GandiV5/Email/Offer.html +0 -514
  115. data/doc/GandiV5/Email/Slot.html +0 -4244
  116. data/doc/GandiV5/Error.html +0 -151
  117. data/doc/GandiV5/Error/GandiError.html +0 -270
  118. data/doc/GandiV5/LiveDNS.html +0 -300
  119. data/doc/GandiV5/LiveDNS/Domain.html +0 -2984
  120. data/doc/GandiV5/LiveDNS/RecordSet.html +0 -1593
  121. data/doc/GandiV5/LiveDNS/Zone.html +0 -8891
  122. data/doc/GandiV5/LiveDNS/Zone/Snapshot.html +0 -1556
  123. data/doc/GandiV5/Organization.html +0 -2341
  124. data/doc/_index.html +0 -474
  125. data/doc/class_list.html +0 -51
  126. data/doc/css/common.css +0 -1
  127. data/doc/css/full_list.css +0 -58
  128. data/doc/css/style.css +0 -496
  129. data/doc/file.README.html +0 -175
  130. data/doc/file_list.html +0 -56
  131. data/doc/frames.html +0 -17
  132. data/doc/index.html +0 -175
  133. data/doc/js/app.js +0 -303
  134. data/doc/js/full_list.js +0 -216
  135. data/doc/js/jquery.js +0 -4
  136. data/doc/method_list.html +0 -2427
  137. data/doc/top-level-namespace.html +0 -110
  138. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  139. data/lib/gandi_v5/live_dns/zone.rb +0 -305
  140. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  141. data/spec/features/domain_spec.rb +0 -45
  142. data/spec/features/livedns_domain_spec.rb +0 -8
  143. data/spec/features/livedns_zone_spec.rb +0 -45
  144. data/spec/features/mailbox_spec.rb +0 -18
  145. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/get.yaml +0 -4
  146. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/get.yaml +0 -11
  147. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yaml +0 -11
  148. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yaml +0 -3
  149. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -54
  150. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  151. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  152. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  153. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  154. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  155. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  156. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  157. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Email::Forward do
4
+ subject { described_class.new source: 'alice', destinations: ['bob@example.com'], fqdn: 'example.com' }
5
+
6
+ describe '#update' do
7
+ it 'ʘ‿ʘ' do
8
+ expect(GandiV5).to receive(:put).with(
9
+ 'https://api.gandi.net/v5/email/forwards/example.com/alice',
10
+ '{"destinations":["bob@example.com","charlie@example.com"]}'
11
+ )
12
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
13
+ expect(subject.update('bob@example.com', 'charlie@example.com')).to eq 'Confirmation message.'
14
+ expect(subject.destinations).to match_array ['bob@example.com', 'charlie@example.com']
15
+ end
16
+
17
+ it 'Empty destinations' do
18
+ expect { subject.update }.to raise_error ArgumentError, 'destinations can\'t be empty'
19
+ end
20
+ end
21
+
22
+ it '#delete' do
23
+ expect(GandiV5).to receive(:delete).with(
24
+ 'https://api.gandi.net/v5/email/forwards/example.com/alice'
25
+ )
26
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
27
+ expect(subject.delete).to eq 'Confirmation message.'
28
+ end
29
+
30
+ describe '#to_s' do
31
+ it 'With one destination' do
32
+ expect(subject.to_s).to eq 'alice@example.com -> bob@example.com'
33
+ end
34
+
35
+ it 'With many destinations' do
36
+ subject.instance_exec { @destinations = ['bob@example.com', 'charlie@example.com'] }
37
+ expect(subject.to_s).to eq 'alice@example.com -> bob@example.com, charlie@example.com'
38
+ end
39
+ end
40
+
41
+ describe '.create' do
42
+ it 'ʘ‿ʘ' do
43
+ response = double(
44
+ RestClient::Response,
45
+ headers: { location: 'https://api.gandi.net/v5/email/forwards/example.com/alice' }
46
+ )
47
+ expect(GandiV5).to receive(:post).with(
48
+ 'https://api.gandi.net/v5/email/forwards/example.com',
49
+ '{"source":"alice","destinations":["bob@example.com"]}'
50
+ )
51
+ .and_return([response, { 'message' => 'Confirmation message.' }])
52
+
53
+ forward = described_class.new fqdn: 'example.com', source: 'alice', destinations: ['bob@example.com']
54
+ expect(described_class.create('example.com', 'alice', 'bob@example.com').to_h).to eq forward.to_h
55
+ end
56
+
57
+ it 'Empty destinations' do
58
+ expect { described_class.create('example.com', 'alice') }.to raise_error ArgumentError, 'destinations can\'t be empty'
59
+ end
60
+ end
61
+
62
+ describe '.list' do
63
+ let(:body_fixture) do
64
+ File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Forward', 'list.yml'))
65
+ end
66
+ let(:url) { 'https://api.gandi.net/v5/email/forwards/example.com' }
67
+
68
+ describe 'With default values' do
69
+ subject { described_class.list 'example.com' }
70
+
71
+ before :each do
72
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
73
+ .and_yield(YAML.load_file(body_fixture))
74
+ end
75
+
76
+ its('count') { should eq 1 }
77
+ its('first.source') { should eq 'alice' }
78
+ its('first.destinations') { should match_array ['bob@example.com', 'charlie@example.com'] }
79
+ its('first.fqdn') { should eq 'example.com' }
80
+ end
81
+
82
+ describe 'Passes optional query params' do
83
+ %i[source sort_by].each do |param|
84
+ it param.to_s do
85
+ headers = { params: { param => 'value' } }
86
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, **headers)
87
+ expect(described_class.list('example.com', param => 'value')).to eq []
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -9,7 +9,7 @@ describe GandiV5::Email::Mailbox do
9
9
 
10
10
  describe '#refresh' do
11
11
  before :each do
12
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'get.yaml'))
12
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'fetch.yml'))
13
13
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid')
14
14
  .and_return([nil, YAML.load_file(body_fixture)])
15
15
  subject.refresh
@@ -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,13 +356,23 @@ 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
260
372
  subject { described_class.fetch 'example.com', 'mailbox-uuid' }
261
373
 
262
374
  before :each do
263
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'get.yaml'))
375
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'fetch.yml'))
264
376
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid')
265
377
  .and_return([nil, YAML.load_file(body_fixture)])
266
378
  end
@@ -281,16 +393,16 @@ describe GandiV5::Email::Mailbox do
281
393
 
282
394
  describe '.list' do
283
395
  let(:body_fixture) do
284
- File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Mailbox', 'list.yaml'))
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
- headers = { params: { page: 1 } }
292
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/mailboxes/example.com', headers)
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
- headers = { params: { page: 1 }.merge(query_param => 'value') }
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
@@ -28,7 +28,7 @@ describe GandiV5::Email::Slot do
28
28
 
29
29
  describe '#refresh' do
30
30
  before :each do
31
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'get.yaml'))
31
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'fetch.yml'))
32
32
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com/123')
33
33
  .and_return([nil, YAML.load_file(body_fixture)])
34
34
  subject.refresh
@@ -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
 
@@ -151,7 +159,7 @@ describe GandiV5::Email::Slot do
151
159
  subject { described_class.fetch 'example.com', 123 }
152
160
 
153
161
  before :each do
154
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'get.yaml'))
162
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'fetch.yml'))
155
163
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com/123')
156
164
  .and_return([nil, YAML.load_file(body_fixture)])
157
165
  end
@@ -171,7 +179,7 @@ describe GandiV5::Email::Slot do
171
179
  subject { described_class.list 'example.com' }
172
180
 
173
181
  before :each do
174
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'list.yaml'))
182
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Email_Slot', 'list.yml'))
175
183
  expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/email/slots/example.com')
176
184
  .and_return([nil, YAML.load_file(body_fixture)])
177
185
  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