()
| 179 | } |
| 180 | |
| 181 | validate(): void { |
| 182 | if ( |
| 183 | (this.mechanism === AuthMechanism.MONGODB_GSSAPI || |
| 184 | this.mechanism === AuthMechanism.MONGODB_PLAIN || |
| 185 | this.mechanism === AuthMechanism.MONGODB_SCRAM_SHA1 || |
| 186 | this.mechanism === AuthMechanism.MONGODB_SCRAM_SHA256) && |
| 187 | !this.username |
| 188 | ) { |
| 189 | throw new MongoMissingCredentialsError(`Username required for mechanism '${this.mechanism}'`); |
| 190 | } |
| 191 | |
| 192 | if (this.mechanism === AuthMechanism.MONGODB_OIDC) { |
| 193 | if ( |
| 194 | this.username && |
| 195 | this.mechanismProperties.ENVIRONMENT && |
| 196 | this.mechanismProperties.ENVIRONMENT !== 'azure' |
| 197 | ) { |
| 198 | throw new MongoInvalidArgumentError( |
| 199 | `username and ENVIRONMENT '${this.mechanismProperties.ENVIRONMENT}' may not be used together for mechanism '${this.mechanism}'.` |
| 200 | ); |
| 201 | } |
| 202 | |
| 203 | if (this.username && this.password) { |
| 204 | throw new MongoInvalidArgumentError( |
| 205 | `No password is allowed in ENVIRONMENT '${this.mechanismProperties.ENVIRONMENT}' for '${this.mechanism}'.` |
| 206 | ); |
| 207 | } |
| 208 | |
| 209 | if ( |
| 210 | (this.mechanismProperties.ENVIRONMENT === 'azure' || |
| 211 | this.mechanismProperties.ENVIRONMENT === 'gcp') && |
| 212 | !this.mechanismProperties.TOKEN_RESOURCE |
| 213 | ) { |
| 214 | throw new MongoInvalidArgumentError(TOKEN_RESOURCE_MISSING_ERROR); |
| 215 | } |
| 216 | |
| 217 | if ( |
| 218 | this.mechanismProperties.ENVIRONMENT && |
| 219 | !ALLOWED_ENVIRONMENT_NAMES.includes(this.mechanismProperties.ENVIRONMENT) |
| 220 | ) { |
| 221 | throw new MongoInvalidArgumentError( |
| 222 | `Currently only a ENVIRONMENT in ${ALLOWED_ENVIRONMENT_NAMES.join( |
| 223 | ',' |
| 224 | )} is supported for mechanism '${this.mechanism}'.` |
| 225 | ); |
| 226 | } |
| 227 | |
| 228 | if ( |
| 229 | !this.mechanismProperties.ENVIRONMENT && |
| 230 | !this.mechanismProperties.OIDC_CALLBACK && |
| 231 | !this.mechanismProperties.OIDC_HUMAN_CALLBACK |
| 232 | ) { |
| 233 | throw new MongoInvalidArgumentError( |
| 234 | `Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK must be specified for mechanism '${this.mechanism}'.` |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | if (this.mechanismProperties.ALLOWED_HOSTS) { |
no test coverage detected