-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jwt): allow all numbers in jwt token type names (#511)
* 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
- Loading branch information
1 parent
e62d7af
commit b3e22d6
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/postgraphql/schema/auth/__tests__/getPgTokenTypeFromIdentifier-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import withPgClient from '../../../../__tests__/utils/withPgClient' | ||
import introspectDatabase from '../../../../postgres/introspection/introspectDatabase' | ||
import getPgTokenTypeFromIdentifier from '../getPgTokenTypeFromIdentifier' | ||
|
||
// good names start with a letter or underscore and may also contain numbers after position 0 | ||
// note: names that start with a number must be escaped with double quotes | ||
const validNames = [ | ||
'_test', '0_test', 'test_0', '9_test', 'test_9', | ||
] | ||
|
||
validNames.forEach(validName => { | ||
test(`Valid schema name ${validName} and its jwt_token type should create without error and pass validation`, withPgClient(async client => { | ||
let query = 'not an error' | ||
|
||
try { | ||
query = await client.query(`create schema "${validName}"; create type "${validName}"."jwt_token" as (role text, exp integer, a integer, b integer, c integer)`) | ||
} catch (e) { | ||
query = e | ||
} | ||
|
||
expect(query).not.toBeInstanceOf(Error) | ||
|
||
let catalog = await introspectDatabase(client, [validName]) | ||
let tokenType = getPgTokenTypeFromIdentifier(catalog, `"${validName}"."jwt_token"`) | ||
|
||
expect(tokenType.name).toBe('jwt_token') | ||
})) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters