fix: add obfucation check for w3c documents#25
Conversation
WalkthroughThe changes add support for handling signed W3C Verifiable Credentials using the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Suite
participant Utils as isObfuscated()
participant VC as W3C Verifiable Credential
Test->>Utils: Call isObfuscated(VC)
Utils->>VC: Check if VC is signed (isSignedDocument)
alt VC is signed and proof.type == "BbsBlsSignatureProof2020"
Utils-->>Test: return true
else VC is not obfuscated
Utils-->>Test: return false
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/shared/utils/__tests__/utils.test.ts(2 hunks)
🔇 Additional comments (1)
src/shared/utils/__tests__/utils.test.ts (1)
15-17: LGTM! Import structure follows existing patterns.The new imports for W3C test fixtures and the SignedVerifiableCredential type are well-structured and consistent with the existing codebase patterns.
| describe("isObfuscated", () => { | ||
| test("should return false where there is no obfuscated data in document w3c", () => { | ||
| const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential; | ||
| expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false); | ||
| }); | ||
|
|
||
| test("should return true where there is obfuscated data in document w3c", () => { | ||
| const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential; | ||
| expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Consider improving test descriptions and adding edge cases.
The test structure follows good practices, but there are opportunities for improvement:
- The test descriptions could be more precise
- Consider adding edge cases for better coverage
- test("should return false where there is no obfuscated data in document w3c", () => {
+ test("should return false for W3C document without obfuscated data", () => {
const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
});
- test("should return true where there is obfuscated data in document w3c", () => {
+ test("should return true for W3C document with obfuscated data", () => {
const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
});Consider adding edge case tests such as:
- Invalid W3C document structure
- W3C document with missing proof property
- W3C document with unexpected proof types
Let me verify the actual fixture content and the isObfuscated implementation to ensure comprehensive test coverage:
🏁 Script executed:
#!/bin/bash
# Description: Examine the W3C test fixtures and isObfuscated implementation
echo "=== Examining W3C test fixtures ==="
echo "--- w3c-signed.json ---"
cat test/fixtures/w3c/w3c-signed.json | jq '.'
echo "--- w3c-redacted.json ---"
cat test/fixtures/w3c/w3c-redacted.json | jq '.'
echo "=== Examining isObfuscated implementation ==="
cat src/shared/utils/utils.ts | grep -A 20 -B 5 "isObfuscated"Length of output: 34174
Refine isObfuscated tests and expand coverage
The new describe block correctly validates the two W3C fixtures, but we can improve clarity and robustness:
• Update test descriptions for consistency.
• Add edge-case tests around proof presence/type and unsupported document shapes.
Pinpoint in src/shared/utils/__tests__/utils.test.ts around lines 462–472.
Proposed diff:
describe("isObfuscated", () => {
- test("should return false where there is no obfuscated data in document w3c", () => {
+ test("returns false for signed VC with proof.type = BbsBlsSignature2020", () => {
const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
});
- test("should return true where there is obfuscated data in document w3c", () => {
+ test("returns true for signed VC with proof.type = BbsBlsSignatureProof2020", () => {
const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
});
+
+ test("returns false if proof is missing or proof.type is unexpected", () => {
+ const noProof = { proof: undefined } as SignedVerifiableCredential;
+ const wrongProofType = { proof: { type: "DummyProof2020" } } as SignedVerifiableCredential;
+ expect(utils.isObfuscated(noProof)).toBe(false);
+ expect(utils.isObfuscated(wrongProofType)).toBe(false);
+ });
+
+ test("throws on unsupported document shapes", () => {
+ expect(() => utils.isObfuscated({} as any)).toThrow(
+ /Unsupported document type/
+ );
+ });
});Edge cases to cover:
- Signed VCs without a
proofproperty - Signed VCs with an unrelated
proof.type - Completely invalid document objects (should throw)
These additions will ensure isObfuscated handles all branches in its implementation.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| describe("isObfuscated", () => { | |
| test("should return false where there is no obfuscated data in document w3c", () => { | |
| const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential; | |
| expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false); | |
| }); | |
| test("should return true where there is obfuscated data in document w3c", () => { | |
| const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential; | |
| expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true); | |
| }); | |
| }); | |
| describe("isObfuscated", () => { | |
| test("returns false for signed VC with proof.type = BbsBlsSignature2020", () => { | |
| const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential; | |
| expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false); | |
| }); | |
| test("returns true for signed VC with proof.type = BbsBlsSignatureProof2020", () => { | |
| const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential; | |
| expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true); | |
| }); | |
| test("returns false if proof is missing or proof.type is unexpected", () => { | |
| const noProof = { proof: undefined } as SignedVerifiableCredential; | |
| const wrongProofType = { proof: { type: "DummyProof2020" } } as SignedVerifiableCredential; | |
| expect(utils.isObfuscated(noProof)).toBe(false); | |
| expect(utils.isObfuscated(wrongProofType)).toBe(false); | |
| }); | |
| test("throws on unsupported document shapes", () => { | |
| expect(() => utils.isObfuscated({} as any)).toThrow( | |
| /Unsupported document type/ | |
| ); | |
| }); | |
| }); |
🤖 Prompt for AI Agents
In src/shared/utils/__tests__/utils.test.ts around lines 462 to 472, improve the
isObfuscated test suite by refining test descriptions for clarity and
consistency. Add new tests covering edge cases: one with a signed verifiable
credential missing the proof property, another with a proof property having an
unrelated type, and a test passing a completely invalid document object that
should cause isObfuscated to throw an error. These additions will enhance
coverage and ensure all code branches in isObfuscated are tested.
|
🎉 This PR is included in version 6.10.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
add obfuscation check for w3c documents
Issues
Jira Ticket
Summary by CodeRabbit
New Features
Tests