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 JSON API conditions #602

Merged
merged 2 commits into from
Nov 7, 2024
Merged

Conversation

theref
Copy link
Contributor

@theref theref commented Nov 7, 2024

Context params where not being parsed from endpoint, query, or authToken. This PR fixes those issues and adds a test

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (epic-v0.6.x@6b8184f). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             epic-v0.6.x     #602   +/-   ##
==============================================
  Coverage               ?   89.27%           
==============================================
  Files                  ?       73           
  Lines                  ?     6545           
  Branches               ?      351           
==============================================
  Hits                   ?     5843           
  Misses                 ?      664           
  Partials               ?       38           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* would match 0 - infinity

Co-authored-by: KPrasch <[email protected]>
Copy link
Member

@KPrasch KPrasch left a comment

Choose a reason for hiding this comment

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

LGTM!

@KPrasch KPrasch merged commit 63b0352 into nucypher:epic-v0.6.x Nov 7, 2024
4 checks passed
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

@theref - left some additional RFCs still needed even though this PR was already merged.

Please follow-up on those.

Side note: are releases necessary? A different option is to use local dependency installations and make fixes locally as you need, and then do one PR into the EPIC.
eg.
$ npm install <path_to_local_taco_web>/taco-web/packages/taco
$ npm install <path_to_local_taco_web>/taco-web/packages/taco-auth

Of course, pnpm can be used instead of npm depending on what the demo you are testing with uses.

This would prevent needing to do a release after every fix you make.

}
}
}
if (this.isContextParameter(condition.authorizationToken)) {
Copy link
Member

Choose a reason for hiding this comment

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

An authorizationToken is optional and can only be a context parameter.

Suggested change
if (this.isContextParameter(condition.authorizationToken)) {
if (condition.authorizationToken) {

}
}
if (condition.query) {
const queryParams = condition.query.match(":[a-zA-Z_]+");
Copy link
Member

Choose a reason for hiding this comment

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

There is an existing regex for context variables - CONTEXT_PARAM_REGEXP in const.ts that you can use. You should use that one instead. Context parameters allow numbers to be in the string (just not the first character).

Copy link
Member

@KPrasch KPrasch Nov 7, 2024

Choose a reason for hiding this comment

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

@theref discovered some nuance in the existing regex (CONTEXT_PARAM_REGEXP) that does not fully cover the Json API condition use case. In particular the CONTEXT_PARAM_REGEXP enforces that the pattern must match at the start of a string (^), however, it's possible that a context parameter may appear as a substring in the middle of an endpoint (for example https://example.com/:userAddress/balance). We think this is specific to the case of JSON API conditions, but let us know if you think otherwise.

Copy link
Member

@KPrasch KPrasch Nov 7, 2024

Choose a reason for hiding this comment

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

I'd also like to point out a few other concerns I have about CONTEXT_PARAM_REGEXP : ^:[a-zA-Z_][a-zA-Z0-9_]*$:

  • The usage of the * character here permits matching zero tokens, which means that a simple : will match positively. Instead this can be a + to match one or more tokens.
  • Are we intending to support purely numeric context params?

Copy link
Member

@derekpierre derekpierre Nov 7, 2024

Choose a reason for hiding this comment

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

There are two context regexes in const.ts.

  • CONTEXT_PARAM_REGEXP - matches a regex without expecting it to be at the beginning of the string i.e. no caret.
  • CONTEXT_PARAM_FULL_MATCH_REGEXP - expects the entire string to be a context variable

I believe (?) the first one should be sufficient here.

Copy link
Member

@derekpierre derekpierre Nov 7, 2024

Choose a reason for hiding this comment

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

I'd also like to point out that there is a small bug in CONTEXT_PARAM_REGEXP : ^:[a-zA-Z_][a-zA-Z0-9_]*$. The usage of the * character here permits matching zero tokens, which means that a simple : will match positively.

It's subtle, but the [a-zA-Z_] part (first block) ensures that the context variable starts with a letter or underscore, the rest of regex allows the remaining characters to be a letter, number, or underscore.

Copy link
Member

Choose a reason for hiding this comment

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

It's subtle, but the [a-zA-Z_] part (first block) ensures that the context variable starts with a letter or underscore, the rest of regex allows the remaining characters to be a letter, number, or underscore.

Ah yes, you are correct!

Copy link
Member

Choose a reason for hiding this comment

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

There are two context regexes in const.ts.

  • CONTEXT_PARAM_REGEXP - matches a regex without expecting it to be at the beginning of the string i.e. no caret.
  • CONTEXT_PARAM_FULL_MATCH_REGEXP - expects the entire string to be a context variable

I believe (?) the first one should be sufficient here.

Hmm, perhaps it's in another branch? I don't see two, only CONTEXT_PARAM_REGEXP in const.ts

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yep - that looks suitable.

@derekpierre
Copy link
Member

PS. Nice find @theref - this was definitely missing code in the requested parameters logic.

@derekpierre derekpierre mentioned this pull request Nov 8, 2024
20 tasks
derekpierre added a commit to derekpierre/taco-web that referenced this pull request Dec 18, 2024
@derekpierre derekpierre mentioned this pull request Dec 18, 2024
7 tasks
theref added a commit that referenced this pull request Dec 19, 2024
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.

4 participants