From 34d380a1fa10073ebbdd922548cd8bec2648661b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Nicola?= Date: Thu, 19 Oct 2023 10:21:29 +0200 Subject: [PATCH] Change: add a dummy item in the redis storage for backward compatibility (#1514) * Change: add a dummy item in the redis storage for backward compatibility Since openvas uses positional items and expects the plugin oid in the second position, add a dummy item under filename key * fix test --- rust/redis-storage/src/connector.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rust/redis-storage/src/connector.rs b/rust/redis-storage/src/connector.rs index a4d097ace..925967395 100644 --- a/rust/redis-storage/src/connector.rs +++ b/rust/redis-storage/src/connector.rs @@ -291,9 +291,14 @@ pub trait RedisAddNvt: RedisWrapper { } // Stores the OID under the filename key. This key is currently used - // for the dependency autoload, where the filename is used to fetch the OID + // for the dependency autoload, where the filename is used to fetch the OID. + // + // TODO: since openvas get the oid by position and it is stored in the second position, + // for backward compatibility a dummy item (it is the plugin's upload timestamp) + // under the filename key is added. + // Once openvas is no longer used, the dummy item can be removed. let key_name = format!("filename:{filename}"); - self.lpush(&key_name, &oid)?; + self.rpush(&key_name, &["1", &oid])?; Ok(()) } } @@ -578,9 +583,12 @@ mod tests { ); } "filename:test.nasl" => { - let values = values.first().unwrap().clone(); - let oid = String::from_utf8(values); + assert_eq!(values.len(), 2); + let mut vals = values.clone(); + let oid = String::from_utf8(vals.pop().unwrap()); assert_eq!(Ok("0.0.0.0.0.0.0.0.0.1".to_owned()), oid); + let dummy = vals.pop().unwrap(); + assert_eq!(Ok("1".to_owned()), String::from_utf8(dummy)); } _ => panic!("{key} should not occur"), }