bf2343b7e4
Integration Tests - MySQL + Elasticsearch / Detect Changes (push) Has been cancelled
Integration Tests - MySQL + Elasticsearch / integration-tests-mysql-elasticsearch (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / integration-tests-postgres-elasticsearch-redis (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / integration-tests-postgres-opensearch (push) Has been cancelled
Java Checkstyle / java-checkstyle (push) Has been cancelled
Maven Collate Tests / maven-collate-ci (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests-status (push) Has been cancelled
Publish Package to Maven Central Repository / publish-maven-packages (push) Has been cancelled
OpenMetadata Service Unit Tests / Detect Changes (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests (push) Has been cancelled
OpenMetadata Service Unit Tests / k8s_operator-unit-tests (push) Has been cancelled
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
# Copyright 2025 Collate
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""
|
|
Test AWS Client region validation
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from metadata.clients.aws_client import VALID_AWS_REGIONS, AWSClient
|
|
from metadata.generated.schema.security.credentials.awsCredentials import AWSCredentials
|
|
|
|
|
|
class TestAWSClientRegionValidation:
|
|
"""Validate AWS region validation in AWSClient"""
|
|
|
|
def test_valid_regions_sourced_from_botocore(self):
|
|
assert isinstance(VALID_AWS_REGIONS, set)
|
|
assert len(VALID_AWS_REGIONS) > 0
|
|
assert "us-east-1" in VALID_AWS_REGIONS
|
|
assert "eu-west-1" in VALID_AWS_REGIONS
|
|
|
|
@pytest.mark.parametrize(
|
|
"region",
|
|
[
|
|
"us-east-1",
|
|
"us-west-2",
|
|
"eu-west-1",
|
|
"ap-southeast-1",
|
|
"us-gov-west-1",
|
|
"cn-north-1",
|
|
],
|
|
)
|
|
def test_valid_regions_accepted(self, region):
|
|
config = AWSCredentials(awsRegion=region)
|
|
client = AWSClient(config)
|
|
assert client.config.awsRegion == region
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid_region",
|
|
[
|
|
"us-west-2b",
|
|
"us-east-1a",
|
|
"eu-west-1c",
|
|
"ap-southeast-1b",
|
|
],
|
|
)
|
|
def test_availability_zone_rejected(self, invalid_region):
|
|
config = AWSCredentials(awsRegion=invalid_region)
|
|
with pytest.raises(ValueError, match="Invalid AWS Region"):
|
|
AWSClient(config)
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid_region",
|
|
[
|
|
"invalid-region",
|
|
"us-east",
|
|
"east-1",
|
|
],
|
|
)
|
|
def test_arbitrary_string_rejected(self, invalid_region):
|
|
config = AWSCredentials(awsRegion=invalid_region)
|
|
with pytest.raises(ValueError, match="Invalid AWS Region"):
|
|
AWSClient(config)
|
|
|
|
def test_error_message_contains_invalid_value(self):
|
|
config = AWSCredentials(awsRegion="us-west-2b")
|
|
with pytest.raises(ValueError, match="us-west-2b"):
|
|
AWSClient(config)
|
|
|
|
def test_availability_zone_error_includes_hint(self):
|
|
config = AWSCredentials(awsRegion="us-west-2b")
|
|
with pytest.raises(ValueError, match="availability zone"):
|
|
AWSClient(config)
|
|
|
|
def test_non_az_error_omits_az_hint(self):
|
|
config = AWSCredentials(awsRegion="invalid-region")
|
|
with pytest.raises(ValueError, match="Invalid AWS Region") as exc_info:
|
|
AWSClient(config)
|
|
assert "availability zone" not in str(exc_info.value)
|
|
|
|
def test_none_config_accepted(self):
|
|
client = AWSClient(None)
|
|
assert client.config is None
|
|
|
|
def test_all_valid_regions_accepted(self):
|
|
for region in VALID_AWS_REGIONS:
|
|
config = AWSCredentials(awsRegion=region)
|
|
client = AWSClient(config)
|
|
assert client.config.awsRegion == region
|