Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): refactor checkpoint call and sanitize options (#12908)
- Loading branch information
Showing
4 changed files
with
334 additions
and
71 deletions.
There are no files selected for viewing
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,118 @@ | ||
import { jestContext } from '@prisma/sdk' | ||
|
||
import { redactCommandArray, SENSITIVE_CLI_OPTIONS, tryToReadDataFromSchema } from '../utils/checkpoint' | ||
|
||
const ctx = jestContext.new().assemble() | ||
|
||
it('should redact --option [value]', () => { | ||
for (const option of SENSITIVE_CLI_OPTIONS) { | ||
expect(redactCommandArray(['cmd', option, 'secret'])).toEqual(['cmd', option, '[redacted]']) | ||
} | ||
}) | ||
|
||
it('should redact --option=[value]', () => { | ||
for (const option of SENSITIVE_CLI_OPTIONS) { | ||
expect(redactCommandArray(['cmd', `${option}=secret`])).toEqual(['cmd', `${option}=[redacted]`]) | ||
} | ||
}) | ||
|
||
it('should redact a PostgreSQL connection string', () => { | ||
expect(redactCommandArray(['init', '--url', '"postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"'])) | ||
.toMatchInlineSnapshot(` | ||
Array [ | ||
init, | ||
--url, | ||
[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a MySQL connection string', () => { | ||
expect( | ||
redactCommandArray([ | ||
'init', | ||
`--url "mysql://janedoe:mypassword@localhost:3306/mydb?connection_limit=5&socket_timeout"`, | ||
]), | ||
).toMatchInlineSnapshot(` | ||
Array [ | ||
init, | ||
--url=[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a MongoDB connection string', () => { | ||
expect( | ||
redactCommandArray([ | ||
'init', | ||
`--url "mongodb+srv://root:<password>@cluster0.ab1cd.mongodb.net/myDatabase?retryWrites=true&w=majority"`, | ||
]), | ||
).toMatchInlineSnapshot(` | ||
Array [ | ||
init, | ||
--url=[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a SQLite connection string', () => { | ||
expect(redactCommandArray(['init', '--url', '"file:./dev.db"'])).toMatchInlineSnapshot(` | ||
Array [ | ||
init, | ||
--url, | ||
[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a SQL Server connection string', () => { | ||
expect( | ||
redactCommandArray([ | ||
'init', | ||
`--url="sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;"`, | ||
]), | ||
).toMatchInlineSnapshot(` | ||
Array [ | ||
init, | ||
--url=[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a path with for example --schema', () => { | ||
expect(redactCommandArray(['cmd', '--schema', '../../../../directory/my_schema.prisma'])).toMatchInlineSnapshot(` | ||
Array [ | ||
cmd, | ||
--schema, | ||
[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should redact a name with for example --name', () => { | ||
expect(redactCommandArray(['cmd', '--name', '1234_my_name'])).toMatchInlineSnapshot(` | ||
Array [ | ||
cmd, | ||
--name, | ||
[redacted], | ||
] | ||
`) | ||
}) | ||
|
||
it('should read data from Prisma schema', async () => { | ||
ctx.fixture('checkpoint-read-schema') | ||
|
||
await expect(tryToReadDataFromSchema('./schema.prisma')).resolves.toMatchInlineSnapshot(` | ||
Object { | ||
schemaGeneratorsProviders: Array [ | ||
prisma-client-js, | ||
something, | ||
], | ||
schemaPreviewFeatures: Array [ | ||
extendedIndexes, | ||
cockroachdb, | ||
], | ||
schemaProvider: sqlite, | ||
} | ||
`) | ||
}) |
18 changes: 18 additions & 0 deletions
18
packages/cli/src/__tests__/fixtures/checkpoint-read-schema/schema.prisma
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,18 @@ | ||
datasource my_db { | ||
provider = "sqlite" | ||
url = env("SQLITE_URL") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["extendedIndexes", "cockroachdb"] | ||
} | ||
|
||
generator something { | ||
provider = "something" | ||
} | ||
|
||
model Blog { | ||
id Int @id | ||
viewCount Int | ||
} |
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
Oops, something went wrong.