(dsn: DsnComponents)
| 81 | } |
| 82 | |
| 83 | function validateDsn(dsn: DsnComponents): boolean { |
| 84 | if (!DEBUG_BUILD) { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | const { port, projectId, protocol } = dsn; |
| 89 | |
| 90 | const requiredComponents: ReadonlyArray<keyof DsnComponents> = ['protocol', 'publicKey', 'host', 'projectId']; |
| 91 | const hasMissingRequiredComponent = requiredComponents.find(component => { |
| 92 | if (!dsn[component]) { |
| 93 | debug.error(`Invalid Sentry Dsn: ${component} missing`); |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | }); |
| 98 | |
| 99 | if (hasMissingRequiredComponent) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (!projectId.match(/^\d+$/)) { |
| 104 | debug.error(`Invalid Sentry Dsn: Invalid projectId ${projectId}`); |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | if (!isValidProtocol(protocol)) { |
| 109 | debug.error(`Invalid Sentry Dsn: Invalid protocol ${protocol}`); |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if (port && isNaN(parseInt(port, 10))) { |
| 114 | debug.error(`Invalid Sentry Dsn: Invalid port ${port}`); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Extract the org ID from a DSN host. |
no test coverage detected