Skip to content

Commit

Permalink
CDK: Fix initialize of token_expiry_is_time_of_expiration field (#31279)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhenii-ldv authored Oct 11, 2023
1 parent 370821d commit 17136a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def create_oauth_authenticator(self, model: OAuthAuthenticatorModel, config: Con
scopes=model.scopes,
token_expiry_date=model.token_expiry_date,
token_expiry_date_format=model.token_expiry_date_format, # type: ignore
token_expiry_is_time_of_expiration=bool(model.token_expiry_date),
token_expiry_is_time_of_expiration=bool(model.token_expiry_date_format),
token_refresh_endpoint=model.token_refresh_endpoint,
config=config,
parameters=model.parameters or {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ def test_interpolate_config():
assert authenticator.get_refresh_request_body() == {"body_field": "yoyoyo", "interpolated_body_field": "verysecrettoken"}


def test_interpolate_config_with_token_expiry_date_format():
content = """
authenticator:
type: OAuthAuthenticator
client_id: "some_client_id"
client_secret: "some_client_secret"
token_refresh_endpoint: "https://api.sendgrid.com/v3/auth"
refresh_token: "{{ config['apikey'] }}"
token_expiry_date_format: "%Y-%m-%d %H:%M:%S.%f+00:00"
"""
parsed_manifest = YamlDeclarativeSource._parse(content)
resolved_manifest = resolver.preprocess_manifest(parsed_manifest)
authenticator_manifest = transformer.propagate_types_and_parameters("", resolved_manifest["authenticator"], {})

authenticator = factory.create_component(
model_type=OAuthAuthenticatorModel, component_definition=authenticator_manifest, config=input_config
)

assert isinstance(authenticator, DeclarativeOauth2Authenticator)
assert authenticator.token_expiry_date_format == "%Y-%m-%d %H:%M:%S.%f+00:00"
assert authenticator.token_expiry_is_time_of_expiration
assert authenticator.client_id.eval(input_config) == "some_client_id"
assert authenticator.client_secret.string == "some_client_secret"
assert authenticator.token_refresh_endpoint.eval(input_config) == "https://api.sendgrid.com/v3/auth"


def test_single_use_oauth_branch():
single_use_input_config = {
"apikey": "verysecrettoken",
Expand Down

0 comments on commit 17136a0

Please sign in to comment.