|
1 |
| -import { isLocalOrReservedIP } from '@/helpers/socksProxy/socksProxy'; |
| 1 | +import { isExtConnCheck, isLocalOrReservedIP } from '@/helpers/socksProxy/socksProxy'; |
| 2 | +import { RequestDetails } from './socksProxy.types'; |
2 | 3 |
|
3 | 4 | describe('isLocalOrReservedIP', () => {
|
4 | 5 | it('should return true for localhost', () => {
|
@@ -34,3 +35,87 @@ describe('isLocalOrReservedIP', () => {
|
34 | 35 | expect(isLocalOrReservedIP('')).toBeFalsy();
|
35 | 36 | });
|
36 | 37 | });
|
| 38 | + |
| 39 | +describe('isExtConnCheck', () => { |
| 40 | + const baseDetails: RequestDetails = { |
| 41 | + requestId: '5979', |
| 42 | + url: '', |
| 43 | + method: 'GET', |
| 44 | + type: 'xmlhttprequest', |
| 45 | + fromCache: false, |
| 46 | + incognito: false, |
| 47 | + thirdParty: false, |
| 48 | + originUrl: '', |
| 49 | + documentUrl: '', |
| 50 | + frameId: 0, |
| 51 | + parentFrameId: -1, |
| 52 | + frameAncestors: [], |
| 53 | + timeStamp: 1740215207080, |
| 54 | + tabId: 4, |
| 55 | + cookieStoreId: 'firefox-default', |
| 56 | + urlClassification: { |
| 57 | + firstParty: [], |
| 58 | + thirdParty: [], |
| 59 | + }, |
| 60 | + }; |
| 61 | + |
| 62 | + it('should return true for extension IPv4 connection check', () => { |
| 63 | + const details: RequestDetails = { |
| 64 | + ...baseDetails, |
| 65 | + url: 'https://ipv4.am.i.mullvad.net/json', |
| 66 | + originUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 67 | + documentUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 68 | + }; |
| 69 | + expect(isExtConnCheck(details)).toBeTruthy(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should return true for extension IPv6 connection check', () => { |
| 73 | + const details: RequestDetails = { |
| 74 | + ...baseDetails, |
| 75 | + url: 'https://ipv6.am.i.mullvad.net/json', |
| 76 | + originUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 77 | + documentUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 78 | + }; |
| 79 | + expect(isExtConnCheck(details)).toBeTruthy(); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should return true for extension DNS check', () => { |
| 83 | + const details: RequestDetails = { |
| 84 | + ...baseDetails, |
| 85 | + url: 'https://c30d3da2-fc4f-4732-86cc-f233e1692eac.dnsleak.am.i.mullvad.net/', |
| 86 | + originUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 87 | + documentUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 88 | + }; |
| 89 | + expect(isExtConnCheck(details)).toBeTruthy(); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should return false for DNS check with the wrong base domain', () => { |
| 93 | + const details: RequestDetails = { |
| 94 | + ...baseDetails, |
| 95 | + url: 'https://example.com#am.i.mullvad.net/', |
| 96 | + originUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 97 | + documentUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 98 | + }; |
| 99 | + expect(isExtConnCheck(details)).toBeFalsy(); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should return false for non-extension requests', () => { |
| 103 | + const details: RequestDetails = { |
| 104 | + ...baseDetails, |
| 105 | + url: 'https://ipv4.am.i.mullvad.net/json', |
| 106 | + documentUrl: 'https://example.com', |
| 107 | + originUrl: 'https://example.com', |
| 108 | + }; |
| 109 | + expect(isExtConnCheck(details)).toBeFalsy(); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should return false for extension requests to other URLs', () => { |
| 113 | + const details: RequestDetails = { |
| 114 | + ...baseDetails, |
| 115 | + url: 'https://example.com', |
| 116 | + originUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 117 | + documentUrl: 'moz-extension://8ad8e256-a9a0-4017-b302-1345ac426553/dist/options/index.html', |
| 118 | + }; |
| 119 | + expect(isExtConnCheck(details)).toBeFalsy(); |
| 120 | + }); |
| 121 | +}); |
0 commit comments