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

feat: update receiver regex validation #430

Merged
merged 6 commits into from
Mar 1, 2024

Conversation

BlairCurrey
Copy link
Contributor

Changes proposed in this pull request

changes the receiver regex so that:

  • it now matches with http and any id (instead of just uuid)
  • it does not match with deprecated /connections/ path

Context

I noticed when using the client in the local environment that a receiver with an http url fails validation, which is necessary for local development. We are already using such a url, we're just not using the client for it (see the bruno/postman Create Quote request body). Widening that was the main goal and the other changes are more cleanup.

fixes #429

Copy link

changeset-bot bot commented Feb 22, 2024

🦋 Changeset detected

Latest commit: a4b56ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@interledger/open-payments Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Feb 22, 2024

Deploy Preview for openpayments-preview canceled.

Name Link
🔨 Latest commit a4b56ec
🔍 Latest deploy log https://app.netlify.com/sites/openpayments-preview/deploys/65df77334778f90009bb56e2

@BlairCurrey
Copy link
Contributor Author

⚠️ No Changeset found

Latest commit: e10f069

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets
Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Note: I purposefully did not add a changeset. This only changes the schema (and a test). Can just use the fetch-schemas script in rafiki to get these changes.

@@ -42,10 +42,11 @@ components:
type: string
description: The URL of the incoming payment or ILP STREAM connection that is being paid.
format: uri
pattern: '^https://(.+)/(incoming-payments|connections)/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
pattern: '^(https|http)://(.+)/incoming-payments/(.+)$'
Copy link
Contributor Author

@BlairCurrey BlairCurrey Feb 22, 2024

Choose a reason for hiding this comment

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

As for the id change:

  1. figured it was correct to loosen it to any sort of id (not necessarily uuid) after discussing with Max. Thinking was that while we use uuid's in rafiki this is really a detail which might vary from implementation to implementation and it shouldn't (I think) matter what sort of id scheme the api implementation uses. More opinions welcome.

  2. I changed it to match anything but perhaps chars/numbers only would be better? I just wasn't sure about forbidding the use of query variables and such. While we don't support anything like this I don't know that we should have an opinion against it: incoming-payments/123?something=1

Copy link
Contributor

Choose a reason for hiding this comment

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

I think matching anything is fine in this case

@BlairCurrey
Copy link
Contributor Author

BlairCurrey commented Feb 28, 2024

⚠️ No Changeset found

Latest commit: e10f069
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR

Note: I purposefully did not add a changeset. This only changes the schema (and a test). Can just use the fetch-schemas script in rafiki to get these changes.

Looks like I was wrong about this and do need to version bump open-payments because the response validator uses the schema from this repo. I noticed while using the client in Rafiki. I manually patched the regex in rafiki/openapi/schemas.yml and that fixed the request validation error but I got the same error during response validation. Manually patching the schema in node_modules fixed that.

@mkurapov do you happen to know off the top of your head why we pass in a spec but also refer to a different internal one like this? It just seems like we would either do one or the other.

@mkurapov
Copy link
Contributor

@BlairCurrey re:

@mkurapov do you happen to know off the top of your head why we pass in a spec but also refer to a different internal one like this? It just seems like we would either do one or the other.

What do you mean by pass in a spec here?

openapi/schemas.yaml Outdated Show resolved Hide resolved
Comment on lines 261 to 265
test.each`
body | message | description
${{ receiver: 'ht999tp://something.com/incoming-payments' }} | ${'body.receiver must match pattern "^(https|http):..(.+).incoming-payments.(.+)$"'} | ${'invalid receiver, unknown protocol'}
${{ receiver: 'http://something.com/incoming-payments' }} | ${'body.receiver must match pattern "^(https|http):..(.+).incoming-payments.(.+)$"'} | ${'invalid receiver, missing incoming payment id'}
${{ receiver: 'http://something.com/connections/c3a0d182-b221-4612-a500-07ad106b5f5d' }} | ${'body.receiver must match pattern "^(https|http):..(.+).incoming-payments.(.+)$"'} | ${'invalid receiver, wrong path'}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would be good to have one happy path case

Copy link
Contributor

Choose a reason for hiding this comment

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

... In a separate test block, so that we can just hardcode the 'body.receiver must match pattern "^(https|http):..(.+).incoming-payments.(.+)$"' error message in the result without needing it in the test.each part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make some happy-path tests in a new test group.

Im not necessarily against hardcoding the message here but just want to note that the test is for the quote resource in general and could be extended to validate different fields which would require parameterizing the message like this, like the existing tests do for /incoming-payments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed message param and added happy path cases

@@ -42,10 +42,11 @@ components:
type: string
description: The URL of the incoming payment or ILP STREAM connection that is being paid.
format: uri
pattern: '^https://(.+)/(incoming-payments|connections)/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
pattern: '^(https|http)://(.+)/incoming-payments/(.+)$'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think matching anything is fine in this case

@BlairCurrey
Copy link
Contributor Author

@BlairCurrey re:

@mkurapov do you happen to know off the top of your head why we pass in a spec but also refer to a different internal one like this? It just seems like we would either do one or the other.

What do you mean by pass in a spec here?

What I meant was passing in a spec when creating the client in rafiki, but after a more careful reading I see that is not whats happening.

I guess what I was seeing was not a validation error from the client but from the backend route's validator middleware. Which makes sense. So I take back that concern - was just confusion on my end.

Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

LGTM but make sure to get someone else's eyes on this as well 👍

@BlairCurrey BlairCurrey merged commit fe18cd0 into main Mar 1, 2024
11 checks passed
@BlairCurrey BlairCurrey deleted the bc/429/update-receiver-regex branch March 1, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update receiver regex to allow http and other fixes
3 participants