Skip to content

fix: [WLEO-439] Changed behavior of evaluateInputDescriptor helper functions to throw on no match #238

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

Open
wants to merge 1 commit into
base: eudiw-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/credential/presentation/07-evaluate-input-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ export const evaluateInputDescriptorForMdoc: EvaluateInputDescriptorMdoc = (
);
}

if (requiredDisclosures.length === 0 && optionalDisclosures.length === 0) {
throw new MissingDataError(
"Credential validation failed: No required fields were requested and no optional field has been requested or found."
);
}

return {
requiredDisclosures,
optionalDisclosures,
Expand Down Expand Up @@ -348,6 +354,12 @@ export const evaluateInputDescriptorForSdJwt4VC: EvaluateInputDescriptorSdJwt4VC
);
}

if (requiredDisclosures.length === 0 && optionalDisclosures.length === 0) {
throw new MissingDataError(
"Credential validation failed: No required fields were requested and no optional field has been requested or found."
);
}

return {
requiredDisclosures,
optionalDisclosures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("evaluateInputDescriptorForSdJwt4VC", () => {
).toThrow(); // Required field not satisfied
});

it("should pass if a field path does not exist but is optional", () => {
it("should throw if a field path does not exist but is optional", () => {
const inputDescriptor: InputDescriptor = {
id: "testDescriptor",
name: "test",
Expand All @@ -111,13 +111,13 @@ describe("evaluateInputDescriptorForSdJwt4VC", () => {
},
];

const { requiredDisclosures } = evaluateInputDescriptorForSdJwt4VC(
inputDescriptor,
payloadCredential,
disclosures
);
// Because the field is optional, we keep the original disclosures
expect(requiredDisclosures).toEqual([]);
expect(() => {
evaluateInputDescriptorForSdJwt4VC(
inputDescriptor,
payloadCredential,
disclosures
);
}).toThrow();
});

it("should pass if a field path required and another is optional", () => {
Expand Down Expand Up @@ -340,7 +340,7 @@ describe("evaluateInputDescriptorForMdoc", () => {
).toThrow(); // Required field not satisfied
});

it("should pass if a field path does not exist but is optional", () => {
it("should throw if a field path does not exist but is optional", () => {
const inputDescriptor: InputDescriptor = {
id: "testDescriptor",
name: "test",
Expand All @@ -354,11 +354,9 @@ describe("evaluateInputDescriptorForMdoc", () => {
},
};

const { requiredDisclosures, optionalDisclosures } =
evaluateInputDescriptorForMdoc(inputDescriptor, minimalPayloadCredential);
// Because the field is optional, we keep the original disclosures
expect(requiredDisclosures).toEqual([]);
expect(optionalDisclosures).toEqual([]);
expect(() =>
evaluateInputDescriptorForMdoc(inputDescriptor, minimalPayloadCredential)
).toThrow();
});

it("should pass if a field path required and another is optional", () => {
Expand Down
Loading