-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core)!: improve proof request validation (#525)
BREAKING CHANGE: Proof request requestedAttributes and requestedPredicates are now a map instead of record. This is needed to have proper validation using class-validator. Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
9c3910f
commit 1b4d8d6
Showing
6 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
packages/core/src/modules/proofs/__tests__/ProofRequest.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { JsonTransformer } from '../../../utils/JsonTransformer' | ||
import { MessageValidator } from '../../../utils/MessageValidator' | ||
import { ProofRequest } from '../models' | ||
|
||
describe('ProofRequest', () => { | ||
it('should successfully validate if the proof request json contains a valid structure', async () => { | ||
const proofRequest = JsonTransformer.fromJSON( | ||
{ | ||
name: 'ProofRequest', | ||
version: '1.0', | ||
nonce: '58d223e5-fc4d-4448-b74c-5eb11c6b558f', | ||
requested_attributes: { | ||
First: { | ||
name: 'Timo', | ||
restrictions: [ | ||
{ | ||
schema_id: 'string', | ||
}, | ||
], | ||
}, | ||
}, | ||
requested_predicates: { | ||
Second: { | ||
name: 'Timo', | ||
p_type: '<=', | ||
p_value: 10, | ||
restrictions: [ | ||
{ | ||
schema_id: 'string', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
ProofRequest | ||
) | ||
|
||
expect(MessageValidator.validate(proofRequest)).resolves.not.toThrow() | ||
}) | ||
|
||
it('should throw an error if the proof request json contains an invalid structure', async () => { | ||
const proofRequest = JsonTransformer.fromJSON( | ||
{ | ||
name: 'ProofRequest', | ||
version: '1.0', | ||
nonce: '58d223e5-fc4d-4448-b74c-5eb11c6b558f', | ||
requested_attributes: { | ||
First: { | ||
names: [], | ||
restrictions: [ | ||
{ | ||
schema_id: 'string', | ||
}, | ||
], | ||
}, | ||
}, | ||
requested_predicates: [ | ||
{ | ||
name: 'Timo', | ||
p_type: '<=', | ||
p_value: 10, | ||
restrictions: [ | ||
{ | ||
schema_id: 'string', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
ProofRequest | ||
) | ||
|
||
// Expect 2 top level validation errors | ||
expect(MessageValidator.validate(proofRequest)).rejects.toHaveLength(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters