@@ -6,13 +6,8 @@ import { HandlersDefinition } from '../all-apis-mock';
66import { HttpClientErr , Status } from '../lib/api' ;
77import { messageIdRegex , parseAuthority , parsePort } from '../lib/mock-util' ;
88import { MockJwt } from '../lib/oauth' ;
9- import {
10- FesConfig ,
11- MessageCreateBody ,
12- validateMessageCreateBody ,
13- createMockBodyForValidator ,
14- generateEmailToExternalIdAndUrl ,
15- } from './shared-tenant-fes-endpoints' ;
9+ import { FesConfig , MessageCreateBody , createCombinedBodyForValidator } from './shared-tenant-fes-endpoints' ;
10+ import { getStoredS3Content } from '../s3/s3-endpoints' ;
1611
1712const standardFesUrl = ( port : string ) => {
1813 return `fes.standardsubdomainfes.localhost:${ port } ` ;
@@ -75,95 +70,87 @@ export const getMockCustomerUrlFesEndpoints = (config: FesConfig | undefined): H
7570 const port = parsePort ( req ) ;
7671 if ( parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
7772 authenticate ( req , isCustomIDPUsed ) ;
73+ const storageFileName = 'mock-storage-file-name-' + Date . now ( ) ;
7874 return {
79- storageFileName : 'mock-storage-file-name-' + Date . now ( ) ,
75+ storageFileName,
8076 replyToken : 'mock-fes-reply-token' ,
81- uploadUrl : `https://localhost:${ port } /mock-s3-upload` ,
77+ uploadUrl : `https://localhost:${ port } /mock-s3-upload/ ${ storageFileName } ` ,
8278 } ;
8379 }
8480 throw new HttpClientErr ( 'Not Found' , 404 ) ;
8581 } ,
8682 '/api/v1/messages' : async ( { body } , req ) => {
8783 const port = parsePort ( req ) ;
8884 const fesUrl = standardFesUrl ( port ) ;
89- const baseUrl = `https://${ fesUrl } ` ;
9085 // New endpoint that receives storageFileName instead of encrypted content
9186 if ( parseAuthority ( req ) === fesUrl && req . method === 'POST' && typeof body === 'object' ) {
9287 authenticate ( req , isCustomIDPUsed ) ;
9388 const bodyObj = body as MessageCreateBody ;
94- validateMessageCreateBody ( bodyObj ) ;
95- // Use the validator if provided
89+ // Retrieve the PGP content uploaded to S3 and combine with metadata for validation
90+ const s3Content = getStoredS3Content ( bodyObj . storageFileName ) ;
91+ const combinedBody = createCombinedBodyForValidator ( s3Content , bodyObj ) ;
9692 if ( config ?. messagePostValidator ) {
97- return await config . messagePostValidator ( createMockBodyForValidator ( bodyObj ) , fesUrl ) ;
98- }
99- return {
100- url : `${ baseUrl } /message/mock-external-id` ,
101- externalId : 'FES-MOCK-EXTERNAL-ID' ,
102- emailToExternalIdAndUrl : generateEmailToExternalIdAndUrl ( bodyObj , baseUrl ) ,
103- } ;
104- }
105- throw new HttpClientErr ( 'Not Found' , 404 ) ;
106- } ,
107- '/api/v1/message' : async ( { body } , req ) => {
108- const port = parsePort ( req ) ;
109- const fesUrl = standardFesUrl ( port ) ;
110- // Legacy endpoint - body is a mime-multipart string, we're doing a few smoke checks here without parsing it
111- if ( parseAuthority ( req ) === fesUrl && req . method === 'POST' && typeof body === 'string' ) {
112- authenticate ( req , isCustomIDPUsed ) ;
113- if ( config ?. messagePostValidator ) {
114- return await config . messagePostValidator ( body , fesUrl ) ;
93+ return await config . messagePostValidator ( combinedBody , fesUrl ) ;
11594 }
11695 throw new HttpClientErr ( 'Not Allowed' , 405 ) ;
11796 }
11897 throw new HttpClientErr ( 'Not Found' , 404 ) ;
11998 } ,
120- '/api/v1/message/FES-MOCK-EXTERNAL-ID/gateway' : async ( { body } , req ) => {
99+ // Wildcard handler for /api/v1/messages/* sub-paths (gateway endpoints for new flow)
100+ // test: `compose - user@standardsubdomainfes.localhost - PWD encrypted message with FES web portal`
101+ // test: `compose - user2@standardsubdomainfes.localhost - PWD encrypted message with FES - Reply rendering`
102+ // test: `compose - user3@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - pubkey recipient in bcc`
103+ // test: `compose - user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - some sends fail with BadRequest error`
104+ // test: `user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - a send fails with gateway update error`
105+ '/api/v1/messages/?' : async ( { body } , req ) => {
121106 const port = parsePort ( req ) ;
122- if ( parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
123- // test: `compose - user@standardsubdomainfes.localhost - PWD encrypted message with FES web portal`
124- authenticate ( req , isCustomIDPUsed ) ;
125- expect ( body ) . to . match ( messageIdRegex ( port ) ) ;
126- return { } ;
127- }
128- throw new HttpClientErr ( 'Not Found' , 404 ) ;
129- } ,
130- '/api/v1/message/FES-MOCK-EXTERNAL-FOR-SENDER@DOMAIN.COM-ID/gateway' : async ( { body } , req ) => {
131- const port = parsePort ( req ) ;
132- if ( parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
133- // test: `compose - user2@standardsubdomainfes.localhost - PWD encrypted message with FES - Reply rendering`
107+ const gatewayMatch = / \/ a p i \/ v 1 \/ m e s s a g e s \/ ( [ ^ / ] + ) \/ g a t e w a y / . exec ( req . url ) ;
108+ if ( gatewayMatch && parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
109+ const externalId = gatewayMatch [ 1 ] ;
110+ if ( externalId === 'FES-MOCK-EXTERNAL-FOR-GATEWAYFAILURE@EXAMPLE.COM-ID' ) {
111+ throw new HttpClientErr ( `Test error` , Status . BAD_REQUEST ) ;
112+ }
134113 authenticate ( req , isCustomIDPUsed ) ;
135- expect ( body ) . to . match ( messageIdRegex ( port ) ) ;
114+ const bodyStr = typeof body === 'string' ? body : JSON . stringify ( body ) ;
115+ expect ( bodyStr ) . to . match ( messageIdRegex ( port ) ) ;
136116 return { } ;
137117 }
138118 throw new HttpClientErr ( 'Not Found' , 404 ) ;
139119 } ,
140- '/api/v1/message/FES-MOCK-EXTERNAL-FOR-TO@EXAMPLE.COM-ID/gateway' : async ( { body } , req ) => {
120+ // Legacy endpoint - body is a mime-multipart string
121+ '/api/v1/message' : async ( { body } , req ) => {
141122 const port = parsePort ( req ) ;
142- if ( parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
143- // test: `compose - user@standardsubdomainfes.localhost - PWD encrypted message with FES web portal`
144- // test: `compose - user2@standardsubdomainfes.localhost - PWD encrypted message with FES - Reply rendering`
145- // test: `compose - user3@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - pubkey recipient in bcc`
146- // test: `compose - user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - some sends fail with BadRequest error`
123+ const fesUrl = standardFesUrl ( port ) ;
124+ // body is a mime-multipart string, we're doing a few smoke checks here without parsing it
125+ if ( parseAuthority ( req ) === fesUrl && req . method === 'POST' && typeof body === 'string' ) {
147126 authenticate ( req , isCustomIDPUsed ) ;
148- expect ( body ) . to . match ( messageIdRegex ( port ) ) ;
149- return { } ;
127+ if ( config ?. messagePostValidator ) {
128+ return await config . messagePostValidator ( body , fesUrl ) ;
129+ }
130+ throw new HttpClientErr ( 'Not Allowed' , 405 ) ;
150131 }
151132 throw new HttpClientErr ( 'Not Found' , 404 ) ;
152133 } ,
153- '/api/v1/message/FES-MOCK-EXTERNAL-FOR-BCC@EXAMPLE.COM-ID/gateway' : async ( { body } , req ) => {
134+ // Legacy wildcard handler for /api/v1/message/* sub-paths (gateway endpoints)
135+ // test: `compose - user@standardsubdomainfes.localhost - PWD encrypted message with FES web portal`
136+ // test: `compose - user2@standardsubdomainfes.localhost - PWD encrypted message with FES - Reply rendering`
137+ // test: `compose - user3@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - pubkey recipient in bcc`
138+ // test: `compose - user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - some sends fail with BadRequest error`
139+ // test: `user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - a send fails with gateway update error`
140+ '/api/v1/message/?' : async ( { body } , req ) => {
154141 const port = parsePort ( req ) ;
155- if ( parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
156- // test: `compose - user@standardsubdomainfes.localhost - PWD encrypted message with FES web portal`
142+ const gatewayMatch = / \/ a p i \/ v 1 \/ m e s s a g e \/ ( [ ^ / ] + ) \/ g a t e w a y / . exec ( req . url ) ;
143+ if ( gatewayMatch && parseAuthority ( req ) === standardFesUrl ( port ) && req . method === 'POST' ) {
144+ const externalId = gatewayMatch [ 1 ] ;
145+ if ( externalId === 'FES-MOCK-EXTERNAL-FOR-GATEWAYFAILURE@EXAMPLE.COM-ID' ) {
146+ throw new HttpClientErr ( `Test error` , Status . BAD_REQUEST ) ;
147+ }
157148 authenticate ( req , isCustomIDPUsed ) ;
158149 expect ( body ) . to . match ( messageIdRegex ( port ) ) ;
159150 return { } ;
160151 }
161152 throw new HttpClientErr ( 'Not Found' , 404 ) ;
162153 } ,
163- '/api/v1/message/FES-MOCK-EXTERNAL-FOR-GATEWAYFAILURE@EXAMPLE.COM-ID/gateway' : async ( ) => {
164- // test: `user4@standardsubdomainfes.localhost - PWD encrypted message with FES web portal - a send fails with gateway update error`
165- throw new HttpClientErr ( `Test error` , Status . BAD_REQUEST ) ;
166- } ,
167154 } ;
168155} ;
169156
0 commit comments