Skip to content

Commit d1a0250

Browse files
committed
Fix BetterSQLite3 tests, cleanup
1 parent 9117aa5 commit d1a0250

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

library/agent/hooks/instrumentation/injectedFunctions.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { getInstance } from "../../AgentSingleton";
22
import { getContext } from "../../Context";
33
import { inspectArgs } from "../wrapExport";
44
import { getPackageCallbackInfo } from "./instructions";
5-
import { getBuiltinModuleWithoutPatching } from "./processGetBuiltin";
65

76
export function __instrumentInspectArgs(
87
id: string,
@@ -118,7 +117,3 @@ export function __instrumentModifyReturnValue(
118117

119118
return returnValue;
120119
}
121-
122-
export function __getBuiltinModuleWithoutPatching(id: string) {
123-
return getBuiltinModuleWithoutPatching(id);
124-
}

library/agent/hooks/instrumentation/instructions.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ t.test("it works using injected functions", async (t) => {
178178
[],
179179
this
180180
);
181+
__instrumentModifyReturnValue(
182+
"foo.bar.js.bazABCDEF.MethodDefinition.^1.0.0",
183+
[1, 2, 3],
184+
"42",
185+
this
186+
);
181187
t.equal(pkgInspectArgsCalled, false);
182188
t.equal(pkgModifyArgsCalled, false);
183189
t.equal(pkgModifyReturnValueCalled, false);
@@ -209,6 +215,12 @@ t.test("it works using injected functions", async (t) => {
209215
[],
210216
this
211217
);
218+
__instrumentModifyReturnValue(
219+
"foo.bar.js.bazABCDEF.MethodDefinition.^1.0.0",
220+
[1, 2, 3],
221+
"42",
222+
this
223+
);
212224
t.equal(pkgInspectArgsCalled, false);
213225
t.equal(pkgModifyArgsCalled, false);
214226
t.equal(pkgModifyReturnValueCalled, false);

library/helpers/createTestAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export function createTestAgent(opts?: {
1717
token?: Token;
1818
serverless?: string;
1919
suppressConsoleLog?: boolean;
20-
newInstrumentation?: boolean;
2120
}) {
2221
if (opts?.suppressConsoleLog ?? true) {
2322
wrap(console, "log", function log() {
@@ -30,8 +29,7 @@ export function createTestAgent(opts?: {
3029
opts?.logger ?? new LoggerNoop(),
3130
opts?.api ?? new ReportingAPIForTesting(),
3231
opts?.token, // Defaults to undefined
33-
opts?.serverless, // Defaults to undefined
34-
opts?.newInstrumentation ?? false
32+
opts?.serverless // Defaults to undefined
3533
);
3634

3735
setInstance(agent);

library/sinks/BetterSQLite3.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ t.test("it detects SQL injections", async (t) => {
110110
});
111111

112112
await runWithContext(dangerousPathContext, async () => {
113-
const error = t.throws(() => db.backup("/tmp/insecure"));
114-
t.ok(error instanceof Error);
115-
if (error instanceof Error) {
113+
try {
114+
await db.backup("/tmp/insecure");
115+
t.fail("Expected an error");
116+
} catch (error: any) {
116117
t.same(
117118
error.message,
118119
"Zen has blocked a path traversal attack: better-sqlite3.backup(...) originating from body.myTitle"
119120
);
120121
}
122+
121123
await db.backup("/tmp/sqlite-test-secure");
122124
});
123125

0 commit comments

Comments
 (0)