Fix all tests.
This commit is contained in:
parent
0736812293
commit
478160c412
|
@ -1134,8 +1134,8 @@ class InternalBuilder {
|
||||||
if (this.client === SqlClient.ORACLE) {
|
if (this.client === SqlClient.ORACLE) {
|
||||||
query = query.orderByRaw(`?? ?? nulls ??`, [
|
query = query.orderByRaw(`?? ?? nulls ??`, [
|
||||||
this.convertClobs(composite),
|
this.convertClobs(composite),
|
||||||
direction,
|
this.knex.raw(direction),
|
||||||
nulls,
|
this.knex.raw(nulls as string),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
query = query.orderBy(composite, direction, nulls)
|
query = query.orderBy(composite, direction, nulls)
|
||||||
|
|
|
@ -61,6 +61,7 @@ describe.each([
|
||||||
const isLucene = name === "lucene"
|
const isLucene = name === "lucene"
|
||||||
const isInMemory = name === "in-memory"
|
const isInMemory = name === "in-memory"
|
||||||
const isInternal = isSqs || isLucene || isInMemory
|
const isInternal = isSqs || isLucene || isInMemory
|
||||||
|
const isOracle = name === DatabaseName.ORACLE
|
||||||
const isSql = !isInMemory && !isLucene
|
const isSql = !isInMemory && !isLucene
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
|
|
||||||
|
@ -155,24 +156,24 @@ describe.each([
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
["table", createTable],
|
["table", createTable],
|
||||||
// [
|
[
|
||||||
// "view",
|
"view",
|
||||||
// async (schema: TableSchema) => {
|
async (schema: TableSchema) => {
|
||||||
// const tableId = await createTable(schema)
|
const tableId = await createTable(schema)
|
||||||
// const viewId = await createView(
|
const viewId = await createView(
|
||||||
// tableId,
|
tableId,
|
||||||
// Object.keys(schema).reduce<ViewV2Schema>((viewSchema, fieldName) => {
|
Object.keys(schema).reduce<ViewV2Schema>((viewSchema, fieldName) => {
|
||||||
// const field = schema[fieldName]
|
const field = schema[fieldName]
|
||||||
// viewSchema[fieldName] = {
|
viewSchema[fieldName] = {
|
||||||
// visible: field.visible ?? true,
|
visible: field.visible ?? true,
|
||||||
// readonly: false,
|
readonly: false,
|
||||||
// }
|
}
|
||||||
// return viewSchema
|
return viewSchema
|
||||||
// }, {})
|
}, {})
|
||||||
// )
|
)
|
||||||
// return viewId
|
return viewId
|
||||||
// },
|
},
|
||||||
// ],
|
],
|
||||||
])("from %s", (sourceType, createTableOrView) => {
|
])("from %s", (sourceType, createTableOrView) => {
|
||||||
const isView = sourceType === "view"
|
const isView = sourceType === "view"
|
||||||
|
|
||||||
|
@ -3472,54 +3473,69 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("SQL injection", () => {
|
isSql &&
|
||||||
const badStrings = [
|
describe("SQL injection", () => {
|
||||||
"1; DROP TABLE test;",
|
const badStrings = [
|
||||||
"1; DELETE FROM test;",
|
"1; DROP TABLE test;",
|
||||||
"1; UPDATE test SET name = 'foo';",
|
"1; DELETE FROM test;",
|
||||||
"1; INSERT INTO test (name) VALUES ('foo');",
|
"1; UPDATE test SET name = 'foo';",
|
||||||
"' OR '1'='1' --",
|
"1; INSERT INTO test (name) VALUES ('foo');",
|
||||||
"'; DROP TABLE users; --",
|
"' OR '1'='1' --",
|
||||||
"' OR 1=1 --",
|
"'; DROP TABLE users; --",
|
||||||
"' UNION SELECT null, null, null; --",
|
"' OR 1=1 --",
|
||||||
"' AND (SELECT COUNT(*) FROM users) > 0 --",
|
"' UNION SELECT null, null, null; --",
|
||||||
"\"; EXEC xp_cmdshell('dir'); --",
|
"' AND (SELECT COUNT(*) FROM users) > 0 --",
|
||||||
"\"' OR 'a'='a",
|
"\"; EXEC xp_cmdshell('dir'); --",
|
||||||
"OR 1=1;",
|
"\"' OR 'a'='a",
|
||||||
"'; SHUTDOWN --",
|
"OR 1=1;",
|
||||||
]
|
"'; SHUTDOWN --",
|
||||||
|
]
|
||||||
|
|
||||||
describe.only.each(badStrings)("bad string: %s", badString => {
|
describe.each(badStrings)("bad string: %s", badString => {
|
||||||
it("should not allow SQL injection as a field name", async () => {
|
// The SQL that knex generates when you try to use a double quote in a
|
||||||
const tableOrViewId = await createTableOrView({
|
// field name is always invalid and never works, so we skip it for these
|
||||||
[badString]: {
|
// tests.
|
||||||
name: badString,
|
const skipFieldNameCheck = isOracle && badString.includes('"')
|
||||||
type: FieldType.STRING,
|
|
||||||
},
|
!skipFieldNameCheck &&
|
||||||
|
it("should not allow SQL injection as a field name", async () => {
|
||||||
|
const tableOrViewId = await createTableOrView({
|
||||||
|
[badString]: {
|
||||||
|
name: badString,
|
||||||
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await config.api.row.save(tableOrViewId, { [badString]: "foo" })
|
||||||
|
|
||||||
|
const { rows } = await config.api.row.search(
|
||||||
|
tableOrViewId,
|
||||||
|
{ query: {} },
|
||||||
|
{ status: 200 }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(rows).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not allow SQL injection as a field value", async () => {
|
||||||
|
const tableOrViewId = await createTableOrView({
|
||||||
|
foo: {
|
||||||
|
name: "foo",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await config.api.row.save(tableOrViewId, { foo: "foo" })
|
||||||
|
|
||||||
|
const { rows } = await config.api.row.search(
|
||||||
|
tableOrViewId,
|
||||||
|
{ query: { equal: { foo: badString } } },
|
||||||
|
{ status: 200 }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(rows).toBeEmpty()
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.api.row.search(
|
|
||||||
tableOrViewId,
|
|
||||||
{ query: {} },
|
|
||||||
{ status: 200 }
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should not allow SQL injection as a field value", async () => {
|
|
||||||
const tableOrViewId = await createTableOrView({
|
|
||||||
foo: {
|
|
||||||
name: "foo",
|
|
||||||
type: FieldType.STRING,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await config.api.row.search(
|
|
||||||
tableOrViewId,
|
|
||||||
{ query: { equal: { foo: badString } } },
|
|
||||||
{ status: 200 }
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue