Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-686 (pull request #186)
Browse files Browse the repository at this point in the history
SHIBUI-686 Fixed validation of cert file

Approved-by: Shibui Jenkins <shibui.jenkins@gmail.com>
Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Aug 30, 2018
1 parent ae5601d commit 0ad4284
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 5 deletions.
134 changes: 132 additions & 2 deletions ui/src/app/schema-form/service/schema.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,140 @@ describe(`Schema Service`, () => {
type: 'string'
}
},
required: 'foo'
required: ['foo']
} },
path: ''
path: '/foo'
})).toBe(true);
}));

it(`should return true if the property is currently required based on anyOf`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' }
},
anyOf: [
{
properties: {
foo: { enum: [ true ] }
},
required: [ 'bar' ]
},
{
properties: {
foo: { enum: [ false ] }
}
}
]
},
value: { foo: true }
},
path: '/bar'
})).toBe(true);
})
);

it(`should return true if the property is NOT currently required based on anyOf`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' }
},
anyOf: [
{
properties: {
foo: { enum: [true] }
},
required: ['bar']
},
{
properties: {
foo: { enum: [false] }
}
}
]
},
value: { foo: false }
},
path: '/bar'
})).toBe(false);
})
);

it(`should return false if the property is NOT currently in any values`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' }
},
anyOf: [
{
properties: {
foo: { enum: [true] }
},
required: ['bar']
},
{
properties: {
foo: { enum: [false] }
}
}
]
},
value: {}
},
path: '/bar'
})).toBe(false);
})
);

it(`should return true if dependant on multiple values and any is true`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' },
baz: { type: 'string' }
},
anyOf: [
{
properties: {
foo: { enum: [true] }
},
required: ['bar']
},
{
properties: {
baz: { enum: [true] }
},
required: ['bar']
},
{
properties: {
foo: { enum: [false] }
}
}
]
},
value: {
foo: true,
baz: true
}
},
path: '/bar'
})).toBe(true);
})
);
});
});
10 changes: 9 additions & 1 deletion ui/src/app/schema-form/service/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export class SchemaService {

if (!required) {
const conditions = formProperty.parent.schema.anyOf || [];
conditions.forEach(el => {
const values = formProperty.parent.value;
const currentConditions = conditions.filter(condition =>
Object
.keys(condition.properties)
.some(
key => values.hasOwnProperty(key) ? condition.properties[key].enum[0] === values[key] : false
)
);
currentConditions.forEach(el => {
requiredFields = el.required || [];
required = !required ? requiredFields.indexOf(controlName) > -1 : required;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]
},
{
"title": "Unused Attributes",
"title": "",
"type": "hidden",
"fields": [
"tlsTrustEngineRef",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,25 @@
"default": ""
}
},
"required": ["certificateFile"]
"anyOf": [
{
"properties": {
"requireSignedRoot": {
"enum": [ true ]
}
},
"required": [
"certificateFile"
]
},
{
"properties": {
"requireSignedRoot": {
"enum": [ false ]
}
}
}
]
},
"EntityRoleWhiteList": {
"title": "Entity Role Whitelist Filter",
Expand Down

0 comments on commit 0ad4284

Please sign in to comment.