Skip to content

Commit 82d5805

Browse files
committed
Add test for isExtConnCheck
1 parent 2d9ba00 commit 82d5805

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

src/helpers/socksProxy/socksProxy.test.ts

+86-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { isLocalOrReservedIP } from '@/helpers/socksProxy/socksProxy';
1+
import { isExtConnCheck, isLocalOrReservedIP } from '@/helpers/socksProxy/socksProxy';
2+
import { RequestDetails } from './socksProxy.types';
23

34
describe('isLocalOrReservedIP', () => {
45
it('should return true for localhost', () => {
@@ -34,3 +35,87 @@ describe('isLocalOrReservedIP', () => {
3435
expect(isLocalOrReservedIP('')).toBeFalsy();
3536
});
3637
});
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+
});

src/helpers/socksProxy/socksProxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const getCurrentHost = (details: RequestDetails) => {
131131
return new URL(details.url).hostname;
132132
};
133133

134-
const isExtConnCheck = (details: RequestDetails): boolean => {
134+
export const isExtConnCheck = (details: RequestDetails): boolean => {
135135
const isExtensionRequest = Boolean(details.documentUrl?.startsWith('moz-extension://'));
136136
const isConnCheck =
137137
details.url === 'https://ipv4.am.i.mullvad.net/json' ||

0 commit comments

Comments
 (0)