Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ class NihService(val samDao: SamDAO,

def updateNihLinkAndSyncSelf(userInfo: UserInfo, jwtWrapper: JWTWrapper): Future[PerRequestMessage] = {
val res = for {
_ <-
if (allowedNihMembers(Set(WorkbenchEmail(userInfo.userEmail))).isEmpty) {
Future.failed(
new FireCloudExceptionWithErrorReport(
ErrorReport(StatusCodes.Forbidden, "User is not allowed to link NIH account")
)
)
} else {
Future.successful(())
}
shibbolethPublicKey <- shibbolethDao.getPublicKey()
decodedToken <- Future
.fromTry(Jwt.decodeRawAll(jwtWrapper.jwt, shibbolethPublicKey, Seq(JwtAlgorithm.RS256)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.broadinstitute.dsde.firecloud.service

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.OAuth2BearerToken
import org.broadinstitute.dsde.firecloud.FireCloudExceptionWithErrorReport
import org.broadinstitute.dsde.firecloud.dataaccess._
import org.broadinstitute.dsde.firecloud.mock.MockGoogleServicesDAO
import org.broadinstitute.dsde.firecloud.model.{JWTWrapper, UserInfo}
Expand Down Expand Up @@ -112,4 +114,13 @@ class NihServiceSpec extends AnyFlatSpec with Matchers {
fail(s"Expired token should fail at the decode stage. Response was: $x")
}
}

it should "403 linking denied email" in {
val nihServiceMock = new NihService(samDao, thurloeDao, googleDao, mock[ShibbolethDAO], ecmDao)
val userToken: UserInfo = UserInfo("someone@gmail.com", OAuth2BearerToken("dummyToken"), -1, thurloeDao.TCGA_AND_TARGET_LINKED)
val error = intercept[FireCloudExceptionWithErrorReport] {
Await.result(nihServiceMock.updateNihLinkAndSyncSelf(userToken, JWTWrapper("dummyToken")), 3.seconds)
}
error.errorReport.statusCode shouldBe Some(StatusCodes.Forbidden)
}
}
Loading