Skip to content

Commit

Permalink
The JsonSecretProcessor was not considering oneOf as valid (#17484)
Browse files Browse the repository at this point in the history
* The JsonSecretProcessor was not considering oneOf as valid

* Format
  • Loading branch information
benmoriceau authored Oct 3, 2022
1 parent 8c4b61c commit ac9b1ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class JsonSecretsProcessor {
static final String TYPE_FIELD = "type";
static final String ARRAY_TYPE_FIELD = "array";
static final String ITEMS_FIELD = "items";
static final String ONE_OF_FIELD = "oneOf";

/**
* Returns a copy of the input object wherein any fields annotated with "airbyte_secret" in the
Expand Down Expand Up @@ -175,8 +176,10 @@ private static Optional<String> findJsonCombinationNode(final JsonNode node) {
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private static boolean isValidJsonSchema(final JsonNode schema) {
return schema.isObject() && schema.has(PROPERTIES_FIELD) && schema.get(PROPERTIES_FIELD).isObject();
@VisibleForTesting
public static boolean isValidJsonSchema(final JsonNode schema) {
return schema.isObject() && ((schema.has(PROPERTIES_FIELD) && schema.get(PROPERTIES_FIELD).isObject())
|| (schema.has(ONE_OF_FIELD) && schema.get(ONE_OF_FIELD).isArray()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -46,6 +47,9 @@ void testOnAllExistingConfig() throws IOException, JsonValidationException {
Assertions.assertThat(allSpecs)
.flatMap(spec -> {
try {
if (!JsonSecretsProcessor.isValidJsonSchema(spec)) {
throw new RuntimeException("Fail JsonSecretsProcessor validation");
}
JsonSchemas.traverseJsonSchema(spec, (node, path) -> {});
return Collections.emptyList();
} catch (final Exception e) {
Expand Down

0 comments on commit ac9b1ab

Please sign in to comment.