gandirb 1.1.1 → 2.0.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.
- data/CHANGELOG +6 -0
- data/LICENSE +1 -1
- data/README.rdoc +22 -24
- data/Rakefile +8 -9
- data/USAGE.rdoc +131 -0
- data/gandirb.gemspec +7 -9
- data/lib/gandi/connection.rb +65 -0
- data/lib/gandi/connector.rb +7 -0
- data/lib/gandi/contact.rb +175 -0
- data/lib/gandi/domain/contacts.rb +21 -0
- data/lib/gandi/domain/forward.rb +58 -0
- data/lib/gandi/domain/host.rb +63 -0
- data/lib/gandi/domain/mailbox.rb +72 -0
- data/lib/gandi/domain/nameservers.rb +17 -0
- data/lib/gandi/domain/status.rb +19 -0
- data/lib/gandi/domain/tld.rb +17 -0
- data/lib/gandi/domain/transferin.rb +13 -0
- data/lib/gandi/domain.rb +61 -128
- data/lib/gandi/errors.rb +10 -0
- data/lib/gandi/gandi_object_methods.rb +23 -0
- data/lib/gandi/operation.rb +45 -0
- data/lib/gandi/version.rb +1 -1
- data/lib/gandi.rb +57 -6
- data/spec/gandi/connection_spec.rb +39 -0
- data/spec/gandi/contact_spec.rb +173 -0
- data/spec/gandi/domain/forward_spec.rb +103 -0
- data/spec/gandi/domain/host_spec.rb +103 -0
- data/spec/gandi/domain/mailbox_spec.rb +117 -0
- data/spec/gandi/domain/tld_spec.rb +23 -0
- data/spec/gandi/domain_spec.rb +174 -0
- data/spec/gandi/errors_spec.rb +18 -0
- data/spec/gandi/gandi_spec.rb +57 -0
- data/spec/gandi/operation_spec.rb +73 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/contact_macros.rb +18 -0
- data/spec/support/domain_macros.rb +103 -0
- data/spec/support/operation_macros.rb +22 -0
- metadata +58 -51
- data/lib/gandi/base.rb +0 -121
- data/lib/gandi/domain_modules/contact.rb +0 -36
- data/lib/gandi/domain_modules/host.rb +0 -29
- data/lib/gandi/domain_modules/mail.rb +0 -80
- data/lib/gandi/domain_modules/name_servers.rb +0 -28
- data/lib/gandi/domain_modules/operations.rb +0 -30
- data/lib/gandi/domain_modules/redirection.rb +0 -25
- data/test/gandi/base_test.rb +0 -188
- data/test/gandi/domain_test.rb +0 -301
- data/test/gandi_test.rb +0 -9
- data/test/test_helper.rb +0 -9
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Contact do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
context "a blank instance" do
|
11
|
+
its(:handle) { should be_nil }
|
12
|
+
its(:id) { should be_nil }
|
13
|
+
its(:to_s) { should == '' }
|
14
|
+
it { should_not be_persisted }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "a new instance provided with contact infos" do
|
18
|
+
before { @contact_information_attributes = contact_information_attributes_hash('id' => 'new id', 'type' => 0) }
|
19
|
+
subject { Gandi::Contact.new(nil, @contact_information_attributes) }
|
20
|
+
|
21
|
+
its(:handle) { should be_nil }
|
22
|
+
its(:id) { should == 'new id' }
|
23
|
+
its(:to_s) { should == '' }
|
24
|
+
it { should_not be_persisted }
|
25
|
+
|
26
|
+
it "should map its attributes" do
|
27
|
+
[:orgname, :given, :family, :streetaddr, :city, :state, :zip, :country, :phone, :fax, :mobile,
|
28
|
+
:tva_number, :siren, :marque, :lang, :newsletter, :obfuscated, :whois_obfuscated, :resell, :shippingaddress,
|
29
|
+
:extra_parameters].each do |contact_attribute|
|
30
|
+
[subject.send(contact_attribute), subject[contact_attribute.to_s],subject.to_hash[contact_attribute.to_s]].each do |value|
|
31
|
+
value.should == @contact_information_attributes[contact_attribute.to_s]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can modify its writable attributes" do
|
37
|
+
subject.city = "City 1"
|
38
|
+
subject.city.should == "City 1"
|
39
|
+
subject['city'] = "City 2"
|
40
|
+
subject.city.should == "City 2"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "cannot modify its id" do
|
44
|
+
lambda { subject['id'] = 'other id' }.should raise_error(Gandi::DataError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should map its type to the corresponding string" do
|
48
|
+
subject.type.should == 'person'
|
49
|
+
subject.type = 'company'
|
50
|
+
subject['type'].should == 1
|
51
|
+
subject.type.should == 'company'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "cannot associate domains" do
|
55
|
+
subject.can_associate_domain({:domain => 'any.tld'}).should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
it "cannot get contact informations" do
|
59
|
+
lambda { subject.info }.should raise_error(Gandi::DataError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "cannot be updated" do
|
63
|
+
lambda { subject.update({}) }.should raise_error(Gandi::DataError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "an instance provided with its handle" do
|
68
|
+
before do
|
69
|
+
@handle = 'AA0-GANDI'
|
70
|
+
@attributes = contact_information_attributes_hash('id' => 'contact id', 'handle' => @handle)
|
71
|
+
@connection_mock.should_receive(:call).with('contact.info', @handle).and_return(@attributes)
|
72
|
+
end
|
73
|
+
subject { Gandi::Contact.new(@handle) }
|
74
|
+
|
75
|
+
its(:handle) { should == @handle }
|
76
|
+
its(:id) { should == 'contact id' }
|
77
|
+
its(:to_s) { should == @handle }
|
78
|
+
it { should be_persisted }
|
79
|
+
|
80
|
+
it "should map its attributes" do
|
81
|
+
[:orgname, :given, :family, :streetaddr, :city, :state, :zip, :country, :phone, :fax, :mobile,
|
82
|
+
:tva_number, :siren, :marque, :lang, :newsletter, :obfuscated, :whois_obfuscated, :resell, :shippingaddress,
|
83
|
+
:extra_parameters].each do |contact_attribute|
|
84
|
+
[subject.send(contact_attribute), subject[contact_attribute.to_s],subject.to_hash[contact_attribute.to_s]].each do |value|
|
85
|
+
value.should == @attributes[contact_attribute.to_s]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can test successful domain association" do
|
91
|
+
domain_hash = {:domain => 'mydomain.com'}
|
92
|
+
@connection_mock.should_receive(:call).with('contact.can_associate_domain', @handle, domain_hash).and_return(true)
|
93
|
+
subject.can_associate_domain(domain_hash).should be_true
|
94
|
+
subject.should respond_to(:can_associate_domain?)
|
95
|
+
end
|
96
|
+
|
97
|
+
pending "can test failing domain association"
|
98
|
+
|
99
|
+
it "can fetch its contact informations" do
|
100
|
+
@connection_mock.should_receive(:call).with('contact.info', @handle).and_return(@attributes)
|
101
|
+
subject.info['city'].should == @attributes['city']
|
102
|
+
end
|
103
|
+
|
104
|
+
it "cannot modify its id" do
|
105
|
+
lambda { subject['id'] = 'other id' }.should raise_error(Gandi::DataError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "cannot modify its handle" do
|
109
|
+
lambda { subject['handle'] = 'NH0-GANDI' }.should raise_error(Gandi::DataError)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "can be updated" do
|
113
|
+
@updated_attributes = contact_information_attributes_hash('city' => "Marseille")
|
114
|
+
@connection_mock.should_receive(:call).with('contact.update', @handle, @updated_attributes).and_return(@updated_attributes)
|
115
|
+
subject.update(@updated_attributes)
|
116
|
+
subject.city.should == @updated_attributes['city']
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ".create" do
|
121
|
+
it "should return a contact object" do
|
122
|
+
attributes = contact_information_attributes_hash('id' => 'new id')
|
123
|
+
@connection_mock.should_receive(:call).with('contact.create', attributes).and_return(attributes.merge('handle' => 'AA9-GANDI'))
|
124
|
+
Gandi::Contact.create(attributes).handle.should == 'AA9-GANDI'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe ".info" do
|
129
|
+
it "should return a contact hash" do
|
130
|
+
attributes = contact_information_attributes_hash
|
131
|
+
@connection_mock.should_receive(:call).with('contact.info').and_return(attributes)
|
132
|
+
Gandi::Contact.info.should == attributes
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe ".can_associate" do
|
137
|
+
it "should return a boolean when the domain can be associated" do
|
138
|
+
domain_hash = {:domain => 'mydomain.com'}
|
139
|
+
handle = 'AA0-GANDI'
|
140
|
+
@connection_mock.should_receive(:call).with('contact.can_associate', handle, domain_hash).and_return(true)
|
141
|
+
Gandi::Contact.can_associate(handle, domain_hash).should be_true
|
142
|
+
end
|
143
|
+
|
144
|
+
pending "should return an error hash when the domain cannot be associated"
|
145
|
+
end
|
146
|
+
|
147
|
+
describe ".list" do
|
148
|
+
let(:mocked_contacts_array) { [contact_information_attributes_hash('handle' => 'HA1-GANDI'), contact_information_attributes_hash('handle' => 'HA2-GANDI')] }
|
149
|
+
|
150
|
+
it "returns an array of contacts" do
|
151
|
+
@connection_mock.should_receive(:call).with('contact.list', {}).and_return(mocked_contacts_array)
|
152
|
+
contacts = Gandi::Contact.list
|
153
|
+
contacts.length.should == 2
|
154
|
+
contacts.last.handle.should == 'HA2-GANDI'
|
155
|
+
end
|
156
|
+
|
157
|
+
it "can return an array of contact hashes" do
|
158
|
+
@connection_mock.should_receive(:call).with('contact.list', {}).and_return(mocked_contacts_array)
|
159
|
+
contacts = Gandi::Contact.list({}, false)
|
160
|
+
contacts.length.should == 2
|
161
|
+
contacts.last['handle'].should == 'HA2-GANDI'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe ".update" do
|
166
|
+
it "returns a contact object" do
|
167
|
+
handle = 'JD0-GANDI'
|
168
|
+
attributes = contact_information_attributes_hash
|
169
|
+
@connection_mock.should_receive(:call).with('contact.update', handle, attributes).and_return(attributes.merge('handle' => handle))
|
170
|
+
Gandi::Contact.update(handle, attributes).handle.should == handle
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Domain::Forward do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.list' do
|
11
|
+
let(:fqdn) { 'domain1.tld' }
|
12
|
+
let(:domain) { mock_domain(fqdn) }
|
13
|
+
let(:domain_forwards_list) { [domain_forward_attributes('john.doe'), domain_forward_attributes('jane.doe'), domain_forward_attributes('tom.doe')] }
|
14
|
+
|
15
|
+
before do
|
16
|
+
@connection_mock.should_receive(:call).with('domain.forward.list', fqdn, {}).and_return(domain_forwards_list)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an array of Forward objects" do
|
20
|
+
list = Gandi::Domain::Forward.list(domain)
|
21
|
+
list.length.should == domain_forwards_list.length
|
22
|
+
list.first.should be_a(Gandi::Domain::Forward)
|
23
|
+
list.first.source.should == domain_forwards_list.first['source']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.count' do
|
28
|
+
let(:fqdn) { 'domain1.tld' }
|
29
|
+
let(:domain) { mock_domain(fqdn) }
|
30
|
+
|
31
|
+
before do
|
32
|
+
@connection_mock.should_receive(:call).with('domain.forward.count', fqdn, {}).and_return(42)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns an integer" do
|
36
|
+
Gandi::Domain::Forward.count(domain).should == 42
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '.create' do
|
41
|
+
let(:fqdn) { 'domain1.tld' }
|
42
|
+
let(:domain) { mock_domain(fqdn) }
|
43
|
+
let(:source) { 'john.doe' }
|
44
|
+
let(:forward_create_params) { {'password' => 'securedp4ssword'} }
|
45
|
+
|
46
|
+
before do
|
47
|
+
@connection_mock.should_receive(:call).with('domain.forward.create', fqdn, source, forward_create_params).and_return(forward_create_params)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a Forward object" do
|
51
|
+
forward = Gandi::Domain::Forward.create(domain, source, forward_create_params)
|
52
|
+
forward.should be_a(Gandi::Domain::Forward)
|
53
|
+
forward.source.should == source
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can be instanciated with its attributes" do
|
58
|
+
fqdn = 'domain1.tld'
|
59
|
+
domain = mock_domain(fqdn)
|
60
|
+
source = 'john.doe'
|
61
|
+
forward_attributes = domain_forward_attributes(source)
|
62
|
+
|
63
|
+
forward = Gandi::Domain::Forward.new(domain, source, forward_attributes)
|
64
|
+
forward.to_hash.should == forward_attributes
|
65
|
+
forward.source.should == source
|
66
|
+
forward.domain.should == domain
|
67
|
+
end
|
68
|
+
|
69
|
+
context "an instance" do
|
70
|
+
let(:fqdn) { 'domain1.tld' }
|
71
|
+
let(:domain) { mock_domain(fqdn) }
|
72
|
+
let(:source) { 'john.doe' }
|
73
|
+
let(:forward_attributes) { domain_forward_attributes(source) }
|
74
|
+
|
75
|
+
before do
|
76
|
+
@connection_mock.should_receive(:call).with('domain.forward.list', fqdn, {'source' => source}).and_return([forward_attributes])
|
77
|
+
end
|
78
|
+
subject { Gandi::Domain::Forward.new(domain, source) }
|
79
|
+
|
80
|
+
its(:source) { should == source }
|
81
|
+
its(:domain) { should == domain }
|
82
|
+
|
83
|
+
it "can read its attributes" do
|
84
|
+
subject.to_hash.should == forward_attributes
|
85
|
+
subject['destinations'].should == forward_attributes['destinations']
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can be deleted" do
|
89
|
+
@connection_mock.should_receive(:call).with('domain.forward.delete', fqdn, source).and_return(true)
|
90
|
+
|
91
|
+
subject.delete.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "can be updated" do
|
95
|
+
new_attrs = forward_attributes.merge('destinations' => ['jean.dupond@domain1.tld'])
|
96
|
+
@connection_mock.should_receive(:call).with('domain.forward.update', fqdn, source, new_attrs).and_return(new_attrs)
|
97
|
+
|
98
|
+
same_subject = subject.update(new_attrs)
|
99
|
+
same_subject.should == subject
|
100
|
+
subject.destinations.should == new_attrs['destinations']
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Domain::Host do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.list' do
|
11
|
+
let(:fqdn) { 'domain1.tld' }
|
12
|
+
let(:domain_host_list) { [{"ips"=>["1.2.3.4"], "name"=>"dns1.domain1.tld"}, {"ips"=>["6.7.8.9"], "name"=>"dns2.domain1.tld"}] }
|
13
|
+
|
14
|
+
before do
|
15
|
+
@connection_mock.should_receive(:call).with('domain.host.list', fqdn, {}).and_return(domain_host_list)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an array of Host objects" do
|
19
|
+
list = Gandi::Domain::Host.list(fqdn)
|
20
|
+
list.length.should == domain_host_list.length
|
21
|
+
list.first.should be_a(Gandi::Domain::Host)
|
22
|
+
list.first.hostname.should == domain_host_list.first['name']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.count' do
|
27
|
+
let(:fqdn) { 'domain1.tld' }
|
28
|
+
|
29
|
+
before do
|
30
|
+
@connection_mock.should_receive(:call).with('domain.host.count', fqdn, {}).and_return(42)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns an integer" do
|
34
|
+
Gandi::Domain::Host.count(fqdn).should == 42
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.create' do
|
39
|
+
let(:host_ips) { ["1.2.3.4"] }
|
40
|
+
let(:hostname) { 'dns1.domain1.tld' }
|
41
|
+
|
42
|
+
before do
|
43
|
+
@connection_mock.should_receive(:call).with('domain.host.create', hostname, host_ips).and_return(operation_information_attributes_hash('id' => 42))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns an operation object" do
|
47
|
+
host_operation = Gandi::Domain::Host.create(hostname, host_ips)
|
48
|
+
host_operation.should be_a(Gandi::Operation)
|
49
|
+
host_operation.id.should == 42
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can be instanciated with its attributes" do
|
54
|
+
hostname = 'domain1.tld'
|
55
|
+
host_attributes = domain_host_attributes_hash('name' => hostname)
|
56
|
+
|
57
|
+
host = Gandi::Domain::Host.new(hostname, host_attributes)
|
58
|
+
host.to_hash.should == host_attributes
|
59
|
+
host.hostname.should == hostname
|
60
|
+
end
|
61
|
+
|
62
|
+
context "an instance" do
|
63
|
+
let(:hostname) { 'domain1.tld' }
|
64
|
+
let(:host_attributes) { domain_host_attributes_hash('name' => hostname) }
|
65
|
+
|
66
|
+
before do
|
67
|
+
@connection_mock.should_receive(:call).with('domain.host.info', hostname).and_return(host_attributes)
|
68
|
+
end
|
69
|
+
subject { Gandi::Domain::Host.new(hostname) }
|
70
|
+
|
71
|
+
its(:hostname) { should == hostname }
|
72
|
+
its(:ips) { should == host_attributes['ips'] }
|
73
|
+
|
74
|
+
pending '#domain'
|
75
|
+
|
76
|
+
it "can fetch its informations" do
|
77
|
+
@connection_mock.should_receive(:call).with('domain.host.info', hostname).and_return(host_attributes)
|
78
|
+
subject.info['ips'].should == host_attributes['ips']
|
79
|
+
end
|
80
|
+
|
81
|
+
it "can read its attributes" do
|
82
|
+
subject.to_hash.should == host_attributes
|
83
|
+
subject['ips'].should == host_attributes['ips']
|
84
|
+
end
|
85
|
+
|
86
|
+
it "can be deleted" do
|
87
|
+
@connection_mock.should_receive(:call).with('domain.host.delete', hostname).and_return(operation_information_attributes_hash('id' => 42))
|
88
|
+
|
89
|
+
host_deletion = subject.delete
|
90
|
+
host_deletion.should be_a(Gandi::Operation)
|
91
|
+
host_deletion.id.should == 42
|
92
|
+
end
|
93
|
+
|
94
|
+
it "can be updated" do
|
95
|
+
new_ips = ['5.6.7.8']
|
96
|
+
@connection_mock.should_receive(:call).with('domain.host.update', hostname, new_ips).and_return(operation_information_attributes_hash('id' => 42))
|
97
|
+
|
98
|
+
host_update = subject.update(new_ips)
|
99
|
+
host_update.should be_a(Gandi::Operation)
|
100
|
+
host_update.id.should == 42
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Domain::Mailbox do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.list' do
|
11
|
+
let(:fqdn) { 'domain1.tld' }
|
12
|
+
let(:domain) { mock_domain(fqdn) }
|
13
|
+
let(:domain_mailboxes_list) { [domain_mailbox_attributes('login' => 'john.doe'), domain_mailbox_attributes('login' => 'jane.doe'), domain_mailbox_attributes('login' => 'tom.doe')] }
|
14
|
+
|
15
|
+
before do
|
16
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.list', fqdn, {}).and_return(domain_mailboxes_list)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an array of Mailbox objects by default" do
|
20
|
+
domain_mailboxes_list.each do |mailbox_hash|
|
21
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.info', fqdn, mailbox_hash['login']).and_return(mailbox_hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
list = Gandi::Domain::Mailbox.list(domain)
|
25
|
+
list.length.should == domain_mailboxes_list.length
|
26
|
+
list.first.should be_a(Gandi::Domain::Mailbox)
|
27
|
+
list.first.login.should == domain_mailboxes_list.first['login']
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns an array of hashes if map_mailboxes is false" do
|
31
|
+
list = Gandi::Domain::Mailbox.list(domain, {}, false)
|
32
|
+
list.should == domain_mailboxes_list
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.count' do
|
37
|
+
let(:fqdn) { 'domain1.tld' }
|
38
|
+
let(:domain) { mock_domain(fqdn) }
|
39
|
+
|
40
|
+
before do
|
41
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.count', fqdn, {}).and_return(42)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns an integer" do
|
45
|
+
Gandi::Domain::Mailbox.count(domain).should == 42
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.create' do
|
50
|
+
let(:fqdn) { 'domain1.tld' }
|
51
|
+
let(:domain) { mock_domain(fqdn) }
|
52
|
+
let(:login) { 'john.doe' }
|
53
|
+
let(:mailbox_create_params) { {'password' => 'securedp4ssword'} }
|
54
|
+
|
55
|
+
before do
|
56
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.create', fqdn, login, mailbox_create_params).and_return(mailbox_create_params)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns a Mailbox object" do
|
60
|
+
mailbox = Gandi::Domain::Mailbox.create(domain, login, mailbox_create_params)
|
61
|
+
mailbox.should be_a(Gandi::Domain::Mailbox)
|
62
|
+
mailbox.login.should == login
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "can be instanciated with its attributes" do
|
67
|
+
fqdn = 'domain1.tld'
|
68
|
+
domain = mock_domain(fqdn)
|
69
|
+
login = 'john.doe'
|
70
|
+
mailbox_attributes = domain_mailbox_attributes('login' => login)
|
71
|
+
|
72
|
+
mailbox = Gandi::Domain::Mailbox.new(domain, login, mailbox_attributes)
|
73
|
+
mailbox.to_hash.should == mailbox_attributes
|
74
|
+
mailbox.login.should == login
|
75
|
+
mailbox.domain.should == domain
|
76
|
+
end
|
77
|
+
|
78
|
+
context "an instance" do
|
79
|
+
let(:fqdn) { 'domain1.tld' }
|
80
|
+
let(:domain) { mock_domain(fqdn) }
|
81
|
+
let(:login) { 'john.doe' }
|
82
|
+
let(:mailbox_attributes) { domain_mailbox_attributes('name' => login) }
|
83
|
+
|
84
|
+
before do
|
85
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.info', fqdn, login).and_return(mailbox_attributes)
|
86
|
+
end
|
87
|
+
subject { Gandi::Domain::Mailbox.new(domain, login) }
|
88
|
+
|
89
|
+
its(:login) { should == login }
|
90
|
+
its(:domain) { should == domain }
|
91
|
+
|
92
|
+
it "can fetch its informations" do
|
93
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.info', fqdn, login).and_return(mailbox_attributes)
|
94
|
+
subject.info['ips'].should == mailbox_attributes['ips']
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can read its attributes" do
|
98
|
+
subject.to_hash.should == mailbox_attributes
|
99
|
+
subject['login'].should == mailbox_attributes['login']
|
100
|
+
end
|
101
|
+
|
102
|
+
it "can be deleted" do
|
103
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.delete', fqdn, login).and_return(true)
|
104
|
+
|
105
|
+
subject.delete.should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
it "can be updated" do
|
109
|
+
new_attrs = mailbox_attributes.merge('password' => 'newpassword')
|
110
|
+
@connection_mock.should_receive(:call).with('domain.mailbox.update', fqdn, login, new_attrs).and_return(operation_information_attributes_hash('id' => 42))
|
111
|
+
|
112
|
+
mailbox_update = subject.update(new_attrs)
|
113
|
+
mailbox_update.should be_a(Gandi::Operation)
|
114
|
+
mailbox_update.id.should == 42
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Domain::Tld do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.list' do
|
11
|
+
it "returns a hash" do
|
12
|
+
@connection_mock.should_receive(:call).with('domain.tld.list').and_return(domain_tld_list)
|
13
|
+
Gandi::Domain::Tld.list.should == domain_tld_list
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.region' do
|
18
|
+
it "returns an array" do
|
19
|
+
@connection_mock.should_receive(:call).with('domain.tld.region').and_return(domain_tld_regions)
|
20
|
+
Gandi::Domain::Tld.region.should == domain_tld_regions
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gandi'
|
3
|
+
|
4
|
+
describe Gandi::Domain do
|
5
|
+
before do
|
6
|
+
@connection_mock = double()
|
7
|
+
::Gandi.connection = @connection_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.list' do
|
11
|
+
let(:domain_list) { [domain_information_attributes_hash('fqdn' => 'domain1.com'), domain_information_attributes_hash('fqdn' => 'domain2.net')] }
|
12
|
+
|
13
|
+
before do
|
14
|
+
@connection_mock.should_receive(:call).with('domain.list', {}).and_return(domain_list)
|
15
|
+
@connection_mock.should_receive(:call).with('domain.info', 'domain1.com').and_return(domain_information_attributes_hash('fqdn' => 'domain1.com'))
|
16
|
+
@connection_mock.should_receive(:call).with('domain.info', 'domain2.net').and_return(domain_information_attributes_hash('fqdn' => 'domain2.net'))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an array of domain objects" do
|
20
|
+
list = Gandi::Domain.list
|
21
|
+
list.length.should == domain_list.length
|
22
|
+
list.first.should be_a(Gandi::Domain)
|
23
|
+
list.first.fqdn.should == domain_list.first['fqdn']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.count' do
|
28
|
+
before do
|
29
|
+
@connection_mock.should_receive(:call).with('domain.count', {}).and_return(42)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns an integer" do
|
33
|
+
Gandi::Domain.count.should == 42
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.available' do
|
38
|
+
let(:fqdns) { ['domain1.com', 'domain2.net'] }
|
39
|
+
|
40
|
+
it "returns a hash of fqdns" do
|
41
|
+
fqdns_available_call_result = {"domain1.com"=>"unavailable", "domain2.net"=>"available"}
|
42
|
+
@connection_mock.should_receive(:call).with('domain.available', fqdns).and_return(fqdns_available_call_result)
|
43
|
+
|
44
|
+
Gandi::Domain.available(fqdns).should == fqdns_available_call_result
|
45
|
+
end
|
46
|
+
|
47
|
+
pending "should wait then recall the method when getting pending results"
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.create' do
|
51
|
+
let(:handle) { 'FLN123-GANDI' }
|
52
|
+
let(:domain_creation_params) { {'owner' => handle, 'admin' => handle, 'tech' => handle, 'bill' => handle, 'nameservers' => ['gandi.net'], 'duration' => 1} }
|
53
|
+
let(:fqdn) { 'domain1.com' }
|
54
|
+
|
55
|
+
before do
|
56
|
+
@connection_mock.should_receive(:call).with('domain.create', fqdn, domain_creation_params).and_return(domain_creation_operation_hash('id' => 42))
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns an operation object" do
|
60
|
+
domain_operation = Gandi::Domain.create(fqdn, domain_creation_params)
|
61
|
+
domain_operation.should be_a(Gandi::Operation)
|
62
|
+
domain_operation.id.should == 42
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '.transferin' do
|
67
|
+
let(:handle) { 'FLN123-GANDI' }
|
68
|
+
let(:transfer_params) { {'owner' => handle, 'admin' => handle, 'bill' => handle, 'tech' => handle} }
|
69
|
+
let(:fqdn) { 'domain1.com' }
|
70
|
+
|
71
|
+
before do
|
72
|
+
@connection_mock.should_receive(:call).with('domain.transferin.proceed', fqdn, transfer_params).and_return(operation_information_attributes_hash('id' => 42))
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns an operation object" do
|
76
|
+
domain_operation = Gandi::Domain.transferin(fqdn, transfer_params)
|
77
|
+
domain_operation.should be_a(Gandi::Operation)
|
78
|
+
domain_operation.id.should == 42
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "an instance" do
|
83
|
+
let(:fqdn) { 'domain1.tld' }
|
84
|
+
let(:domain_attributes) { domain_information_attributes_hash('fqdn' => fqdn) }
|
85
|
+
|
86
|
+
before do
|
87
|
+
@connection_mock.should_receive(:call).with('domain.info', fqdn).and_return(domain_attributes)
|
88
|
+
end
|
89
|
+
subject { Gandi::Domain.new(fqdn) }
|
90
|
+
|
91
|
+
its(:fqdn) { should == fqdn }
|
92
|
+
|
93
|
+
it "can fetch its informations" do
|
94
|
+
@connection_mock.should_receive(:call).with('domain.info', fqdn).and_return(domain_attributes)
|
95
|
+
subject.info['fqdn'].should == domain_attributes['fqdn']
|
96
|
+
end
|
97
|
+
|
98
|
+
it "can read its attributes" do
|
99
|
+
subject.to_hash.should == domain_attributes
|
100
|
+
subject['tld'].should == domain_attributes['tld']
|
101
|
+
end
|
102
|
+
|
103
|
+
it "can be renewed" do
|
104
|
+
renewal_spec = domain_renew_spec
|
105
|
+
@connection_mock.should_receive(:call).with('domain.renew', fqdn, renewal_spec).and_return(domain_renewal_operation_hash('id' => 42))
|
106
|
+
|
107
|
+
domain_renewal_operation = subject.renew(renewal_spec)
|
108
|
+
domain_renewal_operation.should be_a(Gandi::Operation)
|
109
|
+
domain_renewal_operation.id.should == 42
|
110
|
+
end
|
111
|
+
|
112
|
+
pending "has attributes writers and readers"
|
113
|
+
|
114
|
+
it "has contacts" do
|
115
|
+
@connection_mock.should_receive(:call).exactly(5).times.with('contact.info', 'FLN123-GANDI').and_return(contact_information_attributes_hash('handle' => 'FLN123-GANDI'))
|
116
|
+
|
117
|
+
contacts = subject.contacts
|
118
|
+
contacts['owner'].should be_a(Gandi::Contact)
|
119
|
+
contacts['owner'].handle.should == 'FLN123-GANDI'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "can set its contacts" do
|
123
|
+
contacts_update_hash = {
|
124
|
+
"admin"=>"FLN123-GANDI",
|
125
|
+
"bill"=>"FLN123-GANDI",
|
126
|
+
"tech"=>"FLN123-GANDI"
|
127
|
+
}
|
128
|
+
@connection_mock.should_receive(:call).with('domain.contacts.set', fqdn, contacts_update_hash).and_return(operation_information_attributes_hash('id' => 42))
|
129
|
+
|
130
|
+
contacts_change = subject.contacts = contacts_update_hash
|
131
|
+
#contacts_change.should be_a(Gandi::Operation)
|
132
|
+
#contacts_change.id.should == 42
|
133
|
+
contacts_change.should == contacts_update_hash
|
134
|
+
end
|
135
|
+
|
136
|
+
pending "can set its contacts using a hash of contacts objects"
|
137
|
+
|
138
|
+
it 'can be locked' do
|
139
|
+
@connection_mock.should_receive(:call).with('domain.status.lock', fqdn).and_return(operation_information_attributes_hash('id' => 42))
|
140
|
+
|
141
|
+
domain_lock_operation = subject.lock
|
142
|
+
domain_lock_operation.should be_a(Gandi::Operation)
|
143
|
+
domain_lock_operation.id.should == 42
|
144
|
+
end
|
145
|
+
|
146
|
+
pending 'cannot be locked if already locked'
|
147
|
+
|
148
|
+
it 'can be unlocked' do
|
149
|
+
@connection_mock.should_receive(:call).with('domain.status.unlock', fqdn).and_return(operation_information_attributes_hash('id' => 42))
|
150
|
+
|
151
|
+
domain_lock_operation = subject.unlock
|
152
|
+
domain_lock_operation.should be_a(Gandi::Operation)
|
153
|
+
domain_lock_operation.id.should == 42
|
154
|
+
end
|
155
|
+
|
156
|
+
pending 'cannot be unlocked if already unlocked'
|
157
|
+
|
158
|
+
pending '#locked?'
|
159
|
+
|
160
|
+
it "has nameservers" do
|
161
|
+
subject.nameservers.should == domain_attributes['nameservers']
|
162
|
+
end
|
163
|
+
|
164
|
+
it "can set its nameservers" do
|
165
|
+
new_nameservers = ['a.dns.gandi-ote.net', 'b.dns.gandi-ote.net', 'c.dns.gandi-ote.net']
|
166
|
+
@connection_mock.should_receive(:call).with('domain.nameservers.set', fqdn, new_nameservers).and_return(operation_information_attributes_hash('id' => 42))
|
167
|
+
|
168
|
+
namservers_change = subject.nameservers=(new_nameservers)
|
169
|
+
#namservers_change.should be_a(Gandi::Operation)
|
170
|
+
#namservers_change.id.should == 42
|
171
|
+
namservers_change.should == new_nameservers
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|