Skip to content
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

JSON schema validation not called for RecordsWrite #681

Open
thehenrytsai opened this issue Feb 6, 2024 · 0 comments
Open

JSON schema validation not called for RecordsWrite #681

thehenrytsai opened this issue Feb 6, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed testing related to new or existing tests

Comments

@thehenrytsai
Copy link
Member

thehenrytsai commented Feb 6, 2024

It appears that JSON schema validation function (Message.validateJsonSchema(message);) is not invoked by RecordsWrite interface class. The schema validation must be invoked in parse() path to ensure message validity, but should probably also be called in message() path too for sanity to make sure we always return a valid message.

Also in create() we should probably call the unauthorized/unidentified version of the schema.

Wrote a test to sanity verify, and the function is not called:

    it('should invoke JSON schema validation when parsing a RecordsWrite', async () => {
      const alice = await TestDataGenerator.generatePersona();

      const recordsWrite = await RecordsWrite.create({
        signer     : Jws.createSigner(alice),
        dataFormat : 'application/octet-stream',
        data       : TestDataGenerator.randomBytes(10),
      });

      const validateJsonSchemaSpy = Sinon.spy(Message, 'validateJsonSchema');

      await RecordsWrite.parse(recordsWrite.message);

      expect(validateJsonSchemaSpy.called).to.be.true;
    });
@thehenrytsai thehenrytsai added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed testing related to new or existing tests labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed testing related to new or existing tests
Projects
Status: High Priority Backlog
Development

No branches or pull requests

1 participant