( app: Application, method: string, path: string, spec: DriverMethodDef<Driver>, driver: Core<any>, isSessCmd: boolean, )
| 85 | } |
| 86 | |
| 87 | function buildHandler( |
| 88 | app: Application, |
| 89 | method: string, |
| 90 | path: string, |
| 91 | spec: DriverMethodDef<Driver>, |
| 92 | driver: Core<any>, |
| 93 | isSessCmd: boolean, |
| 94 | ): void { |
| 95 | const asyncHandler = async (req: Request, res: Response, abandonIfDisconnected?: () => boolean) => { |
| 96 | let httpResBody = {} as any; |
| 97 | let httpStatus = 200; |
| 98 | let newSessionId: string | undefined; |
| 99 | const sessionId = getSessionId(driver, req); |
| 100 | |
| 101 | try { |
| 102 | logDeprecationWarning(driver, method, path, spec, sessionId); |
| 103 | ensureSessionExists(driver, sessionId, isSessCmd); |
| 104 | const jsonParseError = jsonParseErrors.getInvalidArgument(req); |
| 105 | if (jsonParseError) { |
| 106 | throw jsonParseError; |
| 107 | } |
| 108 | assertPostBodyIsJsonObject(req, spec); |
| 109 | |
| 110 | const proxyOutcome = await tryWdProxy(driver, req, res, spec, isSessCmd, sessionId); |
| 111 | if (proxyOutcome === 'handled') { |
| 112 | return; |
| 113 | } |
| 114 | const didPluginOverrideProxy = proxyOutcome === 'plugin-override'; |
| 115 | |
| 116 | // if a command is not in our method map, it's because we |
| 117 | // have no plans to ever implement it |
| 118 | if (!spec.command) { |
| 119 | throw new errors.NotImplementedError(); |
| 120 | } |
| 121 | const command = spec.command; |
| 122 | |
| 123 | // Direct proxying delegates payload and command validation to the remote end. |
| 124 | // A plugin intercepting that same proxy path must preserve this ownership. |
| 125 | const jsonObj = preparePayload(spec, req.body, { |
| 126 | validatePayloadParams: !didPluginOverrideProxy, |
| 127 | }); |
| 128 | const args = buildCommandArgs({ |
| 129 | req, |
| 130 | jsonObj, |
| 131 | spec, |
| 132 | command, |
| 133 | validateCommandArguments: !didPluginOverrideProxy, |
| 134 | }); |
| 135 | |
| 136 | // run the driver command wrapped inside the argument validators |
| 137 | getLogger(driver, sessionId).debug( |
| 138 | `Calling %s.%s() with args: %s`, |
| 139 | driver.constructor.name, |
| 140 | command, |
| 141 | logger.markSensitive(util.truncateString(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH})), |
| 142 | ); |
| 143 | |
| 144 | const result = didPluginOverrideProxy |
no test coverage detected