Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ui-debug.log
.DS_Store
functions/lib
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.1.6

Hardened parameterized path validation (reject empty segments; return callable-safe errors), upgraded the function runtime to Node.js 22, and modernized dependencies.

## Version 0.1.5

Added input validation for parameterized paths to enforce segment integrity.
Expand Down
4 changes: 2 additions & 2 deletions extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

name: firestore-bundle-builder
specVersion: v1beta
version: 0.1.5
version: 0.1.6
license: Apache-2.0

displayName: Firestore Bundle Builder
Expand Down Expand Up @@ -49,7 +49,7 @@ resources:
properties:
location: us-central1
httpsTrigger: {}
runtime: "nodejs14"
runtime: "nodejs22"

# Learn about the `params` field in the docs
params:
Expand Down
37 changes: 32 additions & 5 deletions functions/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
*/

import { buildQuery, parameterizePath } from "../src/build_bundle";
import { HttpsError } from "firebase-functions/v1/https";
import * as admin from "firebase-admin";

describe("buildQuery", () => {
let db: admin.firestore.Firestore;
beforeEach(() => {
db = admin.initializeApp({ projectId: "demo-experimental" }).firestore();
if (admin.apps.length === 0) {
admin.initializeApp({ projectId: "demo-experimental" });
}
db = admin.firestore();
});

xit("should build expected queries", () => {
it("should build expected queries", () => {
const queries: [admin.firestore.Query, admin.firestore.Query][] = [
[
buildQuery(db, { collection: "test-coll", conditions: [] }, {}, {}),
Expand Down Expand Up @@ -170,14 +174,37 @@ describe("parameterizePath", () => {
expect(res).toEqual("stores/austin/products");
});

it("should throw an error when parameter values contain forward slashes", () => {
it("should throw when parameter values contain forward slashes", () => {
expect(() =>
parameterizePath(
"stores/$city/products",
{ city: { type: "string", required: true } },
{ city: "austin/private/salaries" }
)
).toThrow("Invalid path segment parameter: cannot contain '/'");
).toThrow(HttpsError);
});
});

it("should throw when a path parameter is missing or empty", () => {
expect(() =>
parameterizePath(
"users/$uid/friends/$friend",
{
uid: { type: "string" },
friend: { type: "string" },
},
{}
)
).toThrow(HttpsError);

expect(() =>
parameterizePath(
"users/$uid/friends/$friend",
{
uid: { type: "string" },
friend: { type: "string" },
},
{ uid: "user1", friend: "" }
)
).toThrow(HttpsError);
});
});
12 changes: 7 additions & 5 deletions functions/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
const packageJson = require("./package.json");

module.exports = {
name: packageJson.name,
displayName: packageJson.name,
rootDir: "./",
preset: "ts-jest",
globals: {
"ts-jest": {
tsConfig: "<rootDir>/__tests__/tsconfig.json",
},
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: "<rootDir>/__tests__/tsconfig.json",
},
],
},
testMatch: ["**/__tests__/*.test.ts"],
testEnvironment: "node",
Expand Down
Loading