-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DCKM-435: remove optional attributes from pex proof requests #238
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {pexService} from '../service'; | ||
import {pexService, removeOptionalAttribute} from '../service'; | ||
|
||
describe('Pex Examples', () => { | ||
it('expect to filter credentials based on a minimum value numeric filter', () => { | ||
|
@@ -265,7 +265,7 @@ describe('Pex Examples', () => { | |
expect(results.verifiableCredential.length).toBe(1); | ||
}); | ||
|
||
it('expect to remove optional attribute', () => { | ||
it('should fix PEX bug related to optional attributes', () => { | ||
const credentials = [ | ||
{ | ||
'@context': [ | ||
|
@@ -312,9 +312,9 @@ describe('Pex Examples', () => { | |
id: 'income_test', | ||
input_descriptors: [ | ||
{ | ||
id: 'ProofIncome-Merit-7', | ||
name: 'Test - released between 1995 and 2005', | ||
purpose: 'Filter credentials based released date', | ||
id: 'Credential 1', | ||
name: 'optional field', | ||
purpose: 'optional field', | ||
constraints: { | ||
fields: [ | ||
{ | ||
|
@@ -323,12 +323,13 @@ describe('Pex Examples', () => { | |
{ | ||
path: ['$.type[*]'], | ||
filter: { | ||
const: 'BasicCredential', | ||
const: '', | ||
}, | ||
optional: true, | ||
}, | ||
{ | ||
path: ['$.expirationDate'], | ||
optional: true, | ||
optional: false, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we have tests with both scenarios? Also, do we have tests that ensure the field isn't returned in the presentation if it's optional and the user deselects it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added better tests and also documentation about this function. For now, the optional attribute is used to reveal the attribute automatically and the user can't deselect it since there is no UI implication. For example, in the expiration date. But I can see potential issues with an attribute from the credential subject being marked as optional, since it will be always revealed and the user can't see that. I've just created a jira for it https://dock-team.atlassian.net/browse/DCKA-2504 Two scenarios I can think about:
We can handle that in the DCKM-439 |
||
], | ||
}, | ||
|
@@ -343,4 +344,101 @@ describe('Pex Examples', () => { | |
|
||
expect(results.verifiableCredential).toBeTruthy(); | ||
}); | ||
|
||
describe('removeOptionalAttribute', () => { | ||
const getFieldsWithOptionalAttributes = template => { | ||
return template.input_descriptors[0].constraints.fields.filter( | ||
field => field.optional !== undefined, | ||
).length; | ||
}; | ||
|
||
it('should remove optional attributes', () => { | ||
let template = { | ||
id: 'income_test', | ||
input_descriptors: [ | ||
{ | ||
id: 'Credential 1', | ||
name: 'optional field', | ||
purpose: 'optional field', | ||
constraints: { | ||
fields: [ | ||
{ | ||
path: ['$.credentialSubject.id'], | ||
}, | ||
{ | ||
path: ['$.type[*]'], | ||
filter: { | ||
const: '', | ||
}, | ||
optional: true, | ||
}, | ||
{ | ||
path: ['$.expirationDate'], | ||
optional: false, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
expect(getFieldsWithOptionalAttributes(template)).toBe(2); | ||
expect( | ||
getFieldsWithOptionalAttributes(removeOptionalAttribute(template)), | ||
).toBe(0); | ||
|
||
template = { | ||
id: 'income_test', | ||
input_descriptors: [ | ||
{ | ||
id: 'Credential 1', | ||
name: 'optional field', | ||
purpose: 'optional field', | ||
constraints: { | ||
fields: [ | ||
{ | ||
path: ['$.credentialSubject.id'], | ||
}, | ||
{ | ||
path: ['$.type[*]'], | ||
filter: { | ||
const: '', | ||
}, | ||
optional: true, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
expect(getFieldsWithOptionalAttributes(template)).toBe(1); | ||
expect( | ||
getFieldsWithOptionalAttributes(removeOptionalAttribute(template)), | ||
).toBe(0); | ||
|
||
template = { | ||
id: 'income_test', | ||
input_descriptors: [ | ||
{ | ||
id: 'Credential 1', | ||
name: 'optional field', | ||
purpose: 'optional field', | ||
constraints: { | ||
fields: [ | ||
{ | ||
path: ['$.credentialSubject.id'], | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
expect(getFieldsWithOptionalAttributes(template)).toBe(0); | ||
expect( | ||
getFieldsWithOptionalAttributes(removeOptionalAttribute(template)), | ||
).toBe(0); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an issue in that repository we can link to/track?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue for that Sphereon-Opensource/PEX#150