Yicong-Huang commented on code in PR #5274: URL: https://github.com/apache/texera/pull/5274#discussion_r3366121762
########## agent-service/src/api/backend-api.test.ts: ########## Review Comment: backend-api is also a bad name. too general. need to change src as well ########## agent-service/src/api/backend-api.test.ts: ########## @@ -0,0 +1,63 @@ +/** + * 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 { afterEach, describe, expect, test } from "bun:test"; +import { fetchOperatorMetadata, getBackendConfig } from "./backend-api"; + +const realFetch = globalThis.fetch; +let lastUrl = ""; + +function stubFetch(handler: () => Response): void { + globalThis.fetch = (async (url: unknown) => { + lastUrl = String(url); + return handler(); + }) as unknown as typeof fetch; +} + +afterEach(() => { + globalThis.fetch = realFetch; +}); + +describe("getBackendConfig", () => { + test("exposes the configured endpoints and returns a defensive copy", () => { + const a = getBackendConfig(); + const b = getBackendConfig(); + expect(a).not.toBe(b); // a fresh object each call + expect(typeof a.apiEndpoint).toBe("string"); + expect(typeof a.compileEndpoint).toBe("string"); + expect(typeof a.executionEndpoint).toBe("string"); + }); +}); Review Comment: this api is confusing. are you getting configs or endpoints? should be renamed. ########## agent-service/src/api/auth-api.test.ts: ########## @@ -0,0 +1,78 @@ +/** + * 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 { createAuthHeaders, extractUserFromToken, validateToken } from "./auth-api"; + +// Builds a syntactically valid (unsigned) JWT for the given payload. The +// service only base64-decodes the payload — it does not verify the signature — +// so a dummy signature segment is sufficient for these tests. +function makeJwt(payload: Record<string, unknown>): string { + const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64"); + const body = Buffer.from(JSON.stringify(payload)).toString("base64"); + return `${header}.${body}.signature`; +} Review Comment: we should reuse the existing, valid JWT signed by our auth backend. ########## agent-service/src/api/compile-api.test.ts: ########## Review Comment: workflow-compile-api? ########## agent-service/src/api/auth-api.test.ts: ########## @@ -0,0 +1,78 @@ +/** + * 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 { createAuthHeaders, extractUserFromToken, validateToken } from "./auth-api"; + +// Builds a syntactically valid (unsigned) JWT for the given payload. The +// service only base64-decodes the payload — it does not verify the signature — +// so a dummy signature segment is sufficient for these tests. +function makeJwt(payload: Record<string, unknown>): string { + const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64"); + const body = Buffer.from(JSON.stringify(payload)).toString("base64"); + return `${header}.${body}.signature`; +} Review Comment: what? we are signing JWT in agent service? -- 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]
