Skip to content

Commit 3932525

Browse files
committed
Merge pull request #642 from estolfo/wire-version
Correct wire version range checks
2 parents 5ce7f97 + 0444bda commit 3932525

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/mongo/server/description/features.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def initialize(server_wire_versions)
7575
private
7676

7777
def check_driver_support!
78-
if DRIVER_WIRE_VERSIONS.max < server_wire_versions.max
78+
if DRIVER_WIRE_VERSIONS.max < server_wire_versions.min ||
79+
DRIVER_WIRE_VERSIONS.min > server_wire_versions.max
7980
raise Error::UnsupportedFeatures.new(server_wire_versions)
8081
end
8182
end

spec/mongo/server/description/features_spec.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,36 @@
1515
end
1616
end
1717

18-
context 'when the server wire version range is higher' do
18+
context 'when the server wire version range min is higher' do
1919

2020
it 'raises an exception' do
2121
expect {
22-
described_class.new(0..4)
22+
described_class.new(described_class::DRIVER_WIRE_VERSIONS.max+1..described_class::DRIVER_WIRE_VERSIONS.max+2)
2323
}.to raise_error(Mongo::Error::UnsupportedFeatures)
2424
end
2525
end
2626

27-
context 'when the server wire version range is lower' do
27+
context 'when the server wire version range max is higher' do
28+
29+
let(:features) do
30+
described_class.new(0..4)
31+
end
32+
33+
it 'sets the server wire version range' do
34+
expect(features.server_wire_versions).to eq(0..4)
35+
end
36+
end
37+
38+
context 'when the server wire version range max is lower' do
39+
40+
it 'raises an exception' do
41+
expect {
42+
described_class.new(described_class::DRIVER_WIRE_VERSIONS.min-2..described_class::DRIVER_WIRE_VERSIONS.min-1)
43+
}.to raise_error(Mongo::Error::UnsupportedFeatures)
44+
end
45+
end
46+
47+
context 'when the server wire version range max is lower' do
2848

2949
let(:features) do
3050
described_class.new(0..2)

0 commit comments

Comments
 (0)