@@ -952,11 +952,11 @@ pub(crate) mod tests {
952
952
let mut agent = StunAgent :: builder ( TransportType :: Udp , local_addr) . build ( ) ;
953
953
let local_credentials = ShortTermCredentials :: new ( String :: from ( "local_password" ) ) ;
954
954
let remote_credentials = ShortTermCredentials :: new ( String :: from ( "remote_password" ) ) ;
955
- agent. set_local_credentials ( local_credentials. into ( ) ) ;
955
+ agent. set_local_credentials ( local_credentials. clone ( ) . into ( ) ) ;
956
956
agent. set_remote_credentials ( remote_credentials. clone ( ) . into ( ) ) ;
957
957
958
958
let mut msg = Message :: new_request ( BINDING ) ;
959
- msg. add_message_integrity ( & remote_credentials . into ( ) , IntegrityAlgorithm :: Sha1 )
959
+ msg. add_message_integrity ( & local_credentials . into ( ) , IntegrityAlgorithm :: Sha1 )
960
960
. unwrap ( ) ;
961
961
let transmit = agent. send ( msg, remote_addr) . unwrap ( ) ;
962
962
@@ -977,6 +977,42 @@ pub(crate) mod tests {
977
977
assert ! ( reply. is_empty( ) ) ;
978
978
}
979
979
980
+ #[ test]
981
+ fn response_with_incorrect_credentials ( ) {
982
+ init ( ) ;
983
+ let local_addr = "10.0.0.1:12345" . parse ( ) . unwrap ( ) ;
984
+ let remote_addr = "10.0.0.2:3478" . parse ( ) . unwrap ( ) ;
985
+
986
+ let mut agent = StunAgent :: builder ( TransportType :: Udp , local_addr) . build ( ) ;
987
+ let local_credentials = ShortTermCredentials :: new ( String :: from ( "local_password" ) ) ;
988
+ let remote_credentials = ShortTermCredentials :: new ( String :: from ( "remote_password" ) ) ;
989
+ agent. set_local_credentials ( local_credentials. clone ( ) . into ( ) ) ;
990
+ agent. set_remote_credentials ( remote_credentials. into ( ) ) ;
991
+
992
+ let mut msg = Message :: new_request ( BINDING ) ;
993
+ msg. add_message_integrity ( & local_credentials. clone ( ) . into ( ) , IntegrityAlgorithm :: Sha1 )
994
+ . unwrap ( ) ;
995
+ let transmit = agent. send ( msg, remote_addr) . unwrap ( ) ;
996
+
997
+ let request = Message :: from_bytes ( & transmit. data ) . unwrap ( ) ;
998
+
999
+ let mut response = Message :: new_success ( & request) ;
1000
+ response
1001
+ . add_attribute ( XorMappedAddress :: new (
1002
+ transmit. from ,
1003
+ request. transaction_id ( ) ,
1004
+ ) )
1005
+ . unwrap ( ) ;
1006
+ // wrong credentials, should be `remote_credentials`
1007
+ response. add_message_integrity ( & local_credentials. into ( ) , IntegrityAlgorithm :: Sha1 ) . unwrap ( ) ;
1008
+
1009
+ let data = response. to_bytes ( ) ;
1010
+ let to = transmit. to ;
1011
+ let reply = agent. handle_incoming_data ( & data, to) . unwrap ( ) ;
1012
+ // reply is ignored as it does not have credentials
1013
+ assert ! ( reply. is_empty( ) ) ;
1014
+ }
1015
+
980
1016
#[ test]
981
1017
fn tcp_request ( ) {
982
1018
init ( ) ;
0 commit comments