gandi_v5 0.8.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -9
- data/README.md +64 -15
- data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
- data/lib/gandi_v5/data/converter/array_of.rb +3 -2
- data/lib/gandi_v5/data/converter/integer.rb +3 -2
- data/lib/gandi_v5/data/converter/symbol.rb +3 -2
- data/lib/gandi_v5/data/converter/time.rb +3 -2
- data/lib/gandi_v5/data/converter.rb +3 -2
- data/lib/gandi_v5/data.rb +13 -14
- data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
- data/lib/gandi_v5/domain/contact.rb +5 -5
- data/lib/gandi_v5/domain/tld.rb +2 -2
- data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
- data/lib/gandi_v5/domain/transfer_in.rb +172 -0
- data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
- data/lib/gandi_v5/domain.rb +52 -13
- data/lib/gandi_v5/email/forward.rb +1 -1
- data/lib/gandi_v5/email/mailbox.rb +6 -6
- data/lib/gandi_v5/email/slot.rb +1 -1
- data/lib/gandi_v5/email.rb +3 -0
- data/lib/gandi_v5/error/gandi_error.rb +1 -0
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +16 -11
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +5 -1
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +8 -5
- data/lib/gandi_v5/live_dns/domain.rb +29 -1
- data/lib/gandi_v5/live_dns.rb +2 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +1 -1
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +2 -1
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +90 -5
- data/lib/gandi_v5/simple_hosting/instance.rb +9 -0
- data/lib/gandi_v5/simple_hosting.rb +1 -0
- data/lib/gandi_v5/template/dispatch.rb +109 -0
- data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
- data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
- data/lib/gandi_v5/template/payload.rb +64 -0
- data/lib/gandi_v5/template.rb +271 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/lib/gandi_v5.rb +115 -66
- data/spec/.rubocop.yml +3 -50
- data/spec/features/list_domain_renewals_spec.rb +16 -0
- data/spec/features/list_email_addresses_spec.rb +39 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
- data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
- data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
- data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
- data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
- data/spec/spec_helper.rb +8 -7
- data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
- data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
- data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
- data/spec/units/gandi_v5/domain_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +125 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +8 -0
- data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
- data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
- data/spec/units/gandi_v5/template_spec.rb +341 -0
- data/spec/units/gandi_v5_spec.rb +1 -1
- metadata +191 -57
- data/.gitignore +0 -26
- data/.rspec +0 -3
- data/.rubocop.yml +0 -74
- data/.travis.yml +0 -38
- data/FUNDING.yml +0 -10
- data/Gemfile +0 -6
- data/Guardfile +0 -39
- data/Rakefile +0 -3
- data/bin/console +0 -13
- data/gandi_v5.gemspec +0 -42
- data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
- data/spec/units/gandi_v5/error_spec.rb +0 -4
- data/spec/units/gandi_v5/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +0 -4
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GandiV5::Domain::WebForwarding do
|
4
|
+
subject { described_class.new fqdn: 'host.example.com' }
|
5
|
+
|
6
|
+
describe '#update' do
|
7
|
+
let(:url) { 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com' }
|
8
|
+
let(:updated_forwarding) { double GandiV5::Domain::WebForwarding }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
expect(subject).to receive(:refresh).and_return(updated_forwarding)
|
12
|
+
subject.instance_exec { @domain = 'example.com' }
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'nothing' do
|
16
|
+
expect(GandiV5).to receive(:patch).with(url, '{}')
|
17
|
+
expect(subject.update).to be updated_forwarding
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'target' do
|
21
|
+
expect(GandiV5).to receive(:patch).with(url, '{"url":"new"}')
|
22
|
+
expect(subject.update(target: 'new')).to be updated_forwarding
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'override' do
|
26
|
+
expect(GandiV5).to receive(:patch).with(url, '{"override":false}')
|
27
|
+
expect(subject.update(override: false)).to be updated_forwarding
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'protocol' do
|
31
|
+
expect(GandiV5).to receive(:patch).with(url, '{"protocol":"httpsonly"}')
|
32
|
+
expect(subject.update(protocol: :httpsonly)).to be updated_forwarding
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'type' do
|
36
|
+
expect(GandiV5).to receive(:patch).with(url, '{"type":"http302"}')
|
37
|
+
expect(subject.update(type: :http302)).to be updated_forwarding
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it '#delete' do
|
42
|
+
url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com'
|
43
|
+
expect(GandiV5).to receive(:delete).with(url).and_return([nil, { 'message' => 'Confirmation message.' }])
|
44
|
+
subject.instance_exec { @domain = 'example.com' }
|
45
|
+
expect(subject.delete).to eq 'Confirmation message.'
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'helper methods' do
|
49
|
+
context 'an HTTP 301 redirect' do
|
50
|
+
subject { described_class.new type: :http301 }
|
51
|
+
it('#permanent?') { expect(subject.permanent?).to be true }
|
52
|
+
it('#http301?') { expect(subject.http301?).to be true }
|
53
|
+
it('#temporary?') { expect(subject.temporary?).to be false }
|
54
|
+
it('#http302?') { expect(subject.http302?).to be false }
|
55
|
+
it('#found?') { expect(subject.found?).to be false }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'an HTTP 302 redirect' do
|
59
|
+
subject { described_class.new type: :http302 }
|
60
|
+
it('#permanent?') { expect(subject.permanent?).to be false }
|
61
|
+
it('#http301?') { expect(subject.http301?).to be false }
|
62
|
+
it('#temporary?') { expect(subject.temporary?).to be true }
|
63
|
+
it('#http302?') { expect(subject.http302?).to be true }
|
64
|
+
it('#found?') { expect(subject.found?).to be true }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'an http endpoint' do
|
68
|
+
subject { described_class.new protocol: :http }
|
69
|
+
it('#http?') { expect(subject.http?).to be true }
|
70
|
+
it('#https?') { expect(subject.https?).to be false }
|
71
|
+
it('#https_only?') { expect(subject.https_only?).to be false }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'an https endpoint' do
|
75
|
+
subject { described_class.new protocol: :https }
|
76
|
+
it('#http?') { expect(subject.http?).to be true }
|
77
|
+
it('#https?') { expect(subject.https?).to be true }
|
78
|
+
it('#https_only?') { expect(subject.https_only?).to be false }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'an https_only endpoint' do
|
82
|
+
subject { described_class.new protocol: :https_only }
|
83
|
+
it('#http?') { expect(subject.http?).to be false }
|
84
|
+
it('#https?') { expect(subject.https?).to be true }
|
85
|
+
it('#https_only?') { expect(subject.https_only?).to be true }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.fetch' do
|
90
|
+
subject { described_class.fetch 'example.com', 'host' }
|
91
|
+
|
92
|
+
before :each do
|
93
|
+
body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_WebForwarding', 'fetch.yml'))
|
94
|
+
url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com'
|
95
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
|
96
|
+
end
|
97
|
+
|
98
|
+
its('created_at') { should eq Time.new(2020, 11, 29, 14, 57, 14) }
|
99
|
+
its('updated_at') { should eq Time.new(2020, 11, 29, 14, 57, 15) }
|
100
|
+
its('type') { should eq :http301 }
|
101
|
+
its('fqdn') { should eq 'here.example.com' }
|
102
|
+
its('protocol') { should eq :https }
|
103
|
+
its('target') { should eq 'https://example.com/here' }
|
104
|
+
its('cert_status') { should eq '?' }
|
105
|
+
its('cert_uuid') { should eq 'cert-uuid' }
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '.list' do
|
109
|
+
subject { described_class.list 'example.com' }
|
110
|
+
|
111
|
+
before :each do
|
112
|
+
body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_WebForwarding', 'list.yml'))
|
113
|
+
url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs'
|
114
|
+
expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100)
|
115
|
+
.and_yield(YAML.load_file(body_fixture))
|
116
|
+
end
|
117
|
+
|
118
|
+
its('count') { should eq 1 }
|
119
|
+
its('first.created_at') { should eq Time.new(2020, 11, 29, 14, 57, 14) }
|
120
|
+
its('first.updated_at') { should eq Time.new(2020, 11, 29, 14, 57, 15) }
|
121
|
+
its('first.type') { should eq :http301 }
|
122
|
+
its('first.fqdn') { should eq 'here.example.com' }
|
123
|
+
its('first.protocol') { should eq :https }
|
124
|
+
its('first.target') { should eq 'https://example.com/here' }
|
125
|
+
its('first.cert_status') { should eq '?' }
|
126
|
+
its('first.cert_uuid') { should eq 'cert-uuid' }
|
127
|
+
end
|
128
|
+
|
129
|
+
it '.create' do
|
130
|
+
url = 'https://api.gandi.net/v5/domain/domains/example.com/webredirs'
|
131
|
+
body = '{"host":"host","protocol":"httpsonly","type":"http302","url":"example.com","override":true}'
|
132
|
+
response = double(
|
133
|
+
RestClient::Response,
|
134
|
+
headers: { location: ' https://api.gandi.net/v5/domain/domains/example.com/webredirs/host.example.com' }
|
135
|
+
)
|
136
|
+
created_forwarding = double GandiV5::Domain::WebForwarding
|
137
|
+
expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
|
138
|
+
expect(described_class).to receive(:fetch).with('example.com', 'host').and_return(created_forwarding)
|
139
|
+
|
140
|
+
create = {
|
141
|
+
domain: 'example.com',
|
142
|
+
host: 'host',
|
143
|
+
target: 'example.com',
|
144
|
+
protocol: :https_only,
|
145
|
+
type: :http302,
|
146
|
+
override: true
|
147
|
+
}
|
148
|
+
expect(described_class.create(**create)).to be created_forwarding
|
149
|
+
end
|
150
|
+
end
|
@@ -208,6 +208,18 @@ describe GandiV5::Domain do
|
|
208
208
|
expect(subject.email_forwards(param: :value)).to be returns
|
209
209
|
end
|
210
210
|
|
211
|
+
it '.webforwardings' do
|
212
|
+
returns = double Array
|
213
|
+
expect(GandiV5::Domain::WebForwarding).to receive(:list).with('example.com', param: :value).and_return(returns)
|
214
|
+
expect(subject.web_forwardings(param: :value)).to be returns
|
215
|
+
end
|
216
|
+
|
217
|
+
it '.webforwarding' do
|
218
|
+
returns = double Array
|
219
|
+
expect(GandiV5::Domain::WebForwarding).to receive(:fetch).with('example.com', 'host').and_return(returns)
|
220
|
+
expect(subject.web_forwarding('host')).to be returns
|
221
|
+
end
|
222
|
+
|
211
223
|
describe '#to_s' do
|
212
224
|
it 'Has identical fqdn and fqdn_unicode' do
|
213
225
|
domain = described_class.new fqdn: 'example.com', fqdn_unicode: 'example.com'
|
@@ -494,6 +506,44 @@ describe GandiV5::Domain do
|
|
494
506
|
end
|
495
507
|
end
|
496
508
|
|
509
|
+
describe '#transfer_lock' do
|
510
|
+
it 'Passing nothing' do
|
511
|
+
expect(GandiV5).to receive(:patch).with(
|
512
|
+
'https://api.gandi.net/v5/domain/domains/example.com/status',
|
513
|
+
'{"clientTransferProhibited":true}'
|
514
|
+
).and_return([nil, { 'message' => 'Confirmation message.' }])
|
515
|
+
expect(subject.transfer_lock).to eq 'Confirmation message.'
|
516
|
+
expect(subject.status).to eq 'clientTransferProhibited'
|
517
|
+
end
|
518
|
+
|
519
|
+
it 'Passing true' do
|
520
|
+
expect(GandiV5).to receive(:patch).with(
|
521
|
+
'https://api.gandi.net/v5/domain/domains/example.com/status',
|
522
|
+
'{"clientTransferProhibited":true}'
|
523
|
+
).and_return([nil, { 'message' => 'Confirmation message.' }])
|
524
|
+
expect(subject.transfer_lock(true)).to eq 'Confirmation message.'
|
525
|
+
expect(subject.status).to eq 'clientTransferProhibited'
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'Passing false' do
|
529
|
+
expect(GandiV5).to receive(:patch).with(
|
530
|
+
'https://api.gandi.net/v5/domain/domains/example.com/status',
|
531
|
+
'{"clientTransferProhibited":false}'
|
532
|
+
).and_return([nil, { 'message' => 'Confirmation message.' }])
|
533
|
+
expect(subject.transfer_lock(false)).to eq 'Confirmation message.'
|
534
|
+
expect(subject.status).to be nil
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
it '#transfer_unlock' do
|
539
|
+
expect(GandiV5).to receive(:patch).with(
|
540
|
+
'https://api.gandi.net/v5/domain/domains/example.com/status',
|
541
|
+
'{"clientTransferProhibited":false}'
|
542
|
+
).and_return([nil, { 'message' => 'Confirmation message.' }])
|
543
|
+
expect(subject.transfer_unlock).to eq 'Confirmation message.'
|
544
|
+
expect(subject.status).to be nil
|
545
|
+
end
|
546
|
+
|
497
547
|
describe '#glue_records' do
|
498
548
|
let(:glue_records) { double Hash }
|
499
549
|
|
@@ -28,6 +28,85 @@ describe GandiV5::SimpleHosting::Instance::VirtualHost do
|
|
28
28
|
expect(subject.linked_dns_zone.cname).to_not be nil
|
29
29
|
end
|
30
30
|
|
31
|
+
describe '#update' do
|
32
|
+
describe 'application' do
|
33
|
+
it 'Given a GandiV5::SimpleHosting::Instance::Application' do
|
34
|
+
application = GandiV5::SimpleHosting::Instance::Application.new(
|
35
|
+
name: 'app-name',
|
36
|
+
parameters: {}
|
37
|
+
)
|
38
|
+
|
39
|
+
expect(GandiV5).to receive(:put).with(
|
40
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
41
|
+
'{"application":{"name":"app-name","parameters":{}}}'
|
42
|
+
).and_return([nil, body_fetch])
|
43
|
+
subject.update(application: application)
|
44
|
+
|
45
|
+
expect(subject.application.name).to eq 'app-name'
|
46
|
+
expect(subject.application.parameters).to eq({})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Given a Hash' do
|
50
|
+
expect(GandiV5).to receive(:put).with(
|
51
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
52
|
+
'{"application":{"name":"app-name"}}'
|
53
|
+
).and_return([nil, body_fetch])
|
54
|
+
subject.update(application: { name: 'app-name' })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'https_strategy' do
|
59
|
+
it ':redirect_http_to_https' do
|
60
|
+
expect(GandiV5).to receive(:put).with(
|
61
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
62
|
+
'{"https_strategy":"redirect_HTTP_to_HTTPS"}'
|
63
|
+
).and_return([nil, body_fetch])
|
64
|
+
subject.update(https_strategy: :redirect_http_to_https)
|
65
|
+
expect(subject.https_strategy).to be :redirect_http_to_https
|
66
|
+
end
|
67
|
+
|
68
|
+
it ':allow_http_and_https' do
|
69
|
+
expect(GandiV5).to receive(:put).with(
|
70
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
71
|
+
'{"https_strategy":"allow_HTTP_and_HTTPS"}'
|
72
|
+
).and_return([nil, body_fetch])
|
73
|
+
subject.update(https_strategy: :allow_http_and_https)
|
74
|
+
expect(subject.https_strategy).to be :redirect_http_to_https
|
75
|
+
end
|
76
|
+
|
77
|
+
it ':http_only' do
|
78
|
+
expect(GandiV5).to receive(:put).with(
|
79
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
80
|
+
'{"https_strategy":"HTTP_only"}'
|
81
|
+
).and_return([nil, body_fetch])
|
82
|
+
subject.update(https_strategy: :http_only)
|
83
|
+
expect(subject.https_strategy).to be :redirect_http_to_https
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'invalid' do
|
87
|
+
expect(GandiV5).not_to receive(:put)
|
88
|
+
expect { subject.update(https_strategy: :invalid) }.to \
|
89
|
+
raise_error ArgumentError, 'https_strategy :invalid is invalid'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'linked_dns_zone' do
|
94
|
+
expect(GandiV5).to receive(:put).with(
|
95
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
|
96
|
+
'{"linked_dns_zone":{"allow_alteration":false,"allow_alteration_override":true}}'
|
97
|
+
).and_return([nil, body_fetch])
|
98
|
+
subject.update(linked_dns_zone_allow_alteration: false, linked_dns_zone_allow_alteration_override: true)
|
99
|
+
expect(subject.linked_dns_zone.allow_alteration).to be true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it '#delete' do
|
104
|
+
expect(GandiV5).to receive(:delete).with(
|
105
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
|
106
|
+
).and_return([nil, { 'message' => 'Confirmation message.' }])
|
107
|
+
expect(subject.delete).to eq 'Confirmation message.'
|
108
|
+
end
|
109
|
+
|
31
110
|
describe 'Helper methods' do
|
32
111
|
describe 'Status' do
|
33
112
|
context 'being_created' do
|
@@ -130,6 +209,52 @@ describe GandiV5::SimpleHosting::Instance::VirtualHost do
|
|
130
209
|
end
|
131
210
|
end
|
132
211
|
|
212
|
+
describe '.create' do
|
213
|
+
it 'With just fqdn' do
|
214
|
+
expect(GandiV5).to receive(:post).with(
|
215
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
|
216
|
+
'{"fqdn":"vh.example.com"}'
|
217
|
+
).and_return([nil, nil])
|
218
|
+
|
219
|
+
url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
|
220
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
|
221
|
+
|
222
|
+
subject = described_class.create('instance-uuid', 'vh.example.com')
|
223
|
+
expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'Also with application' do
|
227
|
+
expect(GandiV5).to receive(:post).with(
|
228
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
|
229
|
+
'{"fqdn":"vh.example.com","application":{"name":"app-name"}}'
|
230
|
+
).and_return([nil, nil])
|
231
|
+
|
232
|
+
url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
|
233
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
|
234
|
+
|
235
|
+
subject = described_class.create('instance-uuid', 'vh.example.com', application: { name: 'app-name' })
|
236
|
+
expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'Also with linked_dns_zone' do
|
240
|
+
expect(GandiV5).to receive(:post).with(
|
241
|
+
'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
|
242
|
+
'{"fqdn":"vh.example.com","linked_dns_zone":{"allow_alteration":false,"allow_alteration_override":true}}'
|
243
|
+
).and_return([nil, nil])
|
244
|
+
|
245
|
+
url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
|
246
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
|
247
|
+
|
248
|
+
subject = described_class.create(
|
249
|
+
'instance-uuid',
|
250
|
+
'vh.example.com',
|
251
|
+
linked_dns_zone_allow_alteration: false,
|
252
|
+
linked_dns_zone_allow_alteration_override: true
|
253
|
+
)
|
254
|
+
expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
133
258
|
describe '.list' do
|
134
259
|
subject { described_class.list('instance-uuid') }
|
135
260
|
let(:url) { 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts' }
|
@@ -179,4 +179,12 @@ describe GandiV5::SimpleHosting::Instance do
|
|
179
179
|
its('upgrade_to.first.type') { should eq 'database' }
|
180
180
|
its('upgrade_to.first.version') { should eq 'upgrade to version' }
|
181
181
|
end
|
182
|
+
|
183
|
+
it '.create_virtual_host' do
|
184
|
+
returns = double Object
|
185
|
+
expect(GandiV5::SimpleHosting::Instance::VirtualHost).to receive(:create).with('instance-uuid', 'fqdn', key: :value)
|
186
|
+
.and_return(returns)
|
187
|
+
expect(subject).to receive(:refresh)
|
188
|
+
subject.create_virtual_host 'fqdn', key: :value
|
189
|
+
end
|
182
190
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GandiV5::Template::Dispatch do
|
4
|
+
subject do
|
5
|
+
described_class.new uuid: 'dispatch-uuid'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.fetch' do
|
9
|
+
subject { described_class.fetch('dispatch-uuid') }
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:url) { 'https://api.gandi.net/v5/template/dispatch/dispatch-uuid' }
|
16
|
+
let(:body_fixture) do
|
17
|
+
File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Template_Dispatch', 'fetch.yml'))
|
18
|
+
end
|
19
|
+
|
20
|
+
its('attempt') { should eq 1 }
|
21
|
+
its('created_at') { should eq Time.new(2020, 11, 29, 14, 57, 14) }
|
22
|
+
its('uuid') { should eq 'dispatch-uuid' }
|
23
|
+
its('created_by') { should eq 'sharing-uuid' }
|
24
|
+
its('state') { should be :running }
|
25
|
+
its('state_message') { should eq 'state message' }
|
26
|
+
its('updated_at') { should eq Time.new(2020, 11, 29, 14, 57, 15) }
|
27
|
+
its('template_uuid') { should eq 'template-uuid' }
|
28
|
+
its('template_name') { should eq 'template' }
|
29
|
+
its('target_uuid') { should eq 'target-uuid' }
|
30
|
+
its('task_history') do
|
31
|
+
should eq(
|
32
|
+
[
|
33
|
+
{
|
34
|
+
at: Time.new(2020, 11, 29, 16, 57, 47),
|
35
|
+
what: :name_servers,
|
36
|
+
status: :done,
|
37
|
+
message: ''
|
38
|
+
}
|
39
|
+
]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
its('task_statuses') do
|
43
|
+
should eq(
|
44
|
+
{
|
45
|
+
dns_records: :pending,
|
46
|
+
mailboxes: :running,
|
47
|
+
name_servers: :done,
|
48
|
+
web_forwardings: :error
|
49
|
+
}
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
its('payload.dns_records.count') { should eq 1 }
|
54
|
+
its('payload.dns_records.first.name') { should eq 'record-name' }
|
55
|
+
its('payload.dns_records.first.type') { should eq 'TXT' }
|
56
|
+
its('payload.dns_records.first.values') { should eq ['record-value'] }
|
57
|
+
its('payload.dns_records.first.ttl') { should eq 600 }
|
58
|
+
|
59
|
+
its('payload.mailboxes') { should eq ['user-name'] }
|
60
|
+
|
61
|
+
its('payload.name_servers') { should eq ['1.1.1.1'] }
|
62
|
+
|
63
|
+
its('payload.web_forwardings.count') { should eq 1 }
|
64
|
+
its('payload.web_forwardings.first.type') { should eq :http301 }
|
65
|
+
its('payload.web_forwardings.first.target') { should eq 'https://example.com/here' }
|
66
|
+
its('payload.web_forwardings.first.fqdn') { should eq 'here.example.com' }
|
67
|
+
its('payload.web_forwardings.first.override') { should be true }
|
68
|
+
its('payload.web_forwardings.first.protocol') { should eq :https }
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GandiV5::Template::Payload::WebForwarding do
|
4
|
+
describe 'helper methods' do
|
5
|
+
context 'an HTTP 301 redirect' do
|
6
|
+
subject { described_class.new type: :http301 }
|
7
|
+
it('#permanent?') { expect(subject.permanent?).to be true }
|
8
|
+
it('#http301?') { expect(subject.http301?).to be true }
|
9
|
+
it('#temporary?') { expect(subject.temporary?).to be false }
|
10
|
+
it('#http302?') { expect(subject.http302?).to be false }
|
11
|
+
it('#found?') { expect(subject.found?).to be false }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'an HTTP 302 redirect' do
|
15
|
+
subject { described_class.new type: :http302 }
|
16
|
+
it('#permanent?') { expect(subject.permanent?).to be false }
|
17
|
+
it('#http301?') { expect(subject.http301?).to be false }
|
18
|
+
it('#temporary?') { expect(subject.temporary?).to be true }
|
19
|
+
it('#http302?') { expect(subject.http302?).to be true }
|
20
|
+
it('#found?') { expect(subject.found?).to be true }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'an http endpoint' do
|
24
|
+
subject { described_class.new protocol: :http }
|
25
|
+
it('#http?') { expect(subject.http?).to be true }
|
26
|
+
it('#https?') { expect(subject.https?).to be false }
|
27
|
+
it('#https_only?') { expect(subject.https_only?).to be false }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'an https endpoint' do
|
31
|
+
subject { described_class.new protocol: :https }
|
32
|
+
it('#http?') { expect(subject.http?).to be true }
|
33
|
+
it('#https?') { expect(subject.https?).to be true }
|
34
|
+
it('#https_only?') { expect(subject.https_only?).to be false }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'an https_only endpoint' do
|
38
|
+
subject { described_class.new protocol: :https_only }
|
39
|
+
it('#http?') { expect(subject.http?).to be false }
|
40
|
+
it('#https?') { expect(subject.https?).to be true }
|
41
|
+
it('#https_only?') { expect(subject.https_only?).to be true }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|