-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix case of tagged empty variable in Get request and add test
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#[macro_use] extern crate pretty_assertions; | ||
extern crate der_parser; | ||
extern crate snmp_parser; | ||
extern crate nom; | ||
|
||
use nom::IResult; | ||
use snmp_parser::*; | ||
use der_parser::oid::Oid; | ||
|
||
static SNMPV2_GET: &'static [u8] = include_bytes!("../assets/snmpv2c-get-response.bin"); | ||
|
||
#[test] | ||
fn test_snmp_v2_get() { | ||
let empty = &b""[..]; | ||
let bytes = SNMPV2_GET; | ||
let expected = Ok((empty,SnmpMessage{ | ||
version: 1, | ||
community: String::from("public"), | ||
pdu:SnmpPdu::Generic( | ||
SnmpGenericPdu{ | ||
pdu_type: PduType::Response, | ||
req_id:97083662, | ||
err:ErrorStatus(0), | ||
err_index:0, | ||
var:vec![ | ||
SnmpVariable{ | ||
oid: Oid::from(&[1, 3, 6, 1, 2, 1, 25, 1, 1, 0]), | ||
val: ObjectSyntax::Ticks(970069) | ||
}, | ||
SnmpVariable{ | ||
oid: Oid::from(&[1, 3, 6, 1, 2, 1, 25, 1, 5, 0]), | ||
val: ObjectSyntax::Gauge(3) | ||
}, | ||
SnmpVariable{ | ||
oid: Oid::from(&[1, 3, 6, 1, 2, 1, 25, 1, 5, 1]), | ||
val: ObjectSyntax::Empty | ||
} | ||
], | ||
}), | ||
})); | ||
let res = parse_snmp_v1(&bytes); | ||
match &res { | ||
&Ok((_,ref r)) => { | ||
// debug!("r: {:?}",r); | ||
eprintln!("SNMP: v={}, c={:?}, pdu_type={:?}",r.version,r.community,r.pdu_type()); | ||
// debug!("PDU: type={}, {:?}", pdu_type, pdu_res); | ||
for ref v in r.vars_iter() { | ||
eprintln!("v: {:?}",v); | ||
} | ||
}, | ||
_ => (), | ||
}; | ||
assert_eq!(res, expected); | ||
} |