From c3594de5b67bab67737902f861449f2709f7909c Mon Sep 17 00:00:00 2001 From: Lucas Hinderberger Date: Thu, 4 Jul 2024 13:30:07 +0200 Subject: [PATCH] Adding apitest for email endpoints (excl. search) --- test/email/checkbody.json | 104 ++++++++++++++++++++++++++++++ test/email/checkmetadata.json | 75 +++++++++++++++++++++ test/email/expected_index.json | 23 +++++++ test/email/expected_metadata.json | 102 +++++++++++++++++++++++++++++ test/email/manifest.json | 14 ++++ test/email/postmessage.json | 13 ++++ test/email/testmessage.eml | 23 +++++++ 7 files changed, 354 insertions(+) create mode 100644 test/email/checkbody.json create mode 100644 test/email/checkmetadata.json create mode 100644 test/email/expected_index.json create mode 100644 test/email/expected_metadata.json create mode 100644 test/email/manifest.json create mode 100644 test/email/postmessage.json create mode 100644 test/email/testmessage.eml diff --git a/test/email/checkbody.json b/test/email/checkbody.json new file mode 100644 index 0000000..fba851c --- /dev/null +++ b/test/email/checkbody.json @@ -0,0 +1,104 @@ +[ + { + "name": "raw message data is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/raw", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "0965d04dceb3003d88a9ea38f337e97a" + }, + "format": { + "type": "binary" + } + } + }, + { + "name": "top-level body is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/body", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "c182b42fda0cd2e929272dd328f0c45d" + }, + "format": { + "type": "binary" + } + } + }, + { + "name": "part 0 body is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/0/body", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "7883ef0e6c2f3da210febb5ca2b42ace" + }, + "format": { + "type": "binary" + } + } + }, + { + "name": "part 1 body is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1/body", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "effe7461f030f3a58f85e4b736bd5c10" + }, + "format": { + "type": "binary" + } + } + }, + { + "name": "part 1/0 body is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1/multipart/0/body", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "81c8d7e43a1c88daf9031518e8db3136" + }, + "format": { + "type": "binary" + } + } + }, + { + "name": "part 1/1 body is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1/multipart/1/body", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": { + "md5sum": "47ebf0f785a0788262472bf73a4801bb" + }, + "format": { + "type": "binary" + } + } + } +] diff --git a/test/email/checkmetadata.json b/test/email/checkmetadata.json new file mode 100644 index 0000000..b474da4 --- /dev/null +++ b/test/email/checkmetadata.json @@ -0,0 +1,75 @@ +{{ $decodedMetadata := file "expected_metadata.json" | unmarshal }} +[ + { + "name": "top-level index is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ file "expected_index.json" }} + } + }, + { + "name": "top-level metadata is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ marshal $decodedMetadata }} + } + }, + { + "name": "part 0 metadata is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/0", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ index $decodedMetadata "multiparts" 0 | marshal }} + } + }, + { + "name": "part 1 metadata is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ index $decodedMetadata "multiparts" 1 | marshal }} + } + }, + { + "name": "part 1/0 metadata is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1/multipart/0", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ index $decodedMetadata "multiparts" 1 "multiparts" 0 | marshal }} + } + }, + { + "name": "part 1/1 metadata is returned as expected", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/0/multipart/1/multipart/1", + "method": "GET" + }, + "response": { + "statuscode": 200, + "body": {{ index $decodedMetadata "multiparts" 1 "multiparts" 1 | marshal }} + } + } +] diff --git a/test/email/expected_index.json b/test/email/expected_index.json new file mode 100644 index 0000000..5abbb3c --- /dev/null +++ b/test/email/expected_index.json @@ -0,0 +1,23 @@ +{ + "count": 1, + "messages": [ + { + "from": [ + "testsender123@programmfabrik.de" + ], + "idx": 0, + "isMultipart": true, + "receivedAt:control": { + "match": "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]+\\+[0-9]{2}:[0-9]{2}" + }, + "smtpFrom": "testsender123@programmfabrik.de", + "smtpRcptTo": [ + "testreceiver123@programmfabrik.de" + ], + "subject": "Example Nested Message", + "to": [ + "testreceiver123@programmfabrik.de" + ] + } + ] +} diff --git a/test/email/expected_metadata.json b/test/email/expected_metadata.json new file mode 100644 index 0000000..3222036 --- /dev/null +++ b/test/email/expected_metadata.json @@ -0,0 +1,102 @@ +{ + "bodySize": 549, + "contentType": "multipart/alternative", + "contentTypeParams": { + "boundary": "d36c3118be4745f9a1cb4556d11fe92d" + }, + "from": [ + "testsender123@programmfabrik.de" + ], + "headers": { + "Content-Type": [ + "multipart/alternative; boundary=\"d36c3118be4745f9a1cb4556d11fe92d\"" + ], + "Date": [ + "Tue, 25 Jun 2024 11:15:57 +0200" + ], + "From": [ + "testsender123@programmfabrik.de" + ], + "Subject": [ + "Example Nested Message" + ], + "To": [ + "testreceiver123@programmfabrik.de" + ] + }, + "idx": 0, + "isMultipart": true, + "multiparts": [ + { + "bodySize": 57, + "contentType": "text/plain", + "contentTypeParams": { + "charset": "utf-8" + }, + "headers": { + "Content-Type": [ + "text/plain; charset=utf-8" + ] + }, + "idx": 0, + "isMultipart": false + }, + { + "bodySize": 257, + "contentType": "multipart/mixed", + "contentTypeParams": { + "boundary": "710d3e95c17247d4bb35d621f25e094e" + }, + "headers": { + "Content-Type": [ + "multipart/mixed; boundary=\"710d3e95c17247d4bb35d621f25e094e\"" + ] + }, + "idx": 1, + "isMultipart": true, + "multiparts": [ + { + "bodySize": 26, + "contentType": "text/plain", + "contentTypeParams": { + "charset": "ascii" + }, + "headers": { + "Content-Type": [ + "text/plain; charset=ascii" + ] + }, + "idx": 0, + "isMultipart": false + }, + { + "bodySize": 34, + "contentType": "text/html", + "contentTypeParams": { + "charset": "utf-8" + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "idx": 1, + "isMultipart": false + } + ], + "multipartsCount": 2 + } + ], + "multipartsCount": 2, + "receivedAt:control": { + "match": "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]+\\+[0-9]{2}:[0-9]{2}" + }, + "smtpFrom": "testsender123@programmfabrik.de", + "smtpRcptTo": [ + "testreceiver123@programmfabrik.de" + ], + "subject": "Example Nested Message", + "to": [ + "testreceiver123@programmfabrik.de" + ] +} diff --git a/test/email/manifest.json b/test/email/manifest.json new file mode 100644 index 0000000..7ceeef0 --- /dev/null +++ b/test/email/manifest.json @@ -0,0 +1,14 @@ +{ + "http_server": { + "addr": ":9999" + }, + "smtp_server": { + "addr": ":9925" + }, + "name": "testing HTTP endpoints for mock SMTP server", + "tests": [ + "@postmessage.json", + "@checkmetadata.json", + "@checkbody.json" + ] +} diff --git a/test/email/postmessage.json b/test/email/postmessage.json new file mode 100644 index 0000000..466f5d0 --- /dev/null +++ b/test/email/postmessage.json @@ -0,0 +1,13 @@ +{ + "name": "post message", + "request": { + "server_url": "http://localhost:9999", + "endpoint": "smtp/postmessage", + "method": "POST", + "body_type": "file", + "body_file": "testmessage.eml" + }, + "response": { + "statuscode": 200 + } +} diff --git a/test/email/testmessage.eml b/test/email/testmessage.eml new file mode 100644 index 0000000..a2f6f3d --- /dev/null +++ b/test/email/testmessage.eml @@ -0,0 +1,23 @@ +From: testsender123@programmfabrik.de +To: testreceiver123@programmfabrik.de +Date: Tue, 25 Jun 2024 11:15:57 +0200 +Subject: Example Nested Message +Content-type: multipart/alternative; boundary="d36c3118be4745f9a1cb4556d11fe92d" + +--d36c3118be4745f9a1cb4556d11fe92d +Content-Type: text/plain; charset=utf-8 + +Some plain text for clients that don't support multipart. +--d36c3118be4745f9a1cb4556d11fe92d +Content-Type: multipart/mixed; boundary="710d3e95c17247d4bb35d621f25e094e" + +--710d3e95c17247d4bb35d621f25e094e +Content-Type: text/plain; charset=ascii + +This is the first subpart. +--710d3e95c17247d4bb35d621f25e094e +Content-Type: text/html; charset=utf-8 + +This is the second subpart. +--710d3e95c17247d4bb35d621f25e094e-- +--d36c3118be4745f9a1cb4556d11fe92d--