Skip to content

Commit

Permalink
Match descriptions from devConfig.yaml as well
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek3255 committed Feb 21, 2024
1 parent 58abb6e commit da94c96
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions devConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ core_config_version: 0
# password_reset_token_lifetime:


# (DIFFERENT_ACROSS_TENANTS | OPTIONAL | Default: 86400000 (1 day)) long value. Time in milliseconds for how long an
# (DIFFERENT_ACROSS_TENANTS | OPTIONAL | Default: 86400000 (1 day)) long value. Time in milliseconds for how long an
# email verification token / link is valid for.
# email_verification_token_lifetime:

Expand Down Expand Up @@ -140,7 +140,7 @@ disable_telemetry: true

# (OPTIONAL | Default: null). This is used when deploying the core in SuperTokens SaaS infrastructure. If set, limits
# what database information is shown to / modifiable by the dev when they query the core to get the information about
# their tenants. It only exposes that information when this key is used instead of the regular api_keys config.
# their tenants. It only exposes that information when this key is used instead of the regular api_keys config.
# supertokens_saas_secret:

# (DIFFERENT_ACROSS_APPS | OPTIONAL | Default: null). This is used when the core needs to assume a specific CDI version
Expand Down
47 changes: 34 additions & 13 deletions src/test/java/io/supertokens/test/CoreConfigListAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,31 @@ public void testMatchConfigPropertiesDescription() throws Exception {
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

try (BufferedReader reader = new BufferedReader(new FileReader("./config.yaml"))) {
// access_token_signing_key_update_interval is an alias for
// access_token_dynamic_signing_key_update_interval,
// we don't have a description for core_config_version
// and webserver_https_enabled is not present in the config.yaml file
// so we skip these properties.
String[] ignoredProperties = {"access_token_signing_key_update_interval", "core_config_version", "webserver_https_enabled"};

// Match the descriptions in the config.yaml file with the descriptions in the
// CoreConfig class
matchYamlAndConfigDescriptions("./config.yaml", ignoredProperties);

// Match the descriptions in the devConfig.yaml file with the descriptions in
// the CoreConfig class
String[] devConfigIgnoredProperties = Arrays.copyOf(ignoredProperties, ignoredProperties.length + 1);
// We ignore this property in devConfig.yaml because it has a different description
// in devConfig.yaml and has a default value
devConfigIgnoredProperties[ignoredProperties.length] = "disable_telemetry";
matchYamlAndConfigDescriptions("./devConfig.yaml", devConfigIgnoredProperties);

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

private void matchYamlAndConfigDescriptions(String path, String[] ignoreProperties) throws Exception {
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
// Get the content of the file as string
String content = reader.lines().collect(Collectors.joining(System.lineSeparator()));
// Find the line that contains 'core_config_version', and then split
Expand Down Expand Up @@ -124,14 +148,7 @@ public void testMatchConfigPropertiesDescription() throws Exception {
}

for (String fieldId : CoreConfig.getValidFields()) {
// access_token_signing_key_update_interval is an alias for
// access_token_dynamic_signing_key_update_interval,
// we don't have a description for core_config_version
// and webserver_https_enabled is not present in the config.yaml file
// so we skip these properties.
if (fieldId.equals("access_token_signing_key_update_interval")
|| fieldId.equals("core_config_version")
|| fieldId.equals("webserver_https_enabled")) {
if (Arrays.asList(ignoreProperties).contains(fieldId)) {
continue;
}

Expand All @@ -144,6 +161,11 @@ public void testMatchConfigPropertiesDescription() throws Exception {

String descriptionInConfig = field.getAnnotation(ConfigDescription.class).value();
String descriptionInYaml = propertyDescriptions.get(fieldId);

if (descriptionInYaml == null) {
fail("Unable to find description or property for " + fieldId + " in " + path + " file");
}

// Remove the default value from config, since we add default value at the end
// config description
descriptionInConfig = descriptionInConfig.replaceAll("\\s\\[Default:.*|\\s\\(Default:.*", "").trim();
Expand All @@ -152,12 +174,11 @@ public void testMatchConfigPropertiesDescription() throws Exception {
descriptionInConfig = descriptionInConfig.replaceAll("\\.$", "").trim();

// Assert that description in yaml contains the description in config
assertTrue(descriptionInYaml.contains(descriptionInConfig));
if (!descriptionInYaml.contains(descriptionInConfig)) {
fail("Description in config class for " + fieldId + " does not match description in " + path + " file");
}
}
}

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

}

0 comments on commit da94c96

Please sign in to comment.