Skip to content

Commit

Permalink
Techdebt: Remove ACM/pytest warnings (#7350)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Feb 17, 2024
1 parent 4b89874 commit 8561740
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
id: pip-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/dockertests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
id: pip-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand All @@ -82,8 +82,6 @@ jobs:
if: always()
run: |
mkdir serverlogs1
pwd
ls -la
cp server_output.log serverlogs1/server_output.log
docker stop motoserver
- name: Archive Logs
Expand Down Expand Up @@ -122,7 +120,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand All @@ -141,8 +139,6 @@ jobs:
if: always()
run: |
mkdir serverlogs2
pwd
ls -la
cp server_output.log serverlogs2/server_output.log
- name: Archive logs
if: always()
Expand Down Expand Up @@ -179,7 +175,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand All @@ -200,10 +196,7 @@ jobs:
if: always()
run: |
mkdir serverlogs3
pwd
ls -la
cp server_output.log serverlogs3/server_output.log
ls -la serverlogs3
- name: Archive Logs
if: always()
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_outdated_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
responses-version: ["0.15.0", "0.17.0", "0.19.0", "0.20.0" ]
werkzeug-version: ["2.0.1", "2.1.1", "2.2.2"]
openapi-spec-validator-version: ["0.5.0"]
cryptography-version: ["39.0.0"]

steps:
- name: Checkout repository
Expand All @@ -40,6 +41,7 @@ jobs:
pip install werkzeug==${{ matrix.werkzeug-version }}
pip install openapi-spec-validator==${{ matrix.openapi-spec-validator-version }}
pip install ${{ matrix.botocore }}
pip install cryptography==${{ matrix.cryptography-version }}
- name: Run tests
run: |
Expand All @@ -59,8 +61,6 @@ jobs:
if: always()
run: |
mkdir serverlogs
pwd
ls -la
cp server_output.log serverlogs/server_output.log
docker stop motoserver
- name: Archive TF logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_decoratormode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tests_proxymode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand All @@ -45,8 +45,6 @@ jobs:
- name: "Stop MotoProxy"
if: always()
run: |
pwd
ls -la
kill $(lsof -t -i:5005)
- name: Archive Proxy logs
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_real_aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-3.11-${{ hashFiles('**/setup.cfg') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_sdk_dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock python:3.10-slim /moto/scripts/ci_moto_server.sh &
python scripts/ci_wait_for_server.py
- uses: actions/setup-dotnet@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tests_servermode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
Expand Down Expand Up @@ -60,8 +60,6 @@ jobs:
if: always()
run: |
mkdir serverlogs
pwd
ls -la
cp server_output.log serverlogs/server_output.log
docker stop motoserver
- name: Archive TF logs
Expand Down
28 changes: 22 additions & 6 deletions moto/acm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
)

now = utcnow()
if _cert.not_valid_after < now:
if self._not_valid_after(_cert) < now:
raise AWSValidationException(
"The certificate has expired, is not valid."
)

if _cert.not_valid_before > now:
if self._not_valid_before(_cert) > now:
raise AWSValidationException(
"The certificate is not in effect yet, is not valid."
)
Expand All @@ -256,6 +256,22 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
)
return _cert

def _not_valid_after(
self, _cert: cryptography.x509.base.Certificate
) -> datetime.datetime:
try:
return _cert.not_valid_after_utc.replace(tzinfo=None)
except AttributeError:
return _cert.not_valid_after

def _not_valid_before(
self, _cert: cryptography.x509.base.Certificate
) -> datetime.datetime:
try:
return _cert.not_valid_before_utc.replace(tzinfo=None)
except AttributeError:
return _cert.not_valid_before

def validate_chain(self) -> None:
try:
for cert_armored in self.chain.split(b"-\n-"):
Expand All @@ -267,12 +283,12 @@ def validate_chain(self) -> None:
)

now = utcnow()
if self._cert.not_valid_after < now:
if self._not_valid_after(self._cert) < now:
raise AWSValidationException(
"The certificate chain has expired, is not valid."
)

if self._cert.not_valid_before > now:
if self._not_valid_before(self._cert) > now:
raise AWSValidationException(
"The certificate chain is not in effect yet, is not valid."
)
Expand Down Expand Up @@ -325,8 +341,8 @@ def describe(self) -> Dict[str, Any]:
0
].value,
"KeyAlgorithm": key_algo,
"NotAfter": datetime_to_epoch(self._cert.not_valid_after),
"NotBefore": datetime_to_epoch(self._cert.not_valid_before),
"NotAfter": datetime_to_epoch(self._not_valid_after(self._cert)),
"NotBefore": datetime_to_epoch(self._not_valid_before(self._cert)),
"Serial": str(self._cert.serial_number),
"SignatureAlgorithm": self._cert.signature_algorithm_oid._name.upper().replace(
"ENCRYPTION", ""
Expand Down
10 changes: 8 additions & 2 deletions moto/acmpca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ def certificate_bytes(self) -> bytes:
def not_valid_after(self) -> Optional[float]:
if self.certificate is None:
return None
return unix_time(self.certificate.not_valid_after)
try:
return unix_time(self.certificate.not_valid_after_utc.replace(tzinfo=None))
except AttributeError:
return unix_time(self.certificate.not_valid_after)

@property
def not_valid_before(self) -> Optional[float]:
if self.certificate is None:
return None
return unix_time(self.certificate.not_valid_before)
try:
return unix_time(self.certificate.not_valid_before_utc.replace(tzinfo=None))
except AttributeError:
return unix_time(self.certificate.not_valid_before)

def import_certificate_authority_certificate(
self, certificate: bytes, certificate_chain: Optional[bytes]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_awslambda/test_lambda_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from moto import mock_aws, settings

from ..markers import requires_docker
from .test_lambda import LooseVersion, boto3_version
from .utilities import (
get_lambda_using_environment_port,
get_lambda_using_network_mode,
Expand Down Expand Up @@ -383,6 +384,8 @@ def test_invoke_lambda_with_proxy():
@mock_aws
@requires_docker
def test_invoke_lambda_with_entrypoint():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("ImageConfig parameter not available in older versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
conn.create_function(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


@mock_aws
def test_without_parentheses() -> int:
def method_without_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 123


@mock_aws()
def test_with_parentheses() -> int:
def method_with_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 456

Expand All @@ -35,8 +35,8 @@ def test_manual() -> None:
m.stop()


x: int = test_with_parentheses()
x: int = method_with_parentheses()
assert x == 456

y: int = test_without_parentheses()
y: int = method_without_parentheses()
assert y == 123
2 changes: 1 addition & 1 deletion tests/test_ec2/test_route_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def test_create_route_with_vpc_endpoint():
VpcEndpointId=vpce_id,
RouteTableId=route_table.id,
)
rt = ec2_client.describe_route_tables()
rt = ec2_client.describe_route_tables(RouteTableIds=[route_table.id])
new_route = rt["RouteTables"][-1]["Routes"][1]

# Verify
Expand Down

0 comments on commit 8561740

Please sign in to comment.