test(eventhubs): cover SAS auth and connection options - #5092
Draft
Johnathan W (j7nw4r) wants to merge 1 commit into
Draft
test(eventhubs): cover SAS auth and connection options#5092Johnathan W (j7nw4r) wants to merge 1 commit into
Johnathan W (j7nw4r) wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Add one test file for Shared Access Signature authentication and for the connection options that go with it. - Mint a SAS token with an independent signer and pin it against the vector the crate's own signer is tested with. This test is offline and runs in every mode. - Send and receive with a pre-formed SharedAccessSignature connection string that carries no key and no key name. - Prove that a namespace rule with only Send rights can send and cannot receive, and that a rule with only Listen rights can receive and cannot send. - Complete a service operation through an explicit custom endpoint, and show that an unreachable custom endpoint fails the open while the same connection string opens without it. The eight live tests read EVENTHUBS_SEND_ONLY_CONNECTION_STRING and EVENTHUBS_LISTEN_ONLY_CONNECTION_STRING, which come from the SendOnly and ListenOnly rules in sdk/eventhubs/test-resources.bicep. They pass only against a namespace that has local authentication enabled. Refs Azure#4892
Johnathan W (j7nw4r)
force-pushed
the
j7nw4r/eventhubs-sas-auth-live-tests
branch
from
August 25, 2026 18:13
b12bc72 to
f2cfe31
Compare
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.
Summary
The Event Hubs live tests authenticate with a token credential and with a connection string that carries a shared access key. This change adds a test file for Shared Access Signature (SAS) authentication and the connection options that go with it: a pre-formed SAS token, the
SendOnlyandListenOnlyauthorization rules in both directions, andwith_custom_endpoint. Nine tests are added, of which eight are live and one runs offline.Motivation
Each authentication mode takes a different code path to build the AMQP claim, so a defect in one mode is invisible to the tests for another mode. No test presents a pre-formed SAS token today, although
src/common/sas_credential.rsimplements one. TheSendOnlyandListenOnlyrules thattest-resources.bicepalready creates are unused, so nothing proves that the SDK surfaces a clear error when a credential lacks a permission. Thewith_custom_endpointoption has only a unit test that asserts the field is stored, and nothing proves the value reaches the dial.Changes
sdk/eventhubs/azure_messaging_eventhubs/tests/eventhubs_sas_auth.rswith nine tests.minted_sas_token_matches_the_crate_reference_vectoris a plain#[test]. It pins the file's own SAS signer against the reference vector that the crate's signer is tested with, and makes sure the built connection string carries no key fields.preformed_sas_producer_sendsandpreformed_sas_consumer_receivesopen a producer and a consumer with a pre-formed token. The token reaches the client inside a connection string, because that is the only public route;SasCredentialis crate-private and no public API accepts a token directly.amqps://{namespace}/{eventhub}, which is the path the client claims. A token signed with thesb://form that the Microsoft samples show would fail the prefix match and give a spurious authorization error.send_only_rule_can_send,send_only_rule_cannot_receive,listen_only_rule_can_receive, andlisten_only_rule_cannot_sendcover both scoped rules in both directions.open.openends atensure_connection, which never authorizes a path, so a credential with the wrong rights still opens successfully. The claim reaches the wire only at the link attach.custom_endpoint_completes_a_service_operationandcustom_endpoint_is_used_for_the_dialcoverwith_custom_endpoint. The second test opens once against the namespace and once against an unreachable endpoint, so a custom endpoint that never reaches the dial makes the test fail.Cargo.tomledit, and no CHANGELOG entry. The file uses only crates the package already depends on.Test plan
cargo test -p azure_messaging_eventhubs --all-features --test eventhubs_sas_auth -- --test-threads=1reports1 passed; 0 failed; 8 ignored. Each ignored line reads "ignored, skipping live tests"..to_lowercase()from the resource step makes it fail with uppercase percent-encoding against the expected literal. Adding aSharedAccessKeyfield to the built connection string makes its second assertion fail.RUSTFLAGS=-Dwarnings cargo test --no-run --package azure_messaging_eventhubspasses, which is the gate that CI applies througheng/pipelines/templates/variables/rust.yml.cargo test -p azure_messaging_eventhubs --all-features -- --test-threads=1,cargo fmt --package azure_messaging_eventhubs -- --check,cargo clippy -p azure_messaging_eventhubs --all-features --all-targetswith-Dwarnings,cargo doc -p azure_messaging_eventhubs --all-features --no-depswith-Dwarnings, and cspell with the repository config all pass.AZURE_TEST_MODE=live cargo test -p azure_messaging_eventhubs --all-features --test eventhubs_sas_auth -- --test-threads=1.EVENTHUBS_HOST,EVENTHUB_NAME,EVENTHUBS_CONNECTION_STRING,EVENTHUBS_SEND_ONLY_CONNECTION_STRING, andEVENTHUBS_LISTEN_ONLY_CONNECTION_STRING. Read every secret from the environment at run time.SendOnlyandListenOnlyrules. The template creates the rules but publishes no key, and its only connection-string output stays commented out, so an operator sets the two variables by hand.test-resources.bicepsetsdisableLocalAuth: !tenantIsTME, so on a non-TME tenant every SAS test here fails at open for that reason and not for a defect.custom_endpoint_completes_a_service_operationcannot tell an honored custom endpoint from an ignored one when the endpoint is the namespace itself, andcustom_endpoint_is_used_for_the_dialis the test that closes that gap. The helper that builds the pre-formed connection string has no offline coverage, because it reads environment variables.ErrorKindhas noUnauthorizedvariant, and the broker can refuse at either the CBS put-token or the link attach, which surface as different types. The first live run prints the full error, so a follow-up can tighten the assertion.Part of #4886.
Closes #4892.
Live validation
Every test here ran against a live Event Hubs namespace on 2026-08-20: 9 passed, 0 failed.
Command:
AZURE_TEST_MODE=live cargo test --package azure_messaging_eventhubs --test eventhubs_sas_auth -- --test-threads=1.No change was needed. The independently minted SAS token authenticated, both scoped rules failed in the disallowed direction and succeeded in the allowed one, and both custom endpoint tests passed.