1+ /* eslint-disable @typescript-eslint/naming-convention */
12import { JsonRpcResponseStruct } from '@metamask/utils' ;
23
34import { flushPromises } from '../../../../test/lib/timer-helpers' ;
@@ -20,15 +21,23 @@ const getNetworkConfigurationByNetworkClientId = jest.fn();
2021const createMiddleware = (
2122 args : {
2223 // eslint-disable-next-line @typescript-eslint/naming-convention
23- dappSwapMetricsFlag ?: { enabled : boolean ; bridge_quote_fees : number } ;
24+ dappSwapMetricsFlag ?: {
25+ enabled : boolean ;
26+ bridge_quote_fees : number ;
27+ origins : string [ ] ;
28+ } ;
2429 } = { } ,
2530) => {
2631 const middlewareFunction = createDappSwapMiddleware ( {
2732 fetchQuotes,
2833 setDappSwapComparisonData,
2934 getNetworkConfigurationByNetworkClientId,
3035 // eslint-disable-next-line @typescript-eslint/naming-convention
31- dappSwapMetricsFlag : { enabled : true , bridge_quote_fees : 250 } ,
36+ dappSwapMetricsFlag : {
37+ enabled : true ,
38+ bridge_quote_fees : 250 ,
39+ origins : [ 'https://metamask.github.io' ] ,
40+ } ,
3241 ...args ,
3342 } ) ;
3443 return { middlewareFunction } ;
@@ -60,7 +69,11 @@ describe('DappSwapMiddleware', () => {
6069 fetchQuotes . mockReturnValueOnce ( mockBridgeQuotes ) ;
6170 const { middlewareFunction } = createMiddleware ( {
6271 // eslint-disable-next-line @typescript-eslint/naming-convention
63- dappSwapMetricsFlag : { enabled : false , bridge_quote_fees : 250 } ,
72+ dappSwapMetricsFlag : {
73+ enabled : false ,
74+ bridge_quote_fees : 250 ,
75+ origins : [ 'https://metamask.github.io' ] ,
76+ } ,
6477 } ) ;
6578
6679 const req = {
@@ -221,4 +234,44 @@ describe('DappSwapMiddleware', () => {
221234 'Error fetching bridge quotes: Error: Error getting data from swap: invalid batch transaction, invalid command' ,
222235 } ) ;
223236 } ) ;
237+
238+ it ( 'does not fetch quotes if origin is not in the list of allowed origins' , async ( ) => {
239+ fetchQuotes . mockReturnValueOnce ( mockBridgeQuotes ) ;
240+ const { middlewareFunction } = createMiddleware ( {
241+ // eslint-disable-next-line @typescript-eslint/naming-convention
242+ dappSwapMetricsFlag : {
243+ enabled : true ,
244+ bridge_quote_fees : 250 ,
245+ origins : [ 'https://metamask.github.io' ] ,
246+ } ,
247+ } ) ;
248+
249+ const req = {
250+ ...REQUEST_MOCK ,
251+ method : 'eth_sendTransaction' ,
252+ origin : 'https://test.com' ,
253+ securityAlertResponse : {
254+ securityAlertId : '123' ,
255+ } ,
256+ params : [
257+ {
258+ data : '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000068f0dd1b0000000000000000000000000000000000000000000000000000000000000003100604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003070b0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000007ffc3dbf3b2b50ff3a1d5523bc24bb5043837b1400000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000178239802520a9c99dcbd791f81326b70298d62900000000000000000000000000000000000000000000000000000000000601470c' ,
259+ from : '0x12312312312312' ,
260+ chainId : '1' ,
261+ calls : [ ] ,
262+ } ,
263+ ] ,
264+ networkClientId : 'networkClientId' ,
265+ } ;
266+
267+ await middlewareFunction (
268+ req as unknown as DappSwapMiddlewareRequest < ( string | { to : string } ) [ ] > ,
269+ { ...JsonRpcResponseStruct . TYPE } ,
270+ ( ) => undefined ,
271+ ) ;
272+
273+ await flushPromises ( ) ;
274+
275+ expect ( fetchQuotes ) . not . toHaveBeenCalled ( ) ;
276+ } ) ;
224277} ) ;
0 commit comments