Skip to content

Commit

Permalink
ID-807 fixing failing tests from new directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Polumbo committed Oct 26, 2023
1 parent 91923e2 commit edf6957
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.OAuth2BearerToken
import akka.http.scaladsl.server.{Directive, Directive0, Directive1}
import akka.http.scaladsl.server.Directives.{complete, extractRequest, onSuccess, optionalHeaderValueByName}
import akka.http.scaladsl.server.Directives.{complete, extractRequest, onSuccess, optionalHeaderValueByName, provide}
import akka.stream.Materializer
import cats.effect._
import cats.effect.unsafe.implicits.global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ trait SamUserDirectives {
// was added so we can do the "isAdmin calculation" in the routes, just like we've always done it, but then pass this
// data into the Services to let them make their own authz determination. If we can change the way we define admins
// from _not_ depending on Google, then we may be able to get rid of this directive.
def isWorkbenchAdmin(samUser: SamUser): Directive1[Boolean] =
onSuccess(cloudExtensions.isWorkbenchAdmin(samUser.email))
def isWorkbenchAdmin(samUser: SamUser): Directive1[Boolean]

def asAdminServiceUser: Directive0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ trait StandardSamUserDirectives extends SamUserDirectives with LazyLogging with
SamUser(genWorkbenchUserId(System.currentTimeMillis()), googleSubjectId, oidcHeaders.email, azureB2CId, false)
}

override def isWorkbenchAdmin(samUser: SamUser): Directive1[Boolean] =
onSuccess(cloudExtensions.isWorkbenchAdmin(samUser.email))

/** Utility function that knows how to convert all the various headers into OIDCHeaders
*/
private def requireOidcHeaders: Directive1[OIDCHeaders] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.broadinstitute.dsde.workbench.sam.api

import akka.actor.ActorSystem
import akka.http.scaladsl.server.Directives.{onSuccess, reject}
import akka.http.scaladsl.server.Directives.{onSuccess, provide, reject}
import akka.http.scaladsl.server._
import akka.stream.Materializer
import cats.effect.IO
Expand Down Expand Up @@ -145,9 +145,13 @@ class MockSamRoutesBuilder(allUsersGroup: WorkbenchGroup)(implicit system: Actor
}

override def extensionRoutes(samUser: SamUser, samRequestContext: SamRequestContext): Route = reject

implicit val errorReportSource: ErrorReportSource = ErrorReportSource("test")
override def asAdminServiceUser: Directive0 = if (asServiceAdminUser) Directive.Empty
else reject(AuthorizationFailedRejection)

override def asAdminServiceUser: Directive0 =
if (asServiceAdminUser) Directive.Empty else reject(AuthorizationFailedRejection)

override def isWorkbenchAdmin(samUser: SamUser): Directive1[Boolean] = provide(asServiceAdminUser)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ trait MockSamUserDirectives extends SamUserDirectives {
case None => failWith(new Exception("samUser not specified"))
case Some(u) => provide(u)
}

override def isWorkbenchAdmin(samUser: SamUser): Directive1[Boolean] = provide(false)
}

0 comments on commit edf6957

Please sign in to comment.