Skip to content

Commit 1603e11

Browse files
fix(e2e): allow fixture server state requests
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 182e73d commit 1603e11

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/api-mocking/MockServerE2E.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import PortManager, { ResourceType } from '../framework/PortManager.ts';
2121
import {
2222
FALLBACK_GANACHE_PORT,
2323
FALLBACK_DAPP_SERVER_PORT,
24+
FALLBACK_FIXTURE_SERVER_PORT,
2425
} from '../framework/Constants.ts';
2526
import { DEFAULT_ANVIL_PORT } from '../seeder/anvil-manager.ts';
2627
import { logLiveMetaMetricsPostIfDebug } from '../helpers/analytics/analyticsDebug.ts';
@@ -124,6 +125,8 @@ const translateFallbackPortToActual = (url: string): string => {
124125
if (actualPort === undefined) {
125126
actualPort = portManager.getPort(ResourceType.ANVIL);
126127
}
128+
} else if (portNum === FALLBACK_FIXTURE_SERVER_PORT) {
129+
actualPort = portManager.getPort(ResourceType.FIXTURE_SERVER);
127130
} else if (portNum === DEFAULT_ANVIL_PORT) {
128131
actualPort = portManager.getPort(ResourceType.ANVIL);
129132
} else if (
@@ -152,12 +155,33 @@ const translateFallbackPortToActual = (url: string): string => {
152155
}
153156
};
154157

158+
const isFixtureServerStateUrl = (url: string): boolean => {
159+
try {
160+
const parsedUrl = new URL(url);
161+
const port = parseInt(parsedUrl.port, 10);
162+
const fixtureServerPort = PortManager.getInstance().getPort(
163+
ResourceType.FIXTURE_SERVER,
164+
);
165+
166+
return (
167+
parsedUrl.pathname === '/state.json' &&
168+
(port === FALLBACK_FIXTURE_SERVER_PORT || port === fixtureServerPort)
169+
);
170+
} catch {
171+
return false;
172+
}
173+
};
174+
155175
const isUrlAllowed = (url: string): boolean => {
156176
try {
157177
if (ALLOWLISTED_URLS.includes(url)) {
158178
return true;
159179
}
160180

181+
if (isFixtureServerStateUrl(url)) {
182+
return true;
183+
}
184+
161185
// Malformed npm: package URIs that leak through the snap proxy
162186
// e.g. https://https//npm:@metamask/... or npm:@metamask/...
163187
if (/^(?:https?:\/\/.*)?npm[:@]@?metamask\//.test(url)) {

0 commit comments

Comments
 (0)