( headers: RawRequestDefaultExpression['headers'] )
| 211 | } |
| 212 | |
| 213 | export async function validateImportRequest( |
| 214 | headers: RawRequestDefaultExpression['headers'] |
| 215 | ): Promise<IServiceClientWithProject> { |
| 216 | const clientId = headers['openpanel-client-id'] as string; |
| 217 | const clientSecret = (headers['openpanel-client-secret'] as string) || ''; |
| 218 | |
| 219 | if ( |
| 220 | !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test( |
| 221 | clientId |
| 222 | ) |
| 223 | ) { |
| 224 | throw new Error('Import: Client ID must be a valid UUIDv4'); |
| 225 | } |
| 226 | |
| 227 | const client = await getClientByIdCached(clientId); |
| 228 | |
| 229 | if (!client) { |
| 230 | throw new Error('Import: Invalid client id'); |
| 231 | } |
| 232 | |
| 233 | if (!client.secret) { |
| 234 | throw new Error('Import: Client has no secret'); |
| 235 | } |
| 236 | |
| 237 | if (client.type === ClientType.write) { |
| 238 | throw new Error('Import: Client is not allowed to import'); |
| 239 | } |
| 240 | |
| 241 | if (!(await verifyPassword(clientSecret, client.secret))) { |
| 242 | throw new Error('Import: Invalid client secret'); |
| 243 | } |
| 244 | |
| 245 | return client; |
| 246 | } |
| 247 | |
| 248 | export async function validateManageRequest( |
| 249 | headers: RawRequestDefaultExpression['headers'] |
no test coverage detected