You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "PG1204 (via GitHub)" <gi...@apache.org> on 2026/07/16 04:53:05 UTC

[PR] fix(computing-unit): return 4xx instead of 500 when sharing/revoking to an unknown email [texera]

PG1204 opened a new pull request, #6446:
URL: https://github.com/apache/texera/pull/6446

   ### What changes were proposed in this PR?
   ComputingUnitAccessResource.grantAccess and revokeAccess looked up the target user with userDao.fetchOneByEmail(email).getUid and only then null-checked the result:
   
   val granteeId = userDao.fetchOneByEmail(email).getUid  // NPE when email is unknown
   if (granteeId == null) { ... }                          // dead code which never got reached
   
   fetchOneByEmail returns null when no account matches the email, so .getUid threw a NullPointerException before the guard ran, surfacing to the client as an opaque HTTP 500. The intended "User with the given email does not exist" error was unreachable.
   
   This PR reorders both methods to fetch the user object, null-check it, and only then read .getUid, so an unknown email now yields a clear IllegalArgumentException (4xx) instead of a 500. Sharing to a mistyped/nonexistent email is a common user action, so this turns a confusing server error into an actionable message.
   
   ### Any related issues, documentation, discussions?
   Closes #6445 
   
   ### How was this PR tested?
   Added ComputingUnitAccessResourceSpec (embedded Postgres via MockTexeraDB) covering both methods: the happy path, the unknown-email case (the regression this PR fixes), and the no-write-access case. Verified red-then-green — against the old ordering both unknown-email tests fail with NullPointerException; after the fix all 7 pass.
   
   This module had no DB-backed test wiring, so build.sbt was updated to add DAO % "test->test" (for MockTexeraDB + embedded Postgres) and to fork the test JVM with COMPUTING_UNIT_SHARING_ENABLED=true and the repo root as the working directory (so MockTexeraDB can resolve sql/texera_ddl.sql).
   
   Run:
   sbt "ComputingUnitManagingService/testOnly org.apache.texera.service.resource.ComputingUnitAccessResourceSpec"
   
   ### Was this PR authored or co-authored using generative AI tooling?
   Co-authored with Claude Opus 4.8 in compliance with ASF


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "chenlica (via GitHub)" <gi...@apache.org>.
chenlica commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4989185027

   @mengw15 Can you review it as well?


-- 
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: [PR] fix(computing-unit): return 4xx instead of 500 when sharing/revoking to an unknown email [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4988318212

   <!-- texera-reviewer-suggestion -->
   ### Automated Reviewer Suggestions
   
   Based on the `git blame` history of the changed files, we recommend the following reviewers:
   
   - **Contributors with relevant context:** `@Yicong-Huang`, `@Ma77Ball`
     You can notify them by mentioning `@Yicong-Huang`, `@Ma77Ball` in a comment.
   


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "mengw15 (via GitHub)" <gi...@apache.org>.
mengw15 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3593529749


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }
 
     // TODO: add try except and check how to display error message in the frontend
-    val granteeId = userDao.fetchOneByEmail(email).getUid
-    if (granteeId == null) {
+    val grantee = userDao.fetchOneByEmail(email)
+    if (grantee == null) {
       throw new IllegalArgumentException("User with the given email does not exist")

Review Comment:
   One reality-check on the "(4xx)" part of the description: this service registers no ExceptionMapper (`ComputingUnitManagingService` registers only resources/auth/logging), so an `IllegalArgumentException` thrown from a resource method still surfaces through Dropwizard's default `LoggingExceptionMapper` as a 500 — and that mapper does not expose the exception message to the client ("There was an error processing your request. It has been logged…"). The NPE fix and the in-place upsert stand on their own, but the user-visible outcome for a mistyped email is still an opaque 500. Throwing `jakarta.ws.rs.BadRequestException` (400 + message) here — and arguably in the permission checks above, which share the convention — would deliver the actionable 4xx the description promises. The new tests call the methods directly, so they'd only need the exception type swapped.



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598340951


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }

Review Comment:
   confirmed that there's no ExceptionMapper for IllegalArgumentException (only UnauthorizedExceptionMapper), so it was surfacing as a 500. Switched to JAX-RS exceptions: ForbiddenException (403) for the permission check and BadRequestException (400) for the unknown-email case, matching the DatasetAccessResource/WorkflowAccessResource convention. Tests now assert the resolved status codes (403/400).
   
   addressed in 91ad863



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3593386245


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }

Review Comment:
   `grantAccess` throws `IllegalArgumentException` for client errors (no permission / unknown email). There is no `ExceptionMapper` for `IllegalArgumentException` in this repo (only `UnauthorizedExceptionMapper`), so these exceptions are likely to surface as HTTP 500 instead of a 4xx. Use JAX-RS exceptions to guarantee the intended status codes.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }

Review Comment:
   If `grantAccess` uses `ForbiddenException` for authorization failures (so the endpoint returns HTTP 403), this test should intercept `ForbiddenException` rather than `IllegalArgumentException`.



##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -179,10 +183,11 @@ class ComputingUnitAccessResource {
       throw new IllegalArgumentException("User does not have permission to revoke access")
     }

Review Comment:
   Same issue in `revokeAccess`: throwing `IllegalArgumentException` for permission/unknown-email errors will likely be treated as an unhandled runtime exception and returned as HTTP 500. Prefer explicit JAX-RS exceptions (403/400) like other access resources.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }

Review Comment:
   If `ComputingUnitAccessResource` is changed to throw `BadRequestException` (so the REST endpoint returns 4xx instead of 500), this test should intercept that JAX-RS exception type rather than `IllegalArgumentException`.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }
+
+  // ===========================================================================
+  // revokeAccess
+  // ===========================================================================
+
+  "revokeAccess" should "remove the grantee from the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessEmails(cuid) should contain(granteeUser.getEmail)
+
+    accessResource.revokeAccess(ownerSession, cuid, granteeUser.getEmail)
+
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(ownerSession, cuid, nonExistentEmail)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+  }

Review Comment:
   If `revokeAccess` is updated to throw `BadRequestException` for unknown emails (to avoid HTTP 500), update the intercepted exception type here accordingly.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }
+
+  // ===========================================================================
+  // revokeAccess
+  // ===========================================================================
+
+  "revokeAccess" should "remove the grantee from the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessEmails(cuid) should contain(granteeUser.getEmail)
+
+    accessResource.revokeAccess(ownerSession, cuid, granteeUser.getEmail)
+
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(ownerSession, cuid, nonExistentEmail)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+  }
+
+  it should "reject a caller without write access" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(strangerSession, cuid, granteeUser.getEmail)
+    }
+    ex.getMessage should include("does not have permission to revoke access")
+  }

Review Comment:
   If `revokeAccess` is updated to throw `ForbiddenException` for no-write-access cases (HTTP 403), update the intercepted exception type here to match.



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598353759


##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }

Review Comment:
   done, this test now does intercept[ForbiddenException] and asserts ex.getResponse.getStatus shouldEqual 403.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): return 4xx instead of 500 when sharing/revoking to an unknown email [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4988350104

   <!-- texera-benchmarks-comment -->
   ## ✅ No material benchmark regressions detected
   
   🟢 0 better · 🔴 0 worse · ⚪ 15 noise (<±5%) · 0 without baseline
   
   > Compared against main `c7473a1` benchmarked on **this same runner**, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.
   
   [Dashboard](https://apache.github.io/texera/dev/bench/) · [Run](https://github.com/apache/texera/actions/runs/29472442082)
   
   | | config | throughput | MB/s | latency | max Δ latest / 7d |
   |---|---|---:|---:|---:|---:|
   | ⚪ | bs=10 sw=10 sl=64 | 368 | 0.225 | 25,631/36,909/36,909 us | ⚪ within ±5% / 🔴 +160.8% |
   | ⚪ | bs=100 sw=10 sl=64 | 751 | 0.459 | 132,973/151,749/151,749 us | ⚪ within ±5% / 🔴 +55.2% |
   | ⚪ | bs=1000 sw=10 sl=64 | 874 | 0.534 | 1,149,307/1,205,186/1,205,186 us | ⚪ within ±5% / 🔴 +28.0% |
   
   <details><summary>Baseline details</summary>
   
   Latest main `c7473a1` from same runner
   
   | config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
   |---|---|---:|---:|---:|---:|---:|
   | bs=10 sw=10 sl=64 | throughput | 368 tuples/sec | 381 tuples/sec | 847.3 tuples/sec | -3.4% | -56.6% |
   | bs=10 sw=10 sl=64 | MB/s | 0.225 MB/s | 0.233 MB/s | 0.517 MB/s | -3.4% | -56.5% |
   | bs=10 sw=10 sl=64 | p50 | 25,631 us | 24,736 us | 11,621 us | +3.6% | +120.6% |
   | bs=10 sw=10 sl=64 | p95 | 36,909 us | 35,871 us | 14,154 us | +2.9% | +160.8% |
   | bs=10 sw=10 sl=64 | p99 | 36,909 us | 35,871 us | 19,069 us | +2.9% | +93.6% |
   | bs=100 sw=10 sl=64 | throughput | 751 tuples/sec | 780 tuples/sec | 1,104 tuples/sec | -3.7% | -32.0% |
   | bs=100 sw=10 sl=64 | MB/s | 0.459 MB/s | 0.476 MB/s | 0.674 MB/s | -3.6% | -31.9% |
   | bs=100 sw=10 sl=64 | p50 | 132,973 us | 127,813 us | 91,279 us | +4.0% | +45.7% |
   | bs=100 sw=10 sl=64 | p95 | 151,749 us | 145,064 us | 97,771 us | +4.6% | +55.2% |
   | bs=100 sw=10 sl=64 | p99 | 151,749 us | 145,064 us | 107,798 us | +4.6% | +40.8% |
   | bs=1000 sw=10 sl=64 | throughput | 874 tuples/sec | 870 tuples/sec | 1,127 tuples/sec | +0.5% | -22.5% |
   | bs=1000 sw=10 sl=64 | MB/s | 0.534 MB/s | 0.531 MB/s | 0.688 MB/s | +0.6% | -22.4% |
   | bs=1000 sw=10 sl=64 | p50 | 1,149,307 us | 1,134,828 us | 902,553 us | +1.3% | +27.3% |
   | bs=1000 sw=10 sl=64 | p95 | 1,205,186 us | 1,236,433 us | 941,491 us | -2.5% | +28.0% |
   | bs=1000 sw=10 sl=64 | p99 | 1,205,186 us | 1,236,433 us | 979,025 us | -2.5% | +23.1% |
   
   </details>
   
   <details><summary>Raw CSV</summary>
   
   ```csv
   config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
   0,10,10,64,20,543.20,200,128000,368,0.225,25630.70,36909.22,36909.22
   1,100,10,64,20,2662.29,2000,1280000,751,0.459,132973.30,151748.95,151748.95
   2,1000,10,64,20,22877.02,20000,12800000,874,0.534,1149307.15,1205186.07,1205186.07
   ```
   
   </details>
   


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "Ma77Ball (via GitHub)" <gi...@apache.org>.
Ma77Ball commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3593153869


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }
 
     // TODO: add try except and check how to display error message in the frontend
-    val granteeId = userDao.fetchOneByEmail(email).getUid
-    if (granteeId == null) {
+    val grantee = userDao.fetchOneByEmail(email)
+    if (grantee == null) {
       throw new IllegalArgumentException("User with the given email does not exist")
     }
+    val granteeId = grantee.getUid

Review Comment:
   Optional, non-blocking: this fetch + null-check + getUid block is now identical in grantAccess and revokeAccess (same message). Consider lifting it to a small private helper so the two stay in sync. This is a manual two-spot change (add the helper, then replace both blocks with `val granteeId = resolveUidByEmail(email)`), so no click-to-commit suggestion:
   
   ```scala
   private def resolveUidByEmail(email: String): Integer = {
     val user = userDao.fetchOneByEmail(email)
     if (user == null) {
       throw new IllegalArgumentException("User with the given email does not exist")
     }
     user.getUid
   }
   ```



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "mengw15 (via GitHub)" <gi...@apache.org>.
mengw15 merged PR #6446:
URL: https://github.com/apache/texera/pull/6446


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4988460071

   ## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6446?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 70.25%. Comparing base ([`c7473a1`](https://app.codecov.io/gh/apache/texera/commit/c7473a1d8c8bf68f5cfab4ec4968982173ac5ae2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`9080cea`](https://app.codecov.io/gh/apache/texera/commit/9080cea6416577cde49df85159a47229d2113e3a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #6446      +/-   ##
   ============================================
   + Coverage     70.20%   70.25%   +0.04%     
   - Complexity     3390     3395       +5     
   ============================================
     Files          1142     1142              
     Lines         44844    44846       +2     
     Branches       4949     4949              
   ============================================
   + Hits          31484    31506      +22     
   + Misses        11725    11695      -30     
   - Partials       1635     1645      +10     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
   |---|---|---|---|
   | [access-control-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | |
   | [agent-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.76% <ø> (ø)` | | Carriedforward from [2c6b1b9](https://app.codecov.io/gh/apache/texera/commit/2c6b1b913f8e322d2cac8432efb5f2aa73605cb5?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [amber](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.63% <ø> (-0.05%)` | :arrow_down: | |
   | [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `18.18% <100.00%> (+8.20%)` | :arrow_up: | |
   | [config-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.30% <ø> (ø)` | | |
   | [file-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `65.63% <ø> (ø)` | | |
   | [frontend](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `68.96% <ø> (ø)` | | Carriedforward from [2c6b1b9](https://app.codecov.io/gh/apache/texera/commit/2c6b1b913f8e322d2cac8432efb5f2aa73605cb5?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.94% <ø> (ø)` | | |
   | [pyamber](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.19% <ø> (ø)` | | Carriedforward from [2c6b1b9](https://app.codecov.io/gh/apache/texera/commit/2c6b1b913f8e322d2cac8432efb5f2aa73605cb5?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/6446/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.14% <ø> (ø)` | | |
   
   *This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/6446?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598369989


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }
 
     // TODO: add try except and check how to display error message in the frontend
-    val granteeId = userDao.fetchOneByEmail(email).getUid
-    if (granteeId == null) {
+    val grantee = userDao.fetchOneByEmail(email)
+    if (grantee == null) {
       throw new IllegalArgumentException("User with the given email does not exist")

Review Comment:
   thanks for the review, this is exactly right, I confirmed the IllegalArgumentException was falling through to Dropwizard's default LoggingExceptionMapper and surfacing as an opaque 500. Switched to JAX-RS exceptions: BadRequestException (400 + message) for the unknown-email case, and ForbiddenException (403) for the permission checks, I went with 403 there for the semantic status and to match the existing DatasetAccessResource/WorkflowAccessResource convention. The tests now intercept the JAX-RS types and assert the resolved status (400/403).
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "Ma77Ball (via GitHub)" <gi...@apache.org>.
Ma77Ball commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4995861888

   @mengw15 or @chenlica, I already approved this PR. Also, as I'm not a committer, I cannot approve PRs that are merged into the main branch. Please review again when you have time. 


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598358182


##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }
+
+  // ===========================================================================
+  // revokeAccess
+  // ===========================================================================
+
+  "revokeAccess" should "remove the grantee from the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessEmails(cuid) should contain(granteeUser.getEmail)
+
+    accessResource.revokeAccess(ownerSession, cuid, granteeUser.getEmail)
+
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(ownerSession, cuid, nonExistentEmail)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+  }

Review Comment:
   done, this test now does intercept[BadRequestException] and asserts ex.getResponse.getStatus shouldEqual 400.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598349982


##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }

Review Comment:
   done, this test now does intercept[BadRequestException] and also asserts ex.getResponse.getStatus shouldEqual 400.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598345867


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -179,10 +183,11 @@ class ComputingUnitAccessResource {
       throw new IllegalArgumentException("User does not have permission to revoke access")
     }

Review Comment:
   fixed, revokeAccess now throws ForbiddenException (403) for the permission check and BadRequestException (400) for the unknown-email case, same as grantAccess. Tests assert the resolved status codes.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on PR #6446:
URL: https://github.com/apache/texera/pull/6446#issuecomment-4988845689

   /request-review @Ma77Ball 


-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598362448


##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.common.config.ComputingUnitConfig
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables.COMPUTING_UNIT_USER_ACCESS
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, WorkflowComputingUnit}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+/**
+  * Spec for [[ComputingUnitAccessResource]]'s share/revoke endpoints, backed by an
+  * embedded Postgres (via [[MockTexeraDB]]).
+  *
+  * The suite runs with COMPUTING_UNIT_SHARING_ENABLED=true (set in build.sbt), which
+  * `ensureSharingIsEnabled()` requires; this is asserted below so a missing env var
+  * fails loudly instead of silently short-circuiting every case with a ForbiddenException.
+  *
+  * The key regression these tests guard: granting/revoking to an unknown email must
+  * surface a clear IllegalArgumentException, not a NullPointerException (500), because
+  * `userDao.fetchOneByEmail` returns null for an address with no account.
+  */
+class ComputingUnitAccessResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val ownerUser: User = {
+    val user = new User
+    user.setName("cu_owner")
+    user.setPassword("123")
+    user.setEmail("cu_owner@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val granteeUser: User = {
+    val user = new User
+    user.setName("cu_grantee")
+    user.setPassword("123")
+    user.setEmail("cu_grantee@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val strangerUser: User = {
+    val user = new User
+    user.setName("cu_stranger")
+    user.setPassword("123")
+    user.setEmail("cu_stranger@test.com")
+    user.setRole(UserRoleEnum.REGULAR)
+    user
+  }
+
+  private val ownedUnit: WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit
+    unit.setName("owned-unit")
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit.setUri("")
+    unit
+  }
+
+  private val nonExistentEmail: String = "nobody@test.com"
+
+  lazy val accessResource = new ComputingUnitAccessResource()
+
+  lazy val ownerSession = new SessionUser(ownerUser)
+  lazy val strangerSession = new SessionUser(strangerUser)
+
+  private def cuid: Integer = ownedUnit.getCuid
+
+  private def accessEmails(cuid: Integer): List[String] =
+    accessResource.getComputingUnitAccessList(ownerSession, cuid).map(_.email)
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+
+    val userDao = new UserDao(getDSLContext.configuration())
+    userDao.insert(ownerUser)
+    userDao.insert(granteeUser)
+    userDao.insert(strangerUser)
+
+    ownedUnit.setUid(ownerUser.getUid)
+    new WorkflowComputingUnitDao(getDSLContext.configuration()).insert(ownedUnit)
+  }
+
+  override protected def beforeEach(): Unit = {
+    super.beforeEach()
+    // every test starts with no explicit grants on the unit
+    getDSLContext.deleteFrom(COMPUTING_UNIT_USER_ACCESS).execute()
+  }
+
+  override protected def afterAll(): Unit = {
+    try shutdownDB()
+    finally super.afterAll()
+  }
+
+  "the test environment" should "have computing-unit sharing enabled" in {
+    // guards against a silent misconfiguration that would make every case below
+    // short-circuit in ensureSharingIsEnabled rather than test the intended paths
+    ComputingUnitConfig.sharingComputingUnitEnabled shouldBe true
+  }
+
+  // ===========================================================================
+  // grantAccess
+  // ===========================================================================
+
+  "grantAccess" should "add a grantee that appears in the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.READ
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(ownerSession, cuid, nonExistentEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "update the privilege in place when re-granting with a different privilege" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.WRITE)
+
+    val entries = accessResource.getComputingUnitAccessList(ownerSession, cuid)
+    entries should have size 1
+    entries.head.email shouldEqual granteeUser.getEmail
+    entries.head.privilege shouldEqual PrivilegeEnum.WRITE
+  }
+
+  it should "reject a caller without write access" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.grantAccess(strangerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    }
+    ex.getMessage should include("does not have permission to grant access")
+  }
+
+  // ===========================================================================
+  // revokeAccess
+  // ===========================================================================
+
+  "revokeAccess" should "remove the grantee from the access list" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+    accessEmails(cuid) should contain(granteeUser.getEmail)
+
+    accessResource.revokeAccess(ownerSession, cuid, granteeUser.getEmail)
+
+    accessEmails(cuid) shouldBe empty
+  }
+
+  it should "reject an unknown email with a clear error instead of crashing" in {
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(ownerSession, cuid, nonExistentEmail)
+    }
+    ex.getMessage should include("User with the given email does not exist")
+  }
+
+  it should "reject a caller without write access" in {
+    accessResource.grantAccess(ownerSession, cuid, granteeUser.getEmail, PrivilegeEnum.READ)
+
+    val ex = intercept[IllegalArgumentException] {
+      accessResource.revokeAccess(strangerSession, cuid, granteeUser.getEmail)
+    }
+    ex.getMessage should include("does not have permission to revoke access")
+  }

Review Comment:
   done, this test now does intercept[ForbiddenException] and asserts ex.getResponse.getStatus shouldEqual 403.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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: [PR] fix(computing-unit): fix 500s in share/revoke (unknown email + privilege change) [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on code in PR #6446:
URL: https://github.com/apache/texera/pull/6446#discussion_r3598375188


##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala:
##########
@@ -152,18 +152,22 @@ class ComputingUnitAccessResource {
     }
 
     // TODO: add try except and check how to display error message in the frontend
-    val granteeId = userDao.fetchOneByEmail(email).getUid
-    if (granteeId == null) {
+    val grantee = userDao.fetchOneByEmail(email)
+    if (grantee == null) {
       throw new IllegalArgumentException("User with the given email does not exist")
     }
+    val granteeId = grantee.getUid

Review Comment:
   done, extracted a private resolveUidByEmail(email) helper and replaced both blocks with val granteeId = resolveUidByEmail(email), so grant/revoke stay in sync. Kept BadRequestException (400) in the helper rather than IllegalArgumentException so it still maps to a proper 4xx. The existing unknown-email tests exercise the helper through both endpoints.
   
   addressed in https://github.com/apache/texera/commit/91ad863aa74374eb5a280d890fd822cc5720938f



-- 
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