MCPcopy
hub / github.com/snyk/cli / fakeServer

Function fakeServer

test/acceptance/fake-server.ts:112–1892  ·  view source on GitHub ↗
(basePath: string, snykToken: string)

Source from the content-addressed store, hash-verified

110}
111
112export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
113 let requests: express.Request[] = [];
114 let featureFlags: Map<string, boolean> = featureFlagDefaults();
115 let availableSettings: Map<string, boolean> = new Map();
116 let localCodeEngineConfiguration: Record<string, unknown> = {
117 enabled: false,
118 };
119 let unauthorizedActions = new Map();
120 // the status code to return for the next request, overriding statusCode
121 let nextStatusCode: number | undefined = undefined;
122 // the status code to return for all the requests
123 let statusCode: number | undefined = undefined;
124 let nextResponse: any = undefined;
125 let endpointConfigs: Map<string, EndpointConfig> = new Map();
126 let customResponse: Record<string, unknown> | undefined = undefined;
127 let sarifResponse: Record<string, unknown> | undefined = undefined;
128 let redteamNextCallCount: Record<string, number> = {};
129 let server: http.Server | undefined = undefined;
130 let responseDelayMs = 0;
131 const sockets = new Set();
132
133 const getOrCreateEndpointConfig = (endpoint: string): EndpointConfig => {
134 let config = endpointConfigs.get(endpoint);
135 if (!config) {
136 config = {
137 responses: [],
138 statusCodes: [],
139 headers: {},
140 responseIndex: 0,
141 statusCodeIndex: 0,
142 isResponseArray: false,
143 isStatusCodeArray: false,
144 };
145 endpointConfigs.set(endpoint, config);
146 }
147 return config;
148 };
149
150 const restore = () => {
151 statusCode = undefined;
152 requests = [];
153 customResponse = undefined;
154 sarifResponse = undefined;
155 endpointConfigs = new Map();
156 featureFlags = featureFlagDefaults();
157 availableSettings = new Map();
158 unauthorizedActions = new Map();
159 redteamNextCallCount = {};
160 responseDelayMs = 0;
161 };
162
163 const getRequests = () => {
164 return requests;
165 };
166
167 const popRequest = () => {
168 const request = requests?.pop();
169 if (request) return request;

Calls 5

getFixturePathFunction · 0.90
featureFlagDefaultsFunction · 0.85
handleSpecificResponsesFunction · 0.85
addDependenciesFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected