forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpoint.test.ts
137 lines (122 loc) · 3.24 KB
/
checkpoint.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { jestContext } from '@prisma/get-platform'
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(`
[
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(`
[
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(`
[
init,
--url=[redacted],
]
`)
})
it('should redact a SQLite connection string', () => {
expect(redactCommandArray(['init', '--url', '"file:./dev.db"'])).toMatchInlineSnapshot(`
[
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(`
[
init,
--url=[redacted],
]
`)
})
it('should redact a path with for example --schema', () => {
expect(redactCommandArray(['cmd', '--schema', '../../../../directory/my_schema.prisma'])).toMatchInlineSnapshot(`
[
cmd,
--schema,
[redacted],
]
`)
})
it('should redact a name with for example --name', () => {
expect(redactCommandArray(['cmd', '--name', '1234_my_name'])).toMatchInlineSnapshot(`
[
cmd,
--name,
[redacted],
]
`)
})
it('should read data from Prisma schema', async () => {
ctx.fixture('checkpoint-read-schema')
await expect(tryToReadDataFromSchema('./schema.prisma')).resolves.toMatchInlineSnapshot(`
{
schemaGeneratorsProviders: [
prisma-client-js,
something,
],
schemaPreviewFeatures: [
extendedIndexes,
],
schemaProvider: sqlite,
}
`)
})
it('should redact token from Platform commands', () => {
expect(redactCommandArray(['platform', '--token="foo"'])).toMatchInlineSnapshot(`
[
platform,
--token=[redacted],
]
`)
})
it('should redact a database url from Platform accelerate enable command', () => {
expect(redactCommandArray(['platform', 'accelerate', 'enable', '--url="foo"'])).toMatchInlineSnapshot(`
[
platform,
accelerate,
enable,
--url=[redacted],
]
`)
})