Task Summary
Add a SessionUserSpec.scala that pins how SessionUser wraps a jOOQ User and exposes it as a java.security.Principal, including the isRoleOf role check.
Background
SessionUser (common/auth, SessionUser.scala) wraps a generated User POJO and implements java.security.Principal. It delegates identity accessors to the wrapped user and adds a role predicate. It has no dedicated unit-spec (its common/auth sibling HeaderField is already a starter task, #5662).
class SessionUser(val user: User) extends Principal {
def getUser: User = user
override def getName: String = user.getName
def getUid: Integer = user.getUid
def getEmail: String = user.getEmail
def getGoogleId: String = user.getGoogleId
def isRoleOf(role: UserRoleEnum): Boolean = user.getRole == role
}
Behavior to pin
Construct a User POJO (set uid, name, email, googleId, role via setters), wrap it in SessionUser, and assert:
| Surface |
Contract |
getName (Principal contract) |
returns user.getName |
getUid / getEmail / getGoogleId |
delegate to the wrapped user |
getUser |
returns the same User instance |
isRoleOf(role) |
true iff user.getRole == role — verify a match (e.g. ADMIN vs ADMIN) and a mismatch (REGULAR vs ADMIN) using UserRoleEnum |
Scope
- New spec:
SessionUserSpec.scala under common/auth/src/test/scala/org/apache/texera/auth/ (alongside the existing auth specs).
- No production-code changes.
Task Type
Task Summary
Add a
SessionUserSpec.scalathat pins howSessionUserwraps a jOOQUserand exposes it as ajava.security.Principal, including theisRoleOfrole check.Background
SessionUser(common/auth,SessionUser.scala) wraps a generatedUserPOJO and implementsjava.security.Principal. It delegates identity accessors to the wrapped user and adds a role predicate. It has no dedicated unit-spec (itscommon/authsiblingHeaderFieldis already a starter task, #5662).Behavior to pin
Construct a
UserPOJO (setuid,name,email,googleId,rolevia setters), wrap it inSessionUser, and assert:getName(Principal contract)user.getNamegetUid/getEmail/getGoogleIdgetUserUserinstanceisRoleOf(role)trueiffuser.getRole == role— verify a match (e.g.ADMINvsADMIN) and a mismatch (REGULARvsADMIN) usingUserRoleEnumScope
SessionUserSpec.scalaundercommon/auth/src/test/scala/org/apache/texera/auth/(alongside the existing auth specs).Task Type