( rawAuth: unknown, source: string, warnings: HttpImportWarning[], )
| 175 | } |
| 176 | |
| 177 | function parseAuth( |
| 178 | rawAuth: unknown, |
| 179 | source: string, |
| 180 | warnings: HttpImportWarning[], |
| 181 | ): { auth: HttpAuth, headers: HttpHeaderEntry[], query: HttpQueryEntry[] } { |
| 182 | if (rawAuth === 'inherit' || rawAuth === undefined || rawAuth === null) { |
| 183 | return { auth: { type: 'none' }, headers: [], query: [] } |
| 184 | } |
| 185 | |
| 186 | if (!isRecord(rawAuth)) { |
| 187 | return { auth: { type: 'none' }, headers: [], query: [] } |
| 188 | } |
| 189 | |
| 190 | const type = asString(rawAuth.type).toLowerCase() |
| 191 | if (!type || type === 'none' || type === 'inherit') { |
| 192 | return { auth: { type: 'none' }, headers: [], query: [] } |
| 193 | } |
| 194 | |
| 195 | if (type === 'bearer') { |
| 196 | return { |
| 197 | auth: { token: asString(rawAuth.token), type: 'bearer' }, |
| 198 | headers: [], |
| 199 | query: [], |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (type === 'basic') { |
| 204 | return { |
| 205 | auth: { |
| 206 | password: asString(rawAuth.password), |
| 207 | type: 'basic', |
| 208 | username: asString(rawAuth.username), |
| 209 | }, |
| 210 | headers: [], |
| 211 | query: [], |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if (type === 'apikey') { |
| 216 | const key = asString(rawAuth.key) |
| 217 | const value = asString(rawAuth.value) |
| 218 | const placement = asString(rawAuth.placement) |
| 219 | addWarning(warnings, source, 'API key auth imported as request entry') |
| 220 | |
| 221 | if (placement === 'query') { |
| 222 | return { |
| 223 | auth: { type: 'none' }, |
| 224 | headers: [], |
| 225 | query: key ? [{ key, value }] : [], |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return { |
| 230 | auth: { type: 'none' }, |
| 231 | headers: key ? [{ key, value }] : [], |
| 232 | query: [], |
| 233 | } |
| 234 | } |
no test coverage detected