Skip to content

Commit

Permalink
Make sure there aren't version checks that panic with minimum support…
Browse files Browse the repository at this point in the history
…ed version
  • Loading branch information
slinkydeveloper committed Dec 9, 2024
1 parent 422b462 commit b73d7c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/service_protocol/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub struct Encoder {}

impl Encoder {
pub fn new(service_protocol_version: Version) -> Self {
assert_eq!(
service_protocol_version,
Version::maximum_supported_version(),
"Encoder only supports service protocol version {:?}",
assert!(
service_protocol_version >= Version::minimum_supported_version(),
"Encoder only supports service protocol version {:?} <= x <= {:?}",
Version::minimum_supported_version(),
Version::maximum_supported_version()
);
Self {}
Expand Down Expand Up @@ -105,10 +105,10 @@ pub struct Decoder {

impl Decoder {
pub fn new(service_protocol_version: Version) -> Self {
assert_eq!(
service_protocol_version,
Version::maximum_supported_version(),
"Decoder only supports service protocol version {:?}",
assert!(
service_protocol_version >= Version::minimum_supported_version(),
"Decoder only supports service protocol version {:?} <= x <= {:?}",
Version::minimum_supported_version(),
Version::maximum_supported_version()
);
Self {
Expand Down
5 changes: 5 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ fn take_output_on_newly_initialized_vm() {
eq(TakeOutputResult::Buffer(Bytes::default()))
);
}

#[test]
fn instantiate_core_vm_minimum_supported_version() {
CoreVM::mock_init(Version::minimum_supported_version());
}
2 changes: 1 addition & 1 deletion src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl super::VM for CoreVM {
.ok_or(errors::MISSING_CONTENT_TYPE)?
.parse::<Version>()?;

if version != Version::maximum_supported_version() {
if version < Version::minimum_supported_version() {
return Err(Error::new(
errors::codes::UNSUPPORTED_MEDIA_TYPE,
format!("Unsupported protocol version {:?}", version),
Expand Down

0 comments on commit b73d7c0

Please sign in to comment.