Skip to content

Commit

Permalink
CAT: Add scenario that OAuth is default method and fields are marked …
Browse files Browse the repository at this point in the history
…as airbyte_secret (#34178)
  • Loading branch information
darynaishchenko committed Jan 25, 2024
1 parent 6dc61d1 commit 89cfb39
Show file tree
Hide file tree
Showing 6 changed files with 431 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.1.0
Add TestSpec.test_oauth_is_default_method test with OAuth is default option validation.

## 3.0.1
Upgrade to Dagger 0.9.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class BackwardCompatibilityTestsConfig(BaseConfig):
)


class OAuthTestConfig(BaseConfig):
oauth = Field(True, description="Allow source to have another default method that OAuth.")
bypass_reason: Optional[str] = Field(description="Reason why OAuth is not default method.")

@validator("oauth", always=True)
def validate_oauth(cls, oauth, values):
if oauth is False and not values.get("bypass_reason"):
raise ValueError("Please provide a bypass reason for Auth default method")
return oauth


class SpecTestConfig(BaseConfig):
spec_path: str = spec_path
config_path: str = config_path
Expand All @@ -50,6 +61,7 @@ class SpecTestConfig(BaseConfig):
backward_compatibility_tests_config: BackwardCompatibilityTestsConfig = Field(
description="Configuration for the backward compatibility tests.", default=BackwardCompatibilityTestsConfig()
)
auth_default_method: Optional[OAuthTestConfig] = Field(description="Auth default method details.")


class ConnectionTestConfig(BaseConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ async def skip_backward_compatibility_tests_fixture(
pytest.skip(f"Backward compatibility tests are disabled for version {previous_connector_version}.")
return False

@pytest.fixture(name="skip_oauth_default_method_test")
def skip_oauth_default_method_test_fixture(self, inputs: SpecTestConfig):
if inputs.auth_default_method and not inputs.auth_default_method.oauth:
pytest.skip(f"Skipping OAuth is default method test: {inputs.auth_default_method.bypass_reason}")
return False

def test_config_match_spec(self, actual_connector_spec: ConnectorSpecification, connector_config: SecretDict):
"""Check that config matches the actual schema from the spec call"""
# Getting rid of technical variables that start with an underscore
Expand Down Expand Up @@ -521,6 +527,29 @@ def test_oauth_flow_parameters(self, actual_connector_spec: ConnectorSpecificati
diff = paths_to_validate - set(get_expected_schema_structure(spec_schema))
assert diff == set(), f"Specified oauth fields are missed from spec schema: {diff}"

def test_oauth_is_default_method(self, skip_oauth_default_method_test: bool, actual_connector_spec: ConnectorSpecification):
"""
OAuth is default check.
If credentials do have oneOf: we check that the OAuth is listed at first.
If there is no oneOf and Oauth: OAuth is only option to authenticate the source and no check is needed.
"""
advanced_auth = actual_connector_spec.advanced_auth
if not advanced_auth:
pytest.skip("Source does not have OAuth method.")

spec_schema = actual_connector_spec.connectionSpecification
credentials = advanced_auth.predicate_key[0]
try:
one_of_default_method = dpath.util.get(spec_schema, f"/**/{credentials}/oneOf/0")
except KeyError as e: # Key Error when oneOf is not in credentials object
pytest.skip("Credentials object does not have oneOf option.")

path_in_credentials = "/".join(advanced_auth.predicate_key[1:])
auth_method_predicate_const = dpath.util.get(one_of_default_method, f"/**/{path_in_credentials}/const")
assert (
auth_method_predicate_const == advanced_auth.predicate_value
), f"Oauth method should be a default option. Current default method is {auth_method_predicate_const}."

@pytest.mark.default_timeout(ONE_MINUTE)
@pytest.mark.backward_compatibility
def test_backward_compatibility(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "connector-acceptance-test"
version = "3.0.1"
version = "3.1.0"
description = "Contains acceptance tests for connectors."
authors = ["Airbyte <contact@airbyte.io>"]
license = "MIT"
Expand Down
Loading

0 comments on commit 89cfb39

Please sign in to comment.