Skip to content

Commit 618275d

Browse files
updating tests
1 parent 0b12109 commit 618275d

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

lib/mongo/uri/srv_protocol.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def validate_srv_hostname(hostname)
184184
if parts.any?(&:empty?)
185185
raise_invalid_error!("Hostname cannot have consecutive dots: #{hostname}")
186186
end
187+
if parts.length == 0
188+
raise_invalid_error!("Hostname cannot be empty: #{hostname}")
189+
end
187190
end
188191

189192
# Obtains the TXT options of a host.

spec/mongo/uri/srv_protocol_spec.rb

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@
5656
end
5757
end
5858

59-
context 'when the host in URI does not have {hostname}, {domainname} and {tld}' do
60-
61-
let(:string) { "#{scheme}#{hosts}" }
62-
let(:hosts) { '10gen.cc/' }
63-
64-
it 'raises an error' do
65-
expect { uri }.to raise_error(Mongo::Error::InvalidURI)
66-
end
67-
end
68-
6959
context 'when the {tld} is empty' do
7060

7161
let(:string) { "#{scheme}#{hosts}" }
@@ -220,24 +210,6 @@
220210
expect { uri }.to raise_error(Mongo::Error::InvalidURI)
221211
end
222212
end
223-
224-
context 'mongodb+srv://example.com?w=1' do
225-
226-
let(:string) { "#{scheme}example.com?w=1" }
227-
228-
it 'raises an error' do
229-
expect { uri }.to raise_error(Mongo::Error::InvalidURI)
230-
end
231-
end
232-
233-
context 'mongodb+srv://example.com/?w' do
234-
235-
let(:string) { "#{scheme}example.com/?w" }
236-
237-
it 'raises an error' do
238-
expect { uri }.to raise_error(Mongo::Error::InvalidURI)
239-
end
240-
end
241213
end
242214

243215
describe 'valid uris' do
@@ -1302,8 +1274,8 @@
13021274
'a'
13031275
end
13041276

1305-
it 'raises an error' do
1306-
expect { validate }.to raise_error(Mongo::Error::InvalidURI)
1277+
it 'does not raise an error' do
1278+
expect { validate }.to_not raise_error
13071279
end
13081280
end
13091281

@@ -1313,8 +1285,8 @@
13131285
'a.b'
13141286
end
13151287

1316-
it 'raises an error' do
1317-
expect { validate }.to raise_error(Mongo::Error::InvalidURI)
1288+
it 'validates the hostname' do
1289+
expect { validate }.not_to raise_error
13181290
end
13191291
end
13201292

0 commit comments

Comments
 (0)