Skip to content

Commit

Permalink
Filter authentication metadata requests during recording (Azure#14113)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell authored Oct 1, 2020
1 parent 96a605d commit 7ee103c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .preparers import AbstractPreparer, SingleValueReplacer
from .recording_processors import (
RecordingProcessor, SubscriptionRecordingProcessor,
LargeRequestBodyProcessor, LargeResponseBodyProcessor, LargeResponseBodyReplacer,
LargeRequestBodyProcessor, LargeResponseBodyProcessor, LargeResponseBodyReplacer, AuthenticationMetadataFilter,
OAuthRequestResponsesFilter, DeploymentNameReplacer, GeneralNameReplacer, AccessTokenReplacer, RequestUrlNormalizer,
)
from .utilities import create_random_name, get_sha1_hash
Expand All @@ -21,7 +21,8 @@
'AbstractPreparer', 'SingleValueReplacer', 'AllowLargeResponse',
'RecordingProcessor', 'SubscriptionRecordingProcessor',
'LargeRequestBodyProcessor', 'LargeResponseBodyProcessor', 'LargeResponseBodyReplacer',
'OAuthRequestResponsesFilter', 'DeploymentNameReplacer', 'GeneralNameReplacer',
'AuthenticationMetadataFilter', 'OAuthRequestResponsesFilter',
'DeploymentNameReplacer', 'GeneralNameReplacer',
'AccessTokenReplacer', 'RequestUrlNormalizer',
'live_only', 'record_only',
'create_random_name', 'get_sha1_hash']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ def process_response(self, response):
return response


class AuthenticationMetadataFilter(RecordingProcessor):
"""Remove authority and tenant discovery requests and responses from recordings.
MSAL sends these requests to obtain non-secret metadata about the token authority. Recording them is unnecessary
because tests use fake credentials during playback that don't invoke MSAL.
"""

def process_request(self, request):
if "/.well-known/openid-configuration" in request.uri or "/common/discovery/instance" in request.uri:
return None
return request


class OAuthRequestResponsesFilter(RecordingProcessor):
"""Remove oauth authentication requests and responses from recording."""

Expand Down
3 changes: 2 additions & 1 deletion tools/azure-sdk-tools/devtools_testutils/azure_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from azure_devtools.scenario_tests import (
ReplayableTest, AzureTestError,
GeneralNameReplacer, RequestUrlNormalizer,
OAuthRequestResponsesFilter
AuthenticationMetadataFilter, OAuthRequestResponsesFilter
)
from azure_devtools.scenario_tests.config import TestConfig

Expand Down Expand Up @@ -125,6 +125,7 @@ def _load_settings(self):
def _get_recording_processors(self):
return [
self.scrubber,
AuthenticationMetadataFilter(),
OAuthRequestResponsesFilter(),
RequestUrlNormalizer()
]
Expand Down

0 comments on commit 7ee103c

Please sign in to comment.