Skip to content

Commit

Permalink
ci(js): remove snaps (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
gotbadger authored Feb 22, 2024
1 parent 385d752 commit 7fba874
Show file tree
Hide file tree
Showing 279 changed files with 2,345 additions and 10,828 deletions.
2 changes: 1 addition & 1 deletion scripts/migrate_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const determine_annotations = (rule, outputs) => {

const write_annoation = (filePath, result) => {
let lines = fs.readFileSync(filePath, 'utf8').split('\n');
lines.splice(result.line_number - 1, 0, `# bearer:expected ${result.id}`);
lines.splice(result.line_number - 1, 0, `// bearer:expected ${result.id}`);
fs.writeFileSync(filePath, lines.join('\n'));
}

Expand Down

This file was deleted.

55 changes: 37 additions & 18 deletions tests/javascript/express/cross_site_scripting/test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
const { createInvoker, getEnvironment } = require("../../../helper.js")
const {
createNewInvoker,
getEnvironment,
} = require("../../../helper.js")
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname)

describe(ruleId, () => {
const invoke = createInvoker(ruleId, ruleFile, testBase)
const invoke = createNewInvoker(ruleId, ruleFile, testBase)


test("no_xss", () => {
const testCase = "no_xss.js"

const results = invoke(testCase)

test("no_xss", () => {
const testCase = "no_xss.js"
expect(invoke(testCase)).toMatchSnapshot();
})
expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})


test("res_send_xss", () => {
const testCase = "res_send_xss.js"
expect(invoke(testCase)).toMatchSnapshot();
})
test("res_send_xss", () => {
const testCase = "res_send_xss.js"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})


test("res_write_xss", () => {
const testCase = "res_write_xss.js"
expect(invoke(testCase)).toMatchSnapshot();
})
test("res_write_xss", () => {
const testCase = "res_write_xss.js"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})


test("user_input_types", () => {
const testCase = "user_input_types.ts"
expect(invoke(testCase)).toMatchSnapshot();
})
test("user_input_types", () => {
const testCase = "user_input_types.ts"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})

})
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ app.use(helmet())
app.use(helmet.hidePoweredBy())

app.get("/bad", (req, res) => {
// bearer:expected javascript_express_cross_site_scripting
res.send("<p>" + req.body.customer.name + "</p>")
})

app.get("/bad-2", (req, res) => {
// bearer:expected javascript_express_cross_site_scripting
res.send("<p>" + req.body["user_id"] + "</p>")
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ app.use(helmet.hidePoweredBy())

app.get("/bad", (req, res) => {
var customerName = req.body.customer.name
// bearer:expected javascript_express_cross_site_scripting
res.write("<h3> Greetings " + customerName + "</h3>")
})
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
// This file is indirectly testing javascript_shared_express_user_input

// bearer:expected javascript_express_cross_site_scripting
res.send(req.params.oops)

let { params } = req
let { oops } = params
let { subOops } = oops

// bearer:expected javascript_express_cross_site_scripting
res.send(params.oops)
// bearer:expected javascript_express_cross_site_scripting
res.send(oops)

const foo: Request = x
// bearer:expected javascript_express_cross_site_scripting
res.send(foo.params.oops)

const f = (x: string, foo2: Request, { params }: Request) => {
// bearer:expected javascript_express_cross_site_scripting
res.send(foo2.params.oops)
// bearer:expected javascript_express_cross_site_scripting
res.send(params.oops)
}

function(foo3: Request, { params }: Request) {
// bearer:expected javascript_express_cross_site_scripting
res.send(foo3.params.oops)
// bearer:expected javascript_express_cross_site_scripting
res.send(params.oops)
}

function f2(foo4: Request, { params }: Request) {
// bearer:expected javascript_express_cross_site_scripting
res.send(foo4.params.oops)
// bearer:expected javascript_express_cross_site_scripting
res.send(params.oops)
}


class X extends Y {
m(foo5: Request, { params }: Request) {
// bearer:expected javascript_express_cross_site_scripting
res.send(foo5.params.oops)
// bearer:expected javascript_express_cross_site_scripting
res.send(params.oops)
}
}

This file was deleted.

43 changes: 29 additions & 14 deletions tests/javascript/express/default_cookie_config/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
const { createInvoker, getEnvironment } = require("../../../helper.js")
const {
createNewInvoker,
getEnvironment,
} = require("../../../helper.js")
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname)

describe(ruleId, () => {
const invoke = createInvoker(ruleId, ruleFile, testBase)
const invoke = createNewInvoker(ruleId, ruleFile, testBase)


test("default_cookie_session_config", () => {
const testCase = "default_cookie_session_config.js"

const results = invoke(testCase)

test("default_cookie_session_config", () => {
const testCase = "default_cookie_session_config.js"
expect(invoke(testCase)).toMatchSnapshot();
})
expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})


test("default_express_session_cookie_config", () => {
const testCase = "default_express_session_cookie_config.js"
expect(invoke(testCase)).toMatchSnapshot();
})
test("default_express_session_cookie_config", () => {
const testCase = "default_express_session_cookie_config.js"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})


test("ok_cookie_configured", () => {
const testCase = "ok_cookie_configured.js"
expect(invoke(testCase)).toMatchSnapshot();
})
test("ok_cookie_configured", () => {
const testCase = "ok_cookie_configured.js"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})

})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ app.use(helmet())
app.use(helmet.hidePoweredBy())

app.use(
// bearer:expected javascript_express_default_cookie_config
cookieSession({
domain: "example.com",
httpOnly: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ app.use(helmet.hidePoweredBy())

app.use(
session({
// bearer:expected javascript_express_default_cookie_config
cookie: {},
})
)

app.use(
session({
// bearer:expected javascript_express_default_cookie_config
cookie: {
domain: "example.com",
secure: true,
Expand All @@ -26,6 +28,7 @@ app.use(

app.use(
session({
// bearer:expected javascript_express_default_cookie_config
cookie: {
domain: "example.com",
secure: true,
Expand Down
Loading

0 comments on commit 7fba874

Please sign in to comment.