New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix failing ldap server tests #18850
Fix failing ldap server tests #18850
Conversation
@@ -15,7 +15,32 @@ | |||
|
|||
let(:response) {} | |||
|
|||
let(:tcp_server_socket) do | |||
double :tcp_server_socket, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible to use instance_double Rex::Socket::TcpServer
here for an InstanceVerifyingDouble - as behind the scenes in result of Rex::Socket::TcpServer.create(...)
is a ::Socket instance that's been monkey patched with modules like Rex::Socket::TcpServer
etc, which makes it awkward to use instance_double
here:
[5] pry(#<Rex::Proto::LDAP::Server>)> whereami
From: /Users/user/Documents/code/metasploit-framework/lib/rex/proto/ldap/server.rb:102 Rex::Proto::LDAP::Server#start:
97: end
98:
99: if serve_tcp
100: @tcp_sock = Rex::Socket::TcpServer.create(sock_options)
101: require 'pry-byebug'; binding.pry
=> 102: tcp_sock.on_client_connect_proc = proc do |cli|
103: on_client_connect(cli)
104: end
105: tcp_sock.on_client_data_proc = proc do |cli|
106: on_client_data(cli)
107: end
[6] pry(#<Rex::Proto::LDAP::Server>)> @tcp_sock.class
=> Socket
[7] pry(#<Rex::Proto::LDAP::Server>)> @tcp_sock.singleton_class.included_modules
=> [Rex::Socket::TcpServer,
Rex::IO::StreamServer,
Rex::Socket,
Net::BER::BERParser,
...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible can you explain why that was happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For unit tests we generally want to avoid creating real servers etc. So I've gone with mocking the Rex::Socket::TcpServer.create(...)
call.
The rex-socket implementation uses Ruby's API for creating a socket here:
And here:
Then adds additional methods and state onto the socket instance with .extend ...
here:
Let me know if I haven't answered your question 😄
cc @JustAnda7 - does this look okay to you as fix? 🤞 |
Thanks for correcting my mistakes. |
Release NotesFixes failing ldap server tests |
Fix failing ldap server tests introduced by #18678 - by no longer creating real TCP or UDP sockets
Verification
Ensure tests pass locally when port 40000 is already bound:
Before:
After: