You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "gupta-sahil01 (via GitHub)" <gi...@apache.org> on 2026/07/29 18:27:32 UTC

[I] add unit test coverage for agent-service auth-api [texera]

gupta-sahil01 opened a new issue, #7045:
URL: https://github.com/apache/texera/issues/7045

   ### Task Summary
   
   `agent-service/src/api/` currently has no test coverage — none of its four
   modules (`auth-api.ts`, `backend-api.ts`, `workflow-api.ts`, `execution-api.ts`)
   has a corresponding `.spec.ts`. It is the only directory in the service without
   any tests; `src/agent/tools/` and `src/agent/util/` are both covered.
   
   This task covers `auth-api.ts` only, so the change stays small. The remaining
   three modules are HTTP clients that need a stubbed `fetch`, and are better
   handled as a follow-up.
   
   `auth-api.ts` is the authentication gate for the whole service. Every request
   that asks the agent to act on a user's behalf passes through it in
   `server.ts:187-195`:
   
       const userToken = extractBearerToken(headers.authorization);
       if (!userToken) throw new Error("Authorization header ... is required");
       if (!validateToken(userToken)) throw new Error("Invalid or expired token");
       const userInfo = extractUserFromToken(userToken);
   
   The exported functions are pure and dependency-free, so they can be tested
   directly with no mocking or network access.
   
   ### Proposed cases
   
   `extractBearerToken`
   - returns the token from a well-formed `Bearer <token>` header
   - accepts any casing of the scheme (`bearer`, `BEARER`)
   - returns `undefined` for a missing header, a non-Bearer scheme, and a
     `Bearer` header with no token
   
   `extractUserFromToken`
   - maps the backend claim names (`userId`, `sub`, `email`, `role`, set in
     `JwtAuth.jwtClaims`) onto `UserInfo`
   - applies the empty-email and `REGULAR`-role fallbacks when those claims are
     absent
   - throws on a token that is not three segments, and on a non-JSON payload
   
   `validateToken`
   - accepts an `exp` in the future, rejects one in the past
   - rejects a malformed token
   - pins current behaviour for a token carrying no `exp` claim (see question
     below)
   
   ### Open question
   
   `validateToken` only checks expiry — it never verifies the signature, and
   `isTokenExpired` (`auth-api.ts:49`) treats a token with no `exp` claim as
   never expiring. Both look intentional, since the Scala backend verifies the
   signature properly and `JwtAuth.jwtClaims` always sets an expiry. I plan to
   write the tests against current behaviour and flag it here rather than change
   anything. Happy to be corrected if either is actually a gap.
   
   ### Notes
   
   Tests run with `bun test` from `agent-service/`, following the existing style
   in `src/agent/util/context-utils.spec.ts`. No production code changes.
   
   
   ### Task Type
   
   - [ ] Refactor / Cleanup
   - [ ] DevOps / Deployment / CI
   - [x] Testing / QA
   - [ ] Documentation
   - [ ] Performance
   - [ ] Other


-- 
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: notifications-unsubscribe@texera.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] add unit test coverage for agent-service auth-api [texera]

Posted by "gupta-sahil01 (via GitHub)" <gi...@apache.org>.
gupta-sahil01 commented on issue #7045:
URL: https://github.com/apache/texera/issues/7045#issuecomment-5148848397

   Thanks for the comment. When will #5558 land approximately?


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] add unit test coverage for agent-service auth-api [texera]

Posted by "gupta-sahil01 (via GitHub)" <gi...@apache.org>.
gupta-sahil01 commented on issue #7045:
URL: https://github.com/apache/texera/issues/7045#issuecomment-5125585709

   I want some thoughts on this before I open a PR. @xuang7 ?


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] add unit test coverage for agent-service auth-api [texera]

Posted by "gupta-sahil01 (via GitHub)" <gi...@apache.org>.
gupta-sahil01 commented on issue #7045:
URL: https://github.com/apache/texera/issues/7045#issuecomment-5121930327

   /take


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org