Skip to content

Commit 74379d3

Browse files
committed
agent: add test for agent without remote credentials
1 parent 9cef493 commit 74379d3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

stun-proto/src/agent.rs

+40
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl StunAgent {
213213
}
214214
}
215215
} else {
216+
// XXX: may need to return this as 'Unvalididated'.
216217
debug!("no remote credentials, ignoring");
217218
self.outstanding_requests
218219
.insert(msg.transaction_id(), request);
@@ -935,6 +936,45 @@ pub(crate) mod tests {
935936
assert!(!agent.is_validated_peer(remote_addr));
936937
}
937938

939+
#[test]
940+
fn agent_response_without_credentials() {
941+
init();
942+
let local_addr = "10.0.0.1:12345".parse().unwrap();
943+
let remote_addr = "10.0.0.2:3478".parse().unwrap();
944+
945+
let mut agent = StunAgent::builder(TransportType::Udp, local_addr).build();
946+
let local_credentials = ShortTermCredentials::new(String::from("local_password"));
947+
agent.set_local_credentials(local_credentials.clone().into());
948+
949+
let mut msg = Message::builder_request(BINDING);
950+
let transaction_id = msg.transaction_id();
951+
msg.add_message_integrity(&local_credentials.into(), IntegrityAlgorithm::Sha1)
952+
.unwrap();
953+
let transmit = agent.send(msg, remote_addr).unwrap();
954+
955+
let request = Message::from_bytes(&transmit.data).unwrap();
956+
957+
let mut response = Message::builder_success(&request);
958+
response
959+
.add_attribute(&XorMappedAddress::new(
960+
transmit.from,
961+
request.transaction_id(),
962+
))
963+
.unwrap();
964+
965+
let data = response.build();
966+
let to = transmit.to;
967+
let response = Message::from_bytes(&data).unwrap();
968+
let reply = agent.handle_stun(response, to);
969+
// reply is ignored as it does not have credentials
970+
assert!(matches!(reply, HandleStunReply::Drop));
971+
assert!(agent.request_transaction(transaction_id).is_some());
972+
assert!(agent.mut_request_transaction(transaction_id).is_some());
973+
974+
// unvalidated peer data should be dropped
975+
assert!(!agent.is_validated_peer(remote_addr));
976+
}
977+
938978
#[test]
939979
fn response_with_incorrect_credentials() {
940980
init();

0 commit comments

Comments
 (0)