aglinxinyuan commented on code in PR #7384: URL: https://github.com/apache/texera/pull/7384#discussion_r3739637804
########## agent-service/src/api/auth-api.spec.ts: ########## @@ -0,0 +1,133 @@ +/** + * 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, extractBearerToken, extractUserFromToken, validateToken } from "./auth-api"; + +/** Builds a token with the given payload. Only the payload segment is ever read back. */ Review Comment: Good catch — reworded. The helper now says all three segments are required and that only the payload one is decoded, so the header and signature just have to be present. ########## agent-service/src/api/auth-api.spec.ts: ########## @@ -0,0 +1,133 @@ +/** + * 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, extractBearerToken, extractUserFromToken, validateToken } from "./auth-api"; + +/** Builds a token with the given payload. Only the payload segment is ever read back. */ +function tokenWith(payload: Record<string, unknown>): string { + const encoded = Buffer.from(JSON.stringify(payload), "utf-8").toString("base64"); + return `header.${encoded}.signature`; +} + +const SECONDS = 1000; Review Comment: Agreed — dropped the constant instead of renaming it. `exp` is a UNIX second count, so the expiries are now built in seconds (`nowInSeconds() + 60`) and there is no ms/s conversion left to reason about. Re-ran the two mutations that cover these lines (relax the three-segment check, compare `exp` as milliseconds) — both still red. -- 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]
