Skip to content

Commit

Permalink
Raise on bad credential (#16206)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshith91 authored Jan 15, 2021
1 parent c739da5 commit b3960b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

**Bug Fixes**
- `EventGridEvent` has two additional required positional parameters namely, `data` and `data_version`.
- `EventGridPublisherClient` now appropriately throws a `ValueError` if an invalid credential is passed during initialization.

## 2.0.0b4 (2020-11-11)

Expand Down
6 changes: 3 additions & 3 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def _get_authentication_policy(credential):
if credential is None:
raise ValueError("Parameter 'self._credential' must not be None.")
if isinstance(credential, AzureKeyCredential):
authentication_policy = AzureKeyCredentialPolicy(credential=credential, name=constants.EVENTGRID_KEY_HEADER)
return AzureKeyCredentialPolicy(credential=credential, name=constants.EVENTGRID_KEY_HEADER)
if isinstance(credential, AzureSasCredential):
authentication_policy = EventGridSasCredentialPolicy(
return EventGridSasCredentialPolicy(
credential=credential,
name=constants.EVENTGRID_TOKEN_HEADER
)
return authentication_policy
raise ValueError("The provided credential should be an instance of AzureSasCredential or AzureKeyCredential")

def _is_cloud_event(event):
# type: (Any) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,8 @@ def test_send_custom_schema_event_as_list(self, resource_group, eventgrid_topic,
}
)
client.send([custom_event1, custom_event2])

def test_send_throws_with_bad_credential(self):
bad_credential = "I am a bad credential"
with pytest.raises(ValueError, match="The provided credential should be an instance of AzureSasCredential or AzureKeyCredential"):
client = EventGridPublisherClient("eventgrid_endpoint", bad_credential)

0 comments on commit b3960b1

Please sign in to comment.