diff --git a/.github/workflows/stage-cf-deploy-lambda.yml b/.github/workflows/stage-cf-deploy-lambda.yml index 7c952e4..1283960 100644 --- a/.github/workflows/stage-cf-deploy-lambda.yml +++ b/.github/workflows/stage-cf-deploy-lambda.yml @@ -5,14 +5,13 @@ name: Stage CF Lambda@Edge Full Deploy on: - workflow_dispatch: - ## We are skipping automation for now - # push: - # branches: - # - main - # paths-ignore: - # - ".github/**" - # - "tests/**" + workflow_dispatch: + push: + branches: + - main + paths-ignore: + - ".github/**" + - "tests/**" defaults: run: diff --git a/.python-version b/.python-version index bd28b9c..0c7d5f5 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.9 +3.11.4 diff --git a/Makefile b/Makefile index dcd6035..7dc0113 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,7 @@ safety: # check for security vulnerabilities and verify Pipfile.lock is up-to-da pipenv check pipenv verify -lint-apply: # apply changes with 'black' and resolve 'fixable errors' with 'ruff' - black-apply +lint-apply: black-apply # apply changes with 'black' black-apply: # apply changes with 'black' pipenv run black . diff --git a/Pipfile b/Pipfile index d09639f..ca36f75 100644 --- a/Pipfile +++ b/Pipfile @@ -3,9 +3,6 @@ url = "https://pypi.org/simple" verify_ssl = true name = "pypi" -[packages] -sentry-sdk = "*" - [dev-packages] black = "*" coveralls = "*" @@ -13,4 +10,4 @@ pre-commit = "*" pytest = "*" [requires] -python_version = "3.9" +python_version = "3.11" diff --git a/Pipfile.lock b/Pipfile.lock index 52f8b1f..3e28e9a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "22609267546a114134e38dbf7b546bd26cd940968cf5cf4afcf8047586ba1d54" + "sha256": "ff71304bf1aeb4292fa691b2bea64d8145d68e239d6ca2bd68d4cbec58ae2d9b" }, "pipfile-spec": 6, "requires": { - "python_version": "3.9" + "python_version": "3.11" }, "sources": [ { @@ -15,32 +15,7 @@ } ] }, - "default": { - "certifi": { - "hashes": [ - "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1", - "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474" - ], - "markers": "python_version >= '3.6'", - "version": "==2023.11.17" - }, - "sentry-sdk": { - "hashes": [ - "sha256:320a55cdf9da9097a0bead239c35b7e61f53660ef9878861824fd6d9b2eaf3b5", - "sha256:81b5b9ffdd1a374e9eb0c053b5d2012155db9cbe76393a8585677b753bd5fdc1" - ], - "index": "pypi", - "version": "==1.39.1" - }, - "urllib3": { - "hashes": [ - "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3", - "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54" - ], - "markers": "python_version >= '3.6'", - "version": "==2.1.0" - } - }, + "default": {}, "develop": { "black": { "hashes": [ @@ -269,14 +244,6 @@ ], "version": "==0.6.2" }, - "exceptiongroup": { - "hashes": [ - "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14", - "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68" - ], - "markers": "python_version < '3.11'", - "version": "==1.2.0" - }, "filelock": { "hashes": [ "sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e", @@ -447,28 +414,12 @@ "markers": "python_version >= '3.8'", "version": "==69.0.3" }, - "tomli": { - "hashes": [ - "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", - "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" - ], - "markers": "python_version < '3.11'", - "version": "==2.0.1" - }, - "typing-extensions": { - "hashes": [ - "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783", - "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd" - ], - "markers": "python_version < '3.11'", - "version": "==4.9.0" - }, "urllib3": { "hashes": [ "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3", "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '3.8'", "version": "==2.1.0" }, "virtualenv": { diff --git a/tests/fixtures/origin-event-cdn-dev.json b/tests/fixtures/origin-event-cdn-dev.json new file mode 100644 index 0000000..c93600d --- /dev/null +++ b/tests/fixtures/origin-event-cdn-dev.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "cdn.dev1.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 783f879853c2b9ca9ca52e32a3b62dd8.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.dev1.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-cdn-prod-1.json b/tests/fixtures/origin-event-cdn-prod-1.json new file mode 100644 index 0000000..3f797c6 --- /dev/null +++ b/tests/fixtures/origin-event-cdn-prod-1.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "cdn.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 336a36b0f05a8791fdf32df30f71a8f4.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-cdn-prod-2.json b/tests/fixtures/origin-event-cdn-prod-2.json new file mode 100644 index 0000000..15c72e8 --- /dev/null +++ b/tests/fixtures/origin-event-cdn-prod-2.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "cdn.libraries.mit.edu" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 336a36b0f05a8791fdf32df30f71a8f4.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-cdn-stage.json b/tests/fixtures/origin-event-cdn-stage.json new file mode 100644 index 0000000..8a42351 --- /dev/null +++ b/tests/fixtures/origin-event-cdn-stage.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "cdn.stage.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 336a36b0f05a8791fdf32df30f71a8f4.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.stage.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-fol-dev.json b/tests/fixtures/origin-event-fol-dev.json new file mode 100644 index 0000000..1969ae9 --- /dev/null +++ b/tests/fixtures/origin-event-fol-dev.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "fol.dev1.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 405b8ed0c1df92e14644e6db88a3af5a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.dev1.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-fol-prod-1.json b/tests/fixtures/origin-event-fol-prod-1.json new file mode 100644 index 0000000..b979fab --- /dev/null +++ b/tests/fixtures/origin-event-fol-prod-1.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "fol.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 e253a912687c0fa80cad9ce4b2103a4a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] + } diff --git a/tests/fixtures/origin-event-fol-prod-2.json b/tests/fixtures/origin-event-fol-prod-2.json new file mode 100644 index 0000000..203fd47 --- /dev/null +++ b/tests/fixtures/origin-event-fol-prod-2.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "fol.libraries.mit.edu" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 405b8ed0c1df92e14644e6db88a3af5a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/fixtures/origin-event-fol-stage.json b/tests/fixtures/origin-event-fol-stage.json new file mode 100644 index 0000000..4f377c9 --- /dev/null +++ b/tests/fixtures/origin-event-fol-stage.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "fol.stage.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 e253a912687c0fa80cad9ce4b2103a4a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] + } diff --git a/tests/fixtures/origin-event-gc-prod-1.json b/tests/fixtures/origin-event-gc-prod-1.json new file mode 100644 index 0000000..d21c63e --- /dev/null +++ b/tests/fixtures/origin-event-gc-prod-1.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "grandchallenges.mitlibrary.net" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 e253a912687c0fa80cad9ce4b2103a4a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] + } diff --git a/tests/fixtures/origin-event-gc-prod-2.json b/tests/fixtures/origin-event-gc-prod-2.json new file mode 100644 index 0000000..0c468b5 --- /dev/null +++ b/tests/fixtures/origin-event-gc-prod-2.json @@ -0,0 +1,61 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionDomainName": "d111111abcdef8.cloudfront.net", + "distributionId": "EDFDVBD6EXAMPLE", + "eventType": "origin-request", + "requestId": "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + "request": { + "clientIp": "1.2.3.4", + "headers": { + "host": [ + { + "key": "Host", + "value": "grandchallenges.libraries.mit.edu" + } + ], + "x-forwarded-for": [ + { + "key": "X-Forwarded-For", + "value": "1.2.3.4" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Amazon CloudFront" + } + ], + "via": [ + { + "key": "Via", + "value": "2.0 405b8ed0c1df92e14644e6db88a3af5a.cloudfront.net (CloudFront)" + } + ], + "accept-encoding": [ + { + "key": "Accept-Encoding", + "value": "gzip" + } + ] + }, + "method": "GET", + "origin": { + "s3": { + "authMethod": "origin-access-identity", + "customHeaders": {}, + "domainName": "cdn.mitlibrary.net.s3.amazonaws.com", + "path": "", + "region": "us-east-1" + } + }, + "querystring": "", + "uri": "/index.html" + } + } + } + ] +} diff --git a/tests/test_lambda_edge_cdn_fol.py b/tests/test_lambda_edge_cdn_fol.py new file mode 100644 index 0000000..5dbeb2a --- /dev/null +++ b/tests/test_lambda_edge_cdn_fol.py @@ -0,0 +1,40 @@ +from importlib import reload + +import pytest +import json + +from lambdas import lambda_edge + + +def test_lambda_edge_dev(): + with open("tests/fixtures/origin-event-fol-dev.json", encoding="utf-8") as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/fol" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_stage(): + with open( + "tests/fixtures/origin-event-fol-stage.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/fol" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_prod_1(): + with open( + "tests/fixtures/origin-event-fol-prod-1.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/fol" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_prod_2(): + with open( + "tests/fixtures/origin-event-fol-prod-2.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/fol" + assert lambda_response["uri"] == "/index.html" diff --git a/tests/test_lambda_edge_cdn_gc.py b/tests/test_lambda_edge_cdn_gc.py new file mode 100644 index 0000000..21de7b9 --- /dev/null +++ b/tests/test_lambda_edge_cdn_gc.py @@ -0,0 +1,24 @@ +from importlib import reload + +import pytest +import json + +from lambdas import lambda_edge + + +def test_lambda_edge_prod_1(): + with open( + "tests/fixtures/origin-event-gc-prod-1.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/grandchallenges" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_prod_2(): + with open( + "tests/fixtures/origin-event-gc-prod-2.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "/grandchallenges" + assert lambda_response["uri"] == "/index.html" diff --git a/tests/test_lambda_edge_cdn_standard.py b/tests/test_lambda_edge_cdn_standard.py new file mode 100644 index 0000000..6fbf1c6 --- /dev/null +++ b/tests/test_lambda_edge_cdn_standard.py @@ -0,0 +1,40 @@ +from importlib import reload + +import pytest +import json + +from lambdas import lambda_edge + + +def test_lambda_edge_dev(): + with open("tests/fixtures/origin-event-cdn-dev.json", encoding="utf-8") as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_stage(): + with open( + "tests/fixtures/origin-event-cdn-stage.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_prod_1(): + with open( + "tests/fixtures/origin-event-cdn-prod-1.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "" + assert lambda_response["uri"] == "/index.html" + + +def test_lambda_edge_prod_2(): + with open( + "tests/fixtures/origin-event-cdn-prod-2.json", encoding="utf-8" + ) as json_file: + lambda_response = lambda_edge.lambda_handler(json.load(json_file), "context") + assert lambda_response["origin"]["s3"]["path"] == "" + assert lambda_response["uri"] == "/index.html"