Skip to content

Commit 31f8075

Browse files
committed
Fix: on range=1 without - it means from and not to this value
1 parent 1aa659c commit 31f8075

4 files changed

+25
-416
lines changed

rust/crates/greenbone-scanner-framework/src/get_scans_id_results.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ where
8383
Some(x) => x.parse().ok(),
8484
None => None,
8585
};
86-
if from.is_some() && to.is_none() {
87-
(None, from)
88-
} else {
89-
(from, to)
90-
}
86+
(from, to)
9187
})
9288
.next()
9389
.unwrap_or_default(),
@@ -174,8 +170,13 @@ mod tests {
174170
io::Error::other("oh no"),
175171
)))]));
176172
}
173+
let to = if from.is_some() {
174+
// for the test case ?range=99
175+
to.unwrap_or(101)
176+
} else {
177+
to.unwrap_or_default()
178+
};
177179
let from = from.unwrap_or_default();
178-
let to = to.unwrap_or_default();
179180
let result: Vec<Result<models::Result, _>> = (from..to)
180181
.map(|id| {
181182
Ok(models::Result {
@@ -248,23 +249,23 @@ mod tests {
248249
}
249250

250251
#[tokio::test]
251-
async fn scan_results_to() {
252+
async fn scan_results_from() {
252253
let entry_point = test_utilities::entry_point(
253254
Authentication::MTLS,
254255
create_single_handler!(GetScansIdResultsHandler::from(Test {})),
255256
Some(ClientHash::from("ok")),
256257
);
257258

258259
let req = Request::builder()
259-
.uri("/scans/id/results?range=100")
260+
.uri("/scans/id/results?range=99")
260261
.method(Method::GET)
261262
.body(Empty::<Bytes>::new())
262263
.unwrap();
263264
let resp = entry_point.call(req).await.unwrap();
264265
assert_eq!(resp.status(), StatusCode::OK);
265266
let bytes = resp.into_body().collect().await.unwrap().to_bytes();
266267
let resp: Vec<models::Result> = serde_json::from_slice(bytes.as_ref()).unwrap();
267-
assert_eq!(resp.len(), 100);
268+
assert_eq!(resp.len(), 2);
268269
insta::assert_ron_snapshot!(resp);
269270
}
270271

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: src/get_scans_id_results.rs
2+
source: crates/greenbone-scanner-framework/src/get_scans_id_results.rs
33
expression: resp
44
---
55
[]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/greenbone-scanner-framework/src/get_scans_id_results.rs
3+
expression: resp
4+
---
5+
[
6+
Result(
7+
id: 99,
8+
type: log,
9+
),
10+
Result(
11+
id: 100,
12+
type: log,
13+
),
14+
]

0 commit comments

Comments
 (0)