|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftAWSLambdaRuntime open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +@testable import AWSLambdaEvents |
| 16 | +import XCTest |
| 17 | + |
| 18 | +class SESTests: XCTestCase { |
| 19 | + static let eventBody = """ |
| 20 | + { |
| 21 | + "Records": [ |
| 22 | + { |
| 23 | + "eventSource": "aws:ses", |
| 24 | + "eventVersion": "1.0", |
| 25 | + "ses": { |
| 26 | + "mail": { |
| 27 | + "commonHeaders": { |
| 28 | + "date": "Wed, 7 Oct 2015 12:34:56 -0700", |
| 29 | + "from": [ |
| 30 | + |
| 31 | + ], |
| 32 | + "messageId": "<0123456789example.com>", |
| 33 | + "returnPath": "[email protected]", |
| 34 | + "subject": "Test Subject", |
| 35 | + "to": [ |
| 36 | + |
| 37 | + ] |
| 38 | + }, |
| 39 | + "destination": [ |
| 40 | + |
| 41 | + ], |
| 42 | + "headers": [ |
| 43 | + { |
| 44 | + "name": "Return-Path", |
| 45 | + |
| 46 | + }, |
| 47 | + { |
| 48 | + "name": "Received", |
| 49 | + "value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.eu-west-1.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for [email protected]; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)" |
| 50 | + } |
| 51 | + ], |
| 52 | + "headersTruncated": true, |
| 53 | + "messageId": "5h5auqp1oa1bg49b2q8f8tmli1oju8pcma2haao1", |
| 54 | + |
| 55 | + "timestamp": "1970-01-01T00:00:00.000Z" |
| 56 | + }, |
| 57 | + "receipt": { |
| 58 | + "action": { |
| 59 | + "functionArn": "arn:aws:lambda:eu-west-1:123456789012:function:Example", |
| 60 | + "invocationType": "Event", |
| 61 | + "type": "Lambda" |
| 62 | + }, |
| 63 | + "dkimVerdict": { |
| 64 | + "status": "PASS" |
| 65 | + }, |
| 66 | + "processingTimeMillis": 574, |
| 67 | + "recipients": [ |
| 68 | + |
| 69 | + |
| 70 | + ], |
| 71 | + "spamVerdict": { |
| 72 | + "status": "PASS" |
| 73 | + }, |
| 74 | + "spfVerdict": { |
| 75 | + "status": "PROCESSING_FAILED" |
| 76 | + }, |
| 77 | + "timestamp": "1970-01-01T00:00:00.000Z", |
| 78 | + "virusVerdict": { |
| 79 | + "status": "FAIL" |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + ] |
| 85 | + } |
| 86 | + """ |
| 87 | + |
| 88 | + func testSimpleEventFromJSON() { |
| 89 | + let data = Data(SESTests.eventBody.utf8) |
| 90 | + var event: SES.Event? |
| 91 | + XCTAssertNoThrow(event = try JSONDecoder().decode(SES.Event.self, from: data)) |
| 92 | + |
| 93 | + guard let record = event?.records.first else { |
| 94 | + XCTFail("Expected to have one record") |
| 95 | + return |
| 96 | + } |
| 97 | + |
| 98 | + XCTAssertEqual(record.eventSource, "aws:ses") |
| 99 | + XCTAssertEqual(record.eventVersion, "1.0") |
| 100 | + XCTAssertEqual(record.ses.mail.commonHeaders.date.description, "2015-10-07 19:34:56 +0000") |
| 101 | + XCTAssertEqual(record .ses .mail .commonHeaders .from[0], "Jane Doe <[email protected]>") |
| 102 | + XCTAssertEqual(record.ses.mail.commonHeaders.messageId, "<0123456789example.com>") |
| 103 | + XCTAssertEqual(record .ses .mail .commonHeaders .returnPath , "[email protected]") |
| 104 | + XCTAssertEqual(record.ses.mail.commonHeaders.subject, "Test Subject") |
| 105 | + XCTAssertEqual(record .ses .mail .commonHeaders .to?[0], "[email protected]") |
| 106 | + XCTAssertEqual(record .ses .mail .destination[0], "[email protected]") |
| 107 | + XCTAssertEqual(record.ses.mail.headers[0].name, "Return-Path") |
| 108 | + XCTAssertEqual(record .ses .mail .headers[0].value , "<[email protected]>") |
| 109 | + XCTAssertEqual(record.ses.mail.headers[1].name, "Received") |
| 110 | + XCTAssertEqual(record .ses .mail .headers[1].value , "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.eu-west-1.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for [email protected]; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)") |
| 111 | + XCTAssertEqual(record.ses.mail.headersTruncated, true) |
| 112 | + XCTAssertEqual(record.ses.mail.messageId, "5h5auqp1oa1bg49b2q8f8tmli1oju8pcma2haao1") |
| 113 | + XCTAssertEqual(record .ses .mail .source , "[email protected]") |
| 114 | + XCTAssertEqual(record.ses.mail.timestamp.description, "1970-01-01 00:00:00 +0000") |
| 115 | + |
| 116 | + XCTAssertEqual(record.ses.receipt.action.functionArn, "arn:aws:lambda:eu-west-1:123456789012:function:Example") |
| 117 | + XCTAssertEqual(record.ses.receipt.action.invocationType, "Event") |
| 118 | + XCTAssertEqual(record.ses.receipt.action.type, "Lambda") |
| 119 | + XCTAssertEqual(record.ses.receipt.dkimVerdict.status, .pass) |
| 120 | + XCTAssertEqual(record.ses.receipt.processingTimeMillis, 574) |
| 121 | + XCTAssertEqual(record .ses .receipt .recipients[0], "[email protected]") |
| 122 | + XCTAssertEqual(record .ses .receipt .recipients[1], "[email protected]") |
| 123 | + XCTAssertEqual(record.ses.receipt.spamVerdict.status, .pass) |
| 124 | + XCTAssertEqual(record.ses.receipt.spfVerdict.status, .processingFailed) |
| 125 | + XCTAssertEqual(record.ses.receipt.timestamp.description, "1970-01-01 00:00:00 +0000") |
| 126 | + XCTAssertEqual(record.ses.receipt.virusVerdict.status, .fail) |
| 127 | + } |
| 128 | +} |
0 commit comments