bobbai00 commented on code in PR #5751:
URL: https://github.com/apache/texera/pull/5751#discussion_r3447769626


##########
agent-service/src/auth/jwt.test.ts:
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { extractUserFromToken, validateToken, createAuthHeaders } from "./jwt";
+
+function makeToken(payload: Record<string, unknown>): string {
+  const encode = (o: Record<string, unknown>) => 
Buffer.from(JSON.stringify(o)).toString("base64");
+  return `${encode({ alg: "none", typ: "JWT" })}.${encode(payload)}.signature`;

Review Comment:
   Done in 5293215b: `makeToken` now encodes the segments with base64url 
instead of base64, and there is an added case whose payload contains `-`/`_` to 
pin the url-safe decoding path.



##########
agent-service/src/auth/jwt.test.ts:
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { extractUserFromToken, validateToken, createAuthHeaders } from "./jwt";

Review Comment:
   Added in 5293215b: a new `extractBearerToken` describe block covers a valid 
Bearer header, case-insensitive scheme, a non-Bearer scheme, a missing token, 
and an absent header.



##########
agent-service/src/auth/jwt.test.ts:
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { extractUserFromToken, validateToken, createAuthHeaders } from "./jwt";
+
+function makeToken(payload: Record<string, unknown>): string {
+  const encode = (o: Record<string, unknown>) => 
Buffer.from(JSON.stringify(o)).toString("base64");
+  return `${encode({ alg: "none", typ: "JWT" })}.${encode(payload)}.signature`;
+}
+
+const nowSeconds = () => Math.floor(Date.now() / 1000);
+
+describe("extractUserFromToken", () => {
+  test("maps JWT claims onto a UserInfo", () => {
+    const token = makeToken({ userId: 7, sub: "alice", email: 
"[email protected]", role: "ADMIN" });
+    expect(extractUserFromToken(token)).toEqual({ uid: 7, name: "alice", 
email: "[email protected]", role: "ADMIN" });
+  });
+
+  test("defaults missing email and role", () => {
+    const token = makeToken({ userId: 1, sub: "bob" });
+    expect(extractUserFromToken(token)).toEqual({ uid: 1, name: "bob", email: 
"", role: "REGULAR" });
+  });
+
+  test("throws on a malformed token", () => {
+    expect(() => extractUserFromToken("not-a-jwt")).toThrow("Failed to decode 
JWT");
+  });
+});
+
+describe("validateToken", () => {
+  test("accepts a token expiring in the future", () => {
+    expect(validateToken(makeToken({ sub: "a", exp: nowSeconds() + 3600 
}))).toBe(true);
+  });
+
+  test("rejects an expired token", () => {
+    expect(validateToken(makeToken({ sub: "a", exp: nowSeconds() - 3600 
}))).toBe(false);
+  });
+
+  test("treats a token without exp as valid", () => {
+    expect(validateToken(makeToken({ sub: "a" }))).toBe(true);
+  });
+
+  test("rejects a malformed token", () => {
+    expect(validateToken("garbage")).toBe(false);
+  });
+});
+
+describe("createAuthHeaders", () => {
+  test("builds bearer auth headers", () => {
+    expect(createAuthHeaders("tok")).toEqual({ Authorization: "Bearer tok", 
"Content-Type": "application/json" });
+  });
+});

Review Comment:
   Added in 5293215b: see the new `extractBearerToken` tests (valid Bearer, 
case-insensitive scheme, wrong scheme, missing token, absent header).



##########
agent-service/src/types/api.ts:
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Wire DTOs: request/response bodies exchanged with backend services and the
+// WebSocket frames this service sends to its own clients. Distinct from domain
+// types (workflow.ts, execution.ts, agent.ts) which model in-memory state.
+
+import type { WorkflowContent, OperatorPortSchemaMap } from "./workflow";
+import type { ReActStep } from "./agent";
+
+// --- Dashboard Service: workflow persistence ---
+
+export interface Workflow {
+  wid: number;
+  name: string;
+  description?: string;
+  content: WorkflowContent;
+  creationTime?: number;
+  lastModifiedTime?: number;
+  isPublished?: boolean;
+}
+
+export interface WorkflowPersistRequest {
+  wid?: number;
+  name: string;
+  description?: string;
+  content: string;
+  isPublic?: boolean;
+}
+
+// --- Workflow Compiling Service ---
+
+export interface WorkflowFatalError {
+  message: string;
+  details: string;
+  operatorId: string;
+  workerId: string;
+  type: { name: string };
+  timestamp: { nanos: number; seconds: number };
+}
+
+export interface WorkflowCompilationResponse {
+  physicalPlan?: any;
+  operatorOutputSchemas: Record<string, OperatorPortSchemaMap>;
+  operatorErrors: Record<string, WorkflowFatalError>;
+}

Review Comment:
   Resolved in afae9957: `types/api.ts` was split into `types/wire.ts` (backend 
DTOs) and `types/ws.ts` (this service's WebSocket frames). The duplicate 
`WorkflowFatalError` is gone — there is now a single definition in 
`types/wire.ts`, corrected to match the backend proto 
(`workflowruntimestate.proto`): `type` is the `FatalErrorType` enum name 
(string), with `details`/`operatorId`/`workerId`/`timestamp` optional. 
`api/compile-api.ts` and its consumers (`context-utils.ts`, `texera-agent.ts`) 
now import that single canonical type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to