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

allow all numbers in jwt token type names #511

Merged
merged 6 commits into from
Jul 14, 2017

Conversation

gkchestertron
Copy link
Contributor

currently naming of the jwt_token type, as in the tutorial/example only allows for names that contain the numbers 1 and 2. I'm using this for multiple PTA organizations and would like to keep consistent naming and identify them by their district number (i.e. pta_dist_14.jwt_token).

This fixes the issue - but I am unsure if there was a good reason that only 1 and two were allowed before.

@benjie
Copy link
Member

benjie commented Jul 11, 2017

O_o this seems weird; surely that'd have to be deliberate... @calebmer any idea?

@gkchestertron
Copy link
Contributor Author

right? but I couldn't think of one.

@benjie
Copy link
Member

benjie commented Jul 12, 2017

Tracking through various levels of git blame; this is where it was originally introduced:

f8b2d42

"Type identifiers are a bit tricky, but this function uses a regular expression to do it. Fun."

Worrisome... I wonder what's tricky about them.

I had a scan through the docs and can't see any issues:

https://www.postgresql.org/docs/9.6/static/sql-createtype.html

Could you add some tests so we can be certain?

@gkchestertron
Copy link
Contributor Author

will do.

@gkchestertron
Copy link
Contributor Author

gkchestertron commented Jul 13, 2017

Let me know if I've completely missed on your conventions - I'm new to ES6, TypeScript, Jest, Travis, and ESLint. Also - sorry this is another suite of slow tests in the postgraphql space.

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

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

I think all the tests you've added should be able to be processed; I think it would be good to test (successfully): "_test", "0_test", "test_0", "9_test", "test_9" and leave it at that. The "bad" test section shouldn't be needed.

let badQuery = 'not an error'

try {
badQuery = await client.query(`create schema ${badName}; create type ${badName}.jwt_token as (role text, exp integer, a integer, b integer, c integer)`)
Copy link
Member

Choose a reason for hiding this comment

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

I think the reason this fails is just that you've not escaped the identifier with double quotes - that doesn't make it inherently invalid. Does it fail if you add double quotes?

Copy link
Member

Choose a reason for hiding this comment

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

create schema "0_test";
CREATE SCHEMA
Time: 35.303 ms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right. works fine when escaped.


// good names start with a letter or underscore and may also contain numbers after position 0
const goodNames = [
'test', 'test_0', 'test_1', 'test_2', 'test_3', 'test_4', 'test_5', 'test_6', 'test_7', 'test_8', 'test_9', '_test',
Copy link
Member

Choose a reason for hiding this comment

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

This only really needs to test edge cases, so 'test_0', 'test_9' and '_test' should suffice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough


// schema, type, etc... names are not allowed to start with numbers
const badNames = [
'0_test', '1_test', '2_test', '3_test', '4_test', '5_test', '6_test', '7_test', '8_test', '9_test',
Copy link
Member

Choose a reason for hiding this comment

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

similarly I'd only test '0_test' and '9_test'

…ping to testing of names starting with a number
Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

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

LGTM 📲

@benjie
Copy link
Member

benjie commented Jul 14, 2017

@gkchestertron Are you good for this to be merged?

@gkchestertron
Copy link
Contributor Author

gkchestertron commented Jul 14, 2017

works for me @benjie

@benjie benjie merged commit b3e22d6 into graphile:master Jul 14, 2017
Belline pushed a commit to Belline/postgraphql that referenced this pull request Dec 18, 2017
* allow all numbers in jwt token type names

* fix(postgraphql): improve jwt token type check regex and add tests for it

* fix(postgraphql): clean up bad style

* fix(postgraphql) more style fixes

* fix(postgraphql) removes unnecessary tests and adds double-quote escaping to testing of names starting with a number
benjie added a commit that referenced this pull request Sep 16, 2023
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.

2 participants