@@ -72,6 +72,78 @@ class APIGatewayV2Tests: XCTestCase {
7272 }
7373 """
7474
75+ static let fullExamplePayload = """
76+ {
77+ " version " : " 2.0 " ,
78+ " routeKey " : " $default " ,
79+ " rawPath " : " /my/path " ,
80+ " rawQueryString " : " parameter1=value1¶meter1=value2¶meter2=value " ,
81+ " cookies " : [
82+ " cookie1 " ,
83+ " cookie2 "
84+ ],
85+ " headers " : {
86+ " header1 " : " value1 " ,
87+ " header2 " : " value1,value2 "
88+ },
89+ " queryStringParameters " : {
90+ " parameter1 " : " value1,value2 " ,
91+ " parameter2 " : " value "
92+ },
93+ " requestContext " : {
94+ " accountId " : " 123456789012 " ,
95+ " apiId " : " api-id " ,
96+ " authentication " : {
97+ " clientCert " : {
98+ " clientCertPem " : " CERT_CONTENT " ,
99+ " subjectDN " : " www.example.com " ,
100+ " issuerDN " : " Example issuer " ,
101+ " serialNumber " : " a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1 " ,
102+ " validity " : {
103+ " notBefore " : " May 28 12:30:02 2019 GMT " ,
104+ " notAfter " : " Aug 5 09:36:04 2021 GMT "
105+ }
106+ }
107+ },
108+ " authorizer " : {
109+ " jwt " : {
110+ " claims " : {
111+ " claim1 " : " value1 " ,
112+ " claim2 " : " value2 "
113+ },
114+ " scopes " : [
115+ " scope1 " ,
116+ " scope2 "
117+ ]
118+ }
119+ },
120+ " domainName " : " id.execute-api.us-east-1.amazonaws.com " ,
121+ " domainPrefix " : " id " ,
122+ " http " : {
123+ " method " : " POST " ,
124+ " path " : " /my/path " ,
125+ " protocol " : " HTTP/1.1 " ,
126+ " sourceIp " : " 192.0.2.1 " ,
127+ " userAgent " : " agent "
128+ },
129+ " requestId " : " id " ,
130+ " routeKey " : " $default " ,
131+ " stage " : " $default " ,
132+ " time " : " 12/Mar/2020:19:03:58 +0000 " ,
133+ " timeEpoch " : 1583348638390
134+ },
135+ " body " : " Hello from Lambda " ,
136+ " pathParameters " : {
137+ " parameter1 " : " value1 "
138+ },
139+ " isBase64Encoded " : false,
140+ " stageVariables " : {
141+ " stageVariable1 " : " value1 " ,
142+ " stageVariable2 " : " value2 "
143+ }
144+ }
145+ """
146+
75147 // MARK: - Request -
76148
77149 // MARK: Decoding
@@ -90,4 +162,17 @@ class APIGatewayV2Tests: XCTestCase {
90162
91163 XCTAssertNil ( req? . body)
92164 }
165+
166+ func testDecodingRequestClientCert( ) throws {
167+ let data = APIGatewayV2Tests . fullExamplePayload. data ( using: . utf8) !
168+ let request = try JSONDecoder ( ) . decode ( APIGatewayV2Request . self, from: data)
169+ let clientCert = request. context. authentication? . clientCert
170+
171+ XCTAssertEqual ( clientCert? . clientCertPem, " CERT_CONTENT " )
172+ XCTAssertEqual ( clientCert? . subjectDN, " www.example.com " )
173+ XCTAssertEqual ( clientCert? . issuerDN, " Example issuer " )
174+ XCTAssertEqual ( clientCert? . serialNumber, " a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1 " )
175+ XCTAssertEqual ( clientCert? . validity. notBefore, " May 28 12:30:02 2019 GMT " )
176+ XCTAssertEqual ( clientCert? . validity. notAfter, " Aug 5 09:36:04 2021 GMT " )
177+ }
93178}
0 commit comments