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

Add dataBuffer to response to be available in test scripts #1881

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

RainoPikkarainen
Copy link

@RainoPikkarainen RainoPikkarainen commented Mar 21, 2024

Description

I have a use case for accessing the dataBuffer in tests to validate a binary response from DNS over https services.
Since the dataBuffer was already exposed some time ago for displaying preview images or such, these trivial changes made it possible to access the binary buffer in tests to parse DNS packets.

image
image
image

I have been able to easily merge these changes and build the app locally, but now my local build does not have the new Golden key stuff, so it would be nice to have this or similar in the main branch.

Use case

meta {
  name: cloudflare-dns-query
  type: http
  seq: 6
}

get {
  url: https://cloudflare-dns.com/dns-query?dns=6bABAAABAAAAAAAAA3d3dxBnb29nbGVhZHNlcnZpY2VzA2NvbQAAAQAB
  body: none
  auth: none
}

query {
  dns: 6bABAAABAAAAAAAAA3d3dxBnb29nbGVhZHNlcnZpY2VzA2NvbQAAAQAB
  ~name: www.googleadservices.com
  ~type: A
}

headers {
  Accept: application/dns-message
  ~Accept: application/dns-json
}

tests {
  const DnsPacket = require('@dnsquery/dns-packet');
  
  const buffer = Buffer.from(res.getDataBuffer());
  const dnsPacket1 = DnsPacket.decode(buffer);
  console.log(JSON.stringify(dnsPacket1, null, 4));
  
  
  test("should get at least one answer", function() {
    expect(dnsPacket1.answers.length).to.be.greaterThan(0);
  });
  
  test("should get answer name matching query", function() {
    expect(dnsPacket1.answers.pop().name).to.equal("www.googleadservices.com");
  });
  
}

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

@Its-treason
Copy link
Member

This also needs to be added to CLI: run-single-request.js

@RainoPikkarainen
Copy link
Author

run-single-request.js doesn't seem to do the data = JSON.parse(response.data) stuff, so response.data is the buffer type already. Please help me out here if there needs to be some API compatibility.

@Its-treason
Copy link
Member

Its-treason commented Mar 21, 2024

run-single-request.js doesn't seem to do the data = JSON.parse(response.data) stuff, so response.data is the buffer type already. Please help me out here if there needs to be some API compatibility.

Yes, but this may also be another problem, if it's not the same in electron & CLI. But I can't test this right now, I look into it on the weekend.

@RainoPikkarainen
Copy link
Author

Is some decision planned whether to expose the response data buffer in GUI tests (like res.getDataBuffer() in this PR) or will the CLI, GUI and extension be unified (eg. all returning the response as a data buffer, likely a breaking change)?

@helloanoop helloanoop self-assigned this Sep 23, 2024
# Conflicts:
#	packages/bruno-js/src/bruno-response.js
@RainoPikkarainen RainoPikkarainen force-pushed the feature/binary-response-in-tests branch from aa4f663 to a075af2 Compare January 8, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants