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(backend): make the rafiki wallet url case insensitive #2833

Merged
merged 18 commits into from
Sep 18, 2024

Conversation

s100tist
Copy link
Contributor

@s100tist s100tist commented Aug 1, 2024

Changes proposed in this pull request

Converting the wallet address to lower case when it get stored
Making the getWalletAddres middleware methods looking for a wallet addres url converted to lower case

Context

When a wallet address is created, the wallet address gets stored in the database as it was written originally.
This causes undesired beheaviour such as 'wallet address not found' being raised due to the case sensitiveness.

This PR fixes issue #2815

Checklist

  • Related issues linked using fixes #number
  • Make sure that all checks pass

s100tist and others added 2 commits July 19, 2024 15:31
…es/backend/src/graphql/resolvers/wallet_address.ts). middleware.ts in packages/backend/src/open_payments/wallet_address/middleware.ts modified to look up for the walletaddress url in a case insensitive way.
Copy link

netlify bot commented Aug 1, 2024

Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit 53b0c8c
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/66eae5cdda3e320008d858c1

@github-actions github-actions bot added pkg: backend Changes in the backend package. type: source Changes business logic labels Aug 1, 2024
@golobitch golobitch changed the title Fix (Backend): Make the rafiki wallet url case insensitive fix(backend): Make the rafiki wallet url case insensitive Aug 15, 2024
@golobitch golobitch changed the title fix(backend): Make the rafiki wallet url case insensitive fix(backend): make the rafiki wallet url case insensitive Aug 15, 2024
@golobitch
Copy link
Collaborator

@s100tist CI prerequisite job is failing due to code format. Please run pnpm format and then commit & push changes.

@@ -15,23 +15,24 @@ export async function getWalletAddressUrlFromRequestBody(
ctx: SignedCollectionContext<CreateBody>,
next: () => Promise<void>
) {
ctx.walletAddressUrl = ctx.request.body.walletAddress
ctx.walletAddressUrl = ctx.request.body.walletAddress.toLowerCase()
Copy link
Contributor

@mkurapov mkurapov Aug 19, 2024

Choose a reason for hiding this comment

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

Instead of doing this all over, we can just do .toLowerCase in during creation (walletAddressService.create) and when we fetch it by url (getWalletAddressByUrl)

ie, as close to the DB as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I correctly understood it would be better to discard the packages/backend/src/open_payments/wallet_address/middleware.ts and packages/backend/src/graphql/resolvers/wallet_address.ts changes and better lowercase inside packages/backend/src/open_payments/wallet_address/service.ts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mkurapov maybe going a little bit further, but probably one very neat solution would be to use GraphQL directive for this kind of things?

Our input object would then look like this

input CreateWalletAddressInput {
  "Asset of the wallet address"
  assetId: String!
  "Wallet Address URL"
  url: String! @lower
  "Public name associated with the wallet address"
  publicName: String
  "Unique key to ensure duplicate or retried requests are processed only once. See [idempotence](https://en.wikipedia.org/wiki/Idempotence)"
  idempotencyKey: String
  "Additional properties associated with the [walletAddress]."
  additionalProperties: [AdditionalPropertyInput!]
}

Notice that @lower? With this kind of directive we would make sure that we always get lower case url in the request.

So the only question would be getWalletAddressByUrl right? If I am not mistaken this gets called only when we create receiver right or with other words, it is only getting called from GraphQL not Rest right? In that case, we can also add directive to that field.

Instead of doing this thing manually as close to the database as possible we would have lowercase url since the beginning and it would be the same as if user were inputing url in lower case.

But maybe this is too much for this ticket?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tadejgolobic

That's quite a nice solution actually, and we probably have a few opportunities where we could leverage GQL directives more.

For this case though, I think it makes sense to keep this in the service/domain layer because no matter the interface/API used to create wallet addresses, we always have this baked into the logic before we create the wallet address

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tadejgolobic would this change not be retroactive? I mean the already created wallets will not be found.

Assuming that you mean admin API instead of GraphQL. Yes, the getWalletAddressByUrl is geting called from the admin API and the rest (open payments>get method)

@s100tist s100tist requested a review from mkurapov August 21, 2024 14:51
@s100tist s100tist marked this pull request as draft August 21, 2024 15:00
@s100tist s100tist marked this pull request as ready for review August 21, 2024 15:29
@s100tist s100tist requested a review from mkurapov August 29, 2024 07:25
@@ -166,7 +166,7 @@ async function createWalletAddress(

return await WalletAddress.query(deps.knex)
.insertGraphAndFetch({
url: options.url,
url: options.url.toLowerCase(),
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add some tests for these :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@s100tist
in the catch statement, you can check for err instanceof UniqueViolationError to catch those cases where you are trying to create a duplicate wallet address

@github-actions github-actions bot added the type: tests Testing related label Sep 4, 2024
@mkurapov mkurapov linked an issue Sep 10, 2024 that may be closed by this pull request
1 task
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.

🚀

@mkurapov mkurapov merged commit 9a7eed9 into interledger:main Sep 18, 2024
30 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure wallet addresses are case insensitive
3 participants