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

fix: gateway conformance improvements #85

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented May 22, 2024

Title

fix: gateway conformance improvements

Description

A lot of changes here to fix requests from the gateway-conformance tests. This PR unblocks the ability to start improving
the gateway conformance of @helia/verified-fetch because most requests are now fully received and responded to by our basic-server.

This change depends on a bug fix in @helia/utils, ipfs/helia#542

Fixes ipfs/service-worker-gateway#266
Fixes #84

Summary of changes

  • gateway-conformance changes
    • Implement IPFS_NS_MAP resolution
      • dnslinks are resolved with local dns resolver
      • ipns records are loaded into Helia datastore (this could likely be improved, but TestGatewayIPNSPath is passing at 100% now)
    • removes reverse-proxy.js since it's no longer needed (less moving parts.. closer to verified-fetch)
    • fixes shutdown logic of basic-server and test fixtures.
    • Implements a HACK for gateway-conformance lack of support for subdomains with ports. see fixingGwcAnnoyance in basic-server.js
    • adds request url suffix to logger in basic-server.js to help debug issues with the gateway conformance tests.
    • constructs explicit Helia instance that is passed to verified-fetch so we can override things as necessary
      • remove delegated routing (we don't want remote work)
      • customize datastore so we can load/resolve ipns records
    • changes individual tests we run that are substrings of other individual test names to explicitly skip the longer name (so the tests are more isolated). e.g. TestTrustlessRaw should not run TestTrustlessRawRanges tests.
  • verified-fetch changes
    • Added getRedirectResponse util that is called prior to calling codecHandlers in order to satisfy the gateway conformance tests
      • We will likely need to adjust this logic because this dropped successRate of TestDagPbConversion and others.
    • Re-orders the REGEX order in matchURLString to resolve /ipns/ paths trigger false-positive DNSLink lookup service-worker-gateway#266 and adds a test for it
    • Returns a 404 for raw requests that have a path, since we can't walk paths on raw IPFS content.
      • Fixes test is passed a filename from a deep traversal if it is available that broke when implementing this change to actually construct a folder with nested content.

Notes & open questions

Returns a 404 for raw requests that have a path, since we can't walk paths on raw IPFS content.

Are there any nuances with the fix I added here we need to handle? maybe something with query/search handler.. but i believe that's already being handled elsewhere (e.g. parseUrl/resource)

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review.. will be applying my own suggestions

packages/gateway-conformance/.aegir.js Outdated Show resolved Hide resolved
packages/gateway-conformance/src/conformance.spec.ts Outdated Show resolved Hide resolved
packages/verified-fetch/src/utils/handle-redirects.ts Outdated Show resolved Hide resolved
packages/verified-fetch/src/utils/handle-redirects.ts Outdated Show resolved Hide resolved
packages/verified-fetch/src/utils/handle-redirects.ts Outdated Show resolved Hide resolved
packages/verified-fetch/src/utils/handle-redirects.ts Outdated Show resolved Hide resolved
packages/verified-fetch/src/verified-fetch.ts Outdated Show resolved Hide resolved
@SgtPooki SgtPooki marked this pull request as ready for review May 23, 2024 20:43
@SgtPooki SgtPooki requested a review from a team as a code owner May 23, 2024 20:43
@@ -109,7 +109,7 @@ const tests: TestConfig[] = [
{
name: 'TestGatewayBlock',
run: ['TestGatewayBlock'],
successRate: 37.93
successRate: 20.69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come some of these tests have a lower sucessRate threshold?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not 100% sure but i think its because requests werent making it to the endpoint and we had false negatives.

Since gwc is still being fleshed out & unit tests &interop are passing i think this is acceptable for now.

This should be the last time we have to adjust successRate to satisfy wishy-washy issues.

It would be nice to be able to output gwc failing/successful tests so we could compare more easily than manually parsing the json

} finally {
urlLog.trace('Cleaning up request')
clearTimeout(reqTimeout)
requestController.abort()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you abort here?

Copy link
Member Author

@SgtPooki SgtPooki May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To kill verified-fetch work that may still be ongoing (session findProvider loop is one I can think of that may still be going)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, this seems a little counter intuitive that there may still be ongoing requests even after the promise is resolved.

Maybe it's something worth documenting with regards to sessions?

return path.endsWith('/') ? path : `${path}/`
}

export async function getRedirectResponse ({ resource, options, logger, cid }: GetRedirectResponse): Promise<null | Response> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a test for this function that illustrate when it redirects?

Suggested change
export async function getRedirectResponse ({ resource, options, logger, cid }: GetRedirectResponse): Promise<null | Response> {
// See https://specs.ipfs.tech/http-gateways/path-gateway/#location-response-header
export async function getRedirectResponse ({ resource, options, logger, cid }: GetRedirectResponse): Promise<null | Response> {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really should have a test, but gwc tests it, so i figured it was fine for now. Since we already have gwc tests, redoing all that coverage in unit tests is not ideal.

Ill add a basic test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@2color 2color left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments and suggestions. No major objections from me as this in essence should increase confidence with the tests

SgtPooki and others added 4 commits May 24, 2024 10:40
Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com>
Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com>
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

Comment on lines +26 to +34
// TODO: do we need to do anything with CNAME resolution...?
// if (questions.some((q) => q.type === 5)) {
// answers.push({
// name: domain,
// type: 5,
// TTL: 180,
// data: ''
// })
// }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure about this one, but tests seem to work for now. I would like to leave this until i'm sure gwc tests don't depend on it. If we are debugging a test failure and end up here, it may trigger idea for a fix.

return path.endsWith('/') ? path : `${path}/`
}

export async function getRedirectResponse ({ resource, options, logger, cid }: GetRedirectResponse): Promise<null | Response> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SgtPooki SgtPooki merged commit 7281078 into main May 24, 2024
20 checks passed
@SgtPooki SgtPooki deleted the 84-fix-infinite-querying-bug-reproducible-on-some-gateway-conformance-tests-that-were-disabled-in-httpsgithubcomipfshelia-verified-fetchpull81 branch May 24, 2024 19:09
github-actions bot pushed a commit that referenced this pull request May 24, 2024
## @helia/verified-fetch [1.4.3](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-1.4.2...@helia/verified-fetch-1.4.3) (2024-05-24)

### Bug Fixes

* gateway conformance improvements ([#85](#85)) ([7281078](7281078))
Copy link

🎉 This PR is included in version 1.4.3 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this pull request May 24, 2024
## @helia/verified-fetch-gateway-conformance [1.1.2](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-gateway-conformance-1.1.1...@helia/verified-fetch-gateway-conformance-1.1.2) (2024-05-24)

### Bug Fixes

* gateway conformance improvements ([#85](#85)) ([7281078](7281078))

### Dependencies

* **@helia/verified-fetch:** upgraded to 1.4.3
Copy link

🎉 This PR is included in version 1.1.2 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this pull request May 24, 2024
## @helia/verified-fetch-interop [1.24.1](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-interop-1.24.0...@helia/verified-fetch-interop-1.24.1) (2024-05-24)

### Bug Fixes

* gateway conformance improvements ([#85](#85)) ([7281078](7281078))

### Dependencies

* bump kubo from 0.27.0 to 0.28.0 ([#54](#54)) ([3579844](3579844))

### Dependencies

* **@helia/verified-fetch:** upgraded to 1.4.3
Copy link

🎉 This PR is included in version 1.24.1 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants