Grpc endpoints followup - #97
Open
badnikhil wants to merge 2 commits into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gRPC test rig — follow-up: auth, response metadata & round-trip tests
Follow-up to #94 (which merged the base gRPC test rig). This PR adds the two
remaining gRPC surfaces API Dash needs to exercise — auth-via-metadata and
response metadata — plus a pytest round-trip suite, and documents the
whole service so every feature has a concrete, reproducible recipe.
What this PR adds (on top of #94)
SecureEcho— auth via call metadata. Acceptsauthorization: Bearer test-tokenorx-api-key: test-apikey; anything else →UNAUTHENTICATED. Success echoes[authenticated] <msg>. (grpc/server.py,grpc/proto/apidash_test.proto,docs/grpc/auth.md)EchoMetadataresponse metadata — in addition to echoing your request metadata into the body, it now returns initial metadata (x-server,x-echoed-count) and trailing metadata (x-trailer), so response-metadata handling can be tested. (grpc/server.py,docs/grpc/metadata.md)tests/grpc/test_grpc.py— 12 round-trip tests (one per feature) against a running server. Protobuf stubs are generated on the fly from the proto at collection time (nothing generated is committed); the module skips gracefully when grpcio/-tools are missing or no server is reachable, so CI stays green. (requirements-dev.txt: grpcio + grpcio-tools + grpcio-reflection;docs/grpc/README.md: Tests section)Run it
Point API Dash at
localhost:9000(plaintext) orlocalhost:9001(TLS → Use TLS + Allow Invalid Certificates). Discover methods via Reflect, or importgrpc/proto/apidash_test.protoand Fetch services.Full service reference —
apidash.test.TestServiceEvery method, and how to reproduce it in API Dash (each also has a page under
docs/grpc/):Echo{message}→ echoed backGetRandomUserStreamTickscount→ receive N messagesSumNumbersChatEchoMetadatax-server/x-echoed-count(initial) +x-trailer(trailing)SecureEchoauthorization: Bearer test-tokenorx-api-key: test-apikey, elseUNAUTHENTICATEDtest-token(or API-key headerx-api-key: test-apikey) →[authenticated] …; none/wrong →UNAUTHENTICATEDRaiseErrorcode=5→NOT_FOUNDgrpc.reflection.v1alpha.ServerReflectionTests
12 passed against a live server — reflection,
Echo,GetRandomUser,StreamTicks(count=5 → 5 ticks),SumNumbers,Chat(bidi),EchoMetadata(request echo + initial/trailing response metadata),SecureEcho×4 (no creds →UNAUTHENTICATED, Bearer → ok,x-api-key→ ok, wrong →UNAUTHENTICATED),RaiseErrorcode=5 →NOT_FOUND. Skips (does not fail) when grpcio/-tools are missing or no server is onlocalhost:9000.Why gRPC needs its own Docker (not a FastAPI route)
gRPC is HTTP/2-based, with its own wire framing, Protobuf messages, server reflection and long-lived streams — it can't be a FastAPI route, and Azure App Service's single HTTP/HTTPS port can't host it (same reason as the MQTT rig). So local testing ships a real gRPC server via Docker, defining our own
apidash.test.TestServicewith mock/random data so every feature has a concrete, reproducible use-case.