(expectation, toSanitize)
| 213 | }; |
| 214 | |
| 215 | const transformRecordedData = (expectation, toSanitize) => { |
| 216 | const requestBodySanitizer = httpRequest => { |
| 217 | let body; |
| 218 | if (httpRequest.body && httpRequest.body.type === 'JSON' && httpRequest.body.json) { |
| 219 | const bodyObject = |
| 220 | typeof httpRequest.body.json === 'string' |
| 221 | ? JSON.parse(httpRequest.body.json) |
| 222 | : httpRequest.body.json; |
| 223 | |
| 224 | if (bodyObject.encoding === 'base64') { |
| 225 | // sanitize encoded data |
| 226 | const decodedBody = Buffer.from(bodyObject.content, 'base64').toString('binary'); |
| 227 | const sanitizedContent = sanitizeString(decodedBody, toSanitize); |
| 228 | const sanitizedEncodedContent = Buffer.from(sanitizedContent, 'binary').toString('base64'); |
| 229 | bodyObject.content = sanitizedEncodedContent; |
| 230 | body = JSON.stringify(bodyObject); |
| 231 | } else { |
| 232 | body = JSON.stringify(bodyObject); |
| 233 | } |
| 234 | } else if (httpRequest.body && httpRequest.body.type === 'STRING' && httpRequest.body.string) { |
| 235 | body = sanitizeString(httpRequest.body.string, toSanitize); |
| 236 | } else if (httpRequest.body) { |
| 237 | const str = |
| 238 | typeof httpRequest.body !== 'string' ? JSON.stringify(httpRequest.body) : httpRequest.body; |
| 239 | body = sanitizeString(str, toSanitize); |
| 240 | } |
| 241 | return body; |
| 242 | }; |
| 243 | |
| 244 | const responseBodySanitizer = (httpRequest, httpResponse) => { |
| 245 | let responseBody = null; |
| 246 | if (httpResponse.body && httpResponse.body.string) { |
| 247 | responseBody = httpResponse.body.string; |
| 248 | } else if ( |
| 249 | httpResponse.body && |
| 250 | httpResponse.body.type === 'BINARY' && |
| 251 | httpResponse.body.base64Bytes |
| 252 | ) { |
| 253 | responseBody = { |
| 254 | encoding: 'base64', |
| 255 | content: httpResponse.body.base64Bytes, |
| 256 | }; |
| 257 | } else if (httpResponse.body && httpResponse.body.json) { |
| 258 | responseBody = JSON.stringify(httpResponse.body.json); |
| 259 | } else { |
| 260 | responseBody = |
| 261 | typeof httpResponse.body === 'string' |
| 262 | ? httpResponse.body |
| 263 | : httpResponse.body && JSON.stringify(httpResponse.body); |
| 264 | } |
| 265 | |
| 266 | // replace recorded user with fake one |
| 267 | if ( |
| 268 | responseBody && |
| 269 | httpRequest.path === '/api/v4/user' && |
| 270 | httpRequest.headers.Host.includes('gitlab.com') |
| 271 | ) { |
| 272 | responseBody = JSON.stringify(FAKE_OWNER_USER); |
no outgoing calls
no test coverage detected