Skip to content

Commit

Permalink
PDE-5589 update field constraints error.schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Natay committed Feb 19, 2025
1 parent 41e6b39 commit a6a66d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 8 additions & 6 deletions packages/schema/lib/functional-constraints/AuthFieldisSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const FORBIDDEN_KEYS = [
const isSensitiveKey = (key = '') =>
FORBIDDEN_KEYS.some((forbidden) => key.toLowerCase().includes(forbidden));

const checkAuthField = (field) => {
const checkAuthField = (field, mainSchema) => {
const errors = [];

// if the field key contains any forbidden substring (case-insensitive),
Expand All @@ -46,7 +46,7 @@ const checkAuthField = (field) => {
new jsonschema.ValidationError(
`cannot set isNoSecret as true for the sensitive key "${field.key}".`,
field,
'/AuthFieldSchema',
'instance.schema',
'instance.field',
'sensitive',
'field',
Expand All @@ -70,8 +70,9 @@ module.exports = (definition, mainSchema) => {
) {
const definitions = Array.isArray(definition) ? definition : [definition];
definitions.forEach((field, index) => {
checkAuthField(field).forEach((err) => {
checkAuthField(field, mainSchema).forEach((err) => {
err.property = `instance[${index}]`;
err.schema = mainSchema.id;
err.stack = err.stack.replace('instance.field', err.property);
errors.push(err);
});
Expand All @@ -85,7 +86,8 @@ module.exports = (definition, mainSchema) => {

if (definition.authentication.inputFields) {
definition.authentication.inputFields.forEach((field, index) => {
checkAuthField(field).forEach((err) => {
checkAuthField(field, mainSchema).forEach((err) => {
err.schema = AUTH_INPUT_FIELD_ID;
err.property = `instance.authentication.inputFields[${index}]`;
err.stack = err.stack.replace('instance.field', err.property);
errors.push(err);
Expand All @@ -94,8 +96,8 @@ module.exports = (definition, mainSchema) => {
}
if (definition.authentication.outputFields) {
definition.authentication.outputFields.forEach((field, index) => {
checkAuthField(field).forEach((err) => {
err.property = `instance.authentication.outputFields[${index}]`;
checkAuthField(field, mainSchema).forEach((err) => {
err.schema = AUTH_OUTPUT_FIELD_ID;
err.stack = err.stack.replace('instance.field', err.property);
errors.push(err);
});
Expand Down
1 change: 0 additions & 1 deletion packages/schema/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ describe('app', () => {
// Expect at least one error because "password" can't have isNoSecret = true
results.errors.should.have.length(1);
should(results.valid).eql(false);

const [error] = results.errors;
error.name.should.equal('sensitive');
error.stack.should.eql(
Expand Down

0 comments on commit a6a66d9

Please sign in to comment.