Skip to content

Maven dependency proxy: refine model validations

🔥 Problem

Updating with:

mutation {
  updateDependencyProxyPackagesSettings(input: {
    projectPath: "<path>",
    mavenExternalRegistryPassword: "",
    mavenExternalRegistryUrl: "https://repo1.maven.org/maven3",
    mavenExternalRegistryUsername: null
  }) {
    dependencyProxyPackagesSetting {
      mavenExternalRegistryUrl
      mavenExternalRegistryUsername
    },
    errors
  }
}

ends up in an Internal error.

this is a mismatch between the database validations and the rails model validations.

  • database : The number of NULLs between the username and the password columns is either 0 or 2.
  • rails model: Check username if the password is present (and vice-versa). The issue is the how the presence check is defined. It's the opposite of blank and blank is true for values: nil, "", '', [], {}, and false.

-> password set to "". For the rails part, a value is set but then when the value is encrypted, the actual value written to the database becomes \x and the database validation will 💥 on this (internal error).

🚒 Solution

Update the model validation is that "" values are not accepted.

The cross presence validation should not rely on the #present? function but use unless: ....nil?.

Edited by David Fernandez