Skip to content
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

Option to allow localhost and allowlist #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niborg
Copy link

@niborg niborg commented Oct 4, 2024

The disable_net_connect! will block any outgoing requests. However, some development environments include core infrastructure which requires gRPC communication. For example, projects utilizing a Bigtable emulator that need to keep this dependency functioning as part of the local system while simultanesouly needing disable system-external gRPC calls.

This commit provides an option to allow localhost-like connections, and specify an allowlist of hosts for which gRPC requests should not be disabled. It shadows the pattern used by the Webmock Ruby library.

The `disable_net_connect!` will block any outgoing requests. However, some development
environments include core infrastructure which requires gRPC communication. For example,
projects utilizing a Bigtable emulator that need to keep this dependency functioning as
part of the local system while simultanesouly needing disable system-external gRPC calls.

This commit provides an option to allow localhost-like connections, and specify an
allowlist of hosts for which gRPC requests should not be disabled. It shadows the pattern
used by the Webmock Ruby library.
def initialize
@client = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)
def initialize(host = 'localhost:8000')
@client = Hello::Hello::Stub.new(host, :this_channel_is_insecure)
Copy link
Author

@niborg niborg Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes it easier for specs to make request to external endpoints so we can test that gRPC requests are bypassing GrpcMock.

end

def send_message(msg, client_stream: false, server_stream: false, metadata: {})
def send_message(msg, client_stream: false, server_stream: false, metadata: {}, timeout: 0.1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec requests to localhost fail immediately, but when the tests try to hit a fake outside service we need a timeout to keep things fast.

@niborg
Copy link
Author

niborg commented Nov 4, 2024

@ganmacs any thoughts on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant