-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ID-816 New User Registration Endpoint
- Loading branch information
Showing
12 changed files
with
133 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/scala/org/broadinstitute/dsde/firecloud/model/RegisterRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.broadinstitute.dsde.firecloud.model | ||
|
||
case class RegisterRequest(acceptsTermsOfService: Boolean, profile: BasicProfile) |
3 changes: 3 additions & 0 deletions
3
src/main/scala/org/broadinstitute/dsde/firecloud/model/SamUserAttributesRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.broadinstitute.dsde.firecloud.model | ||
|
||
case class SamUserAttributesRequest(marketingConsent: Option[Boolean]) |
8 changes: 8 additions & 0 deletions
8
src/main/scala/org/broadinstitute/dsde/firecloud/model/SamUserRegistrationRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.broadinstitute.dsde.firecloud.model | ||
|
||
import org.broadinstitute.dsde.workbench.model.ErrorReport | ||
|
||
case class SamUserRegistrationRequest( | ||
acceptsTermsOfService: Boolean, | ||
userAttributes: SamUserAttributesRequest | ||
) |
16 changes: 16 additions & 0 deletions
16
src/main/scala/org/broadinstitute/dsde/firecloud/model/SamUserResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.broadinstitute.dsde.firecloud.model | ||
|
||
import org.broadinstitute.dsde.workbench.model.{AzureB2CId, GoogleSubjectId, WorkbenchEmail, WorkbenchUserId} | ||
|
||
import java.time.Instant | ||
|
||
final case class SamUserResponse( | ||
id: WorkbenchUserId, | ||
googleSubjectId: Option[GoogleSubjectId], | ||
email: WorkbenchEmail, | ||
azureB2CId: Option[AzureB2CId], | ||
allowed: Boolean, | ||
createdAt: Instant, | ||
registeredAt: Option[Instant], | ||
updatedAt: Instant | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ import akka.http.scaladsl.model.StatusCodes | |
import org.broadinstitute.dsde.firecloud.{FireCloudException, FireCloudExceptionWithErrorReport} | ||
import org.broadinstitute.dsde.firecloud.HealthChecks.termsOfServiceUrl | ||
import org.broadinstitute.dsde.firecloud.model.ManagedGroupRoles.ManagedGroupRole | ||
import org.broadinstitute.dsde.firecloud.model.{AccessToken, FireCloudManagedGroupMembership, RegistrationInfo, RegistrationInfoV2, SamResource, UserIdInfo, UserInfo, WithAccessToken, WorkbenchEnabled, WorkbenchUserInfo} | ||
import org.broadinstitute.dsde.firecloud.model.{AccessToken, FireCloudManagedGroupMembership, RegistrationInfo, RegistrationInfoV2, SamResource, SamUserResponse, UserIdInfo, UserInfo, WithAccessToken, WorkbenchEnabled, WorkbenchUserInfo} | ||
import org.broadinstitute.dsde.workbench.util.health.SubsystemStatus | ||
import org.broadinstitute.dsde.rawls.model.{ErrorReport, RawlsUserEmail} | ||
import org.broadinstitute.dsde.workbench.model.google.GoogleProject | ||
import org.broadinstitute.dsde.workbench.model.{WorkbenchEmail, WorkbenchGroupName} | ||
import org.broadinstitute.dsde.workbench.model.{AzureB2CId, GoogleSubjectId, WorkbenchEmail, WorkbenchGroupName, WorkbenchUserId} | ||
|
||
import java.time.Instant | ||
import scala.concurrent.Future | ||
|
||
/** | ||
|
@@ -82,6 +83,18 @@ class MockSamDAO extends SamDAO { | |
Future.successful(()) | ||
} | ||
|
||
private val registeredUser = Future.successful { | ||
SamUserResponse( | ||
id = WorkbenchUserId("foo"), | ||
googleSubjectId = Some(GoogleSubjectId("bar")), | ||
email = WorkbenchEmail("[email protected]"), | ||
azureB2CId = Some(AzureB2CId("baz")), | ||
allowed = true, | ||
createdAt = Instant.now(), | ||
registeredAt = Some(Instant.now()), | ||
updatedAt = Instant.now() | ||
) | ||
} | ||
|
||
private val enabledUserInfo = Future.successful { | ||
RegistrationInfo( | ||
|
@@ -121,4 +134,12 @@ class MockSamDAO extends SamDAO { | |
override def getPetServiceAccountKeyForUser(user: WithAccessToken, project: GoogleProject): Future[String] = Future.successful("""{"fake":"key""}""") | ||
|
||
override def setPolicyPublic(resourceTypeName: String, resourceId: String, policyName: String, public: Boolean)(implicit userInfo: WithAccessToken): Future[Unit] = Future.successful(()) | ||
|
||
override def registerUserSelf(acceptsTermsOfService: Boolean)(implicit userInfo: WithAccessToken): Future[SamUserResponse] = { | ||
if (acceptsTermsOfService) { | ||
registeredUser | ||
} else { | ||
Future.failed(new FireCloudExceptionWithErrorReport(new ErrorReport("sam", "invalid", Some(StatusCodes.BadRequest), Seq.empty, Seq.empty, None))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,15 @@ package org.broadinstitute.dsde.firecloud.webservice | |
|
||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport | ||
import org.broadinstitute.dsde.firecloud.dataaccess.MockThurloeDAO | ||
import org.broadinstitute.dsde.firecloud.model.{BasicProfile, UserInfo} | ||
import org.broadinstitute.dsde.firecloud.model.{BasicProfile, RegisterRequest, UserInfo, WithAccessToken} | ||
import org.broadinstitute.dsde.firecloud.service.{BaseServiceSpec, RegisterService, UserService} | ||
import akka.http.scaladsl.model.StatusCodes.{BadRequest, Forbidden, NoContent, NotFound, OK} | ||
import akka.http.scaladsl.model.StatusCode | ||
import akka.http.scaladsl.server.Route.{seal => sealRoute} | ||
import org.broadinstitute.dsde.firecloud.HealthChecks.termsOfServiceUrl | ||
import org.broadinstitute.dsde.firecloud.mock.{MockUtils, SamMockserverUtils} | ||
import org.broadinstitute.dsde.firecloud.model.ModelJsonProtocol.impBasicProfile | ||
import org.broadinstitute.dsde.firecloud.model.ModelJsonProtocol.impRegisterRequest | ||
import org.mockserver.integration.ClientAndServer | ||
import org.mockserver.integration.ClientAndServer.startClientAndServer | ||
import org.mockserver.model.Header | ||
|
@@ -78,6 +79,24 @@ final class RegisterApiServiceSpec extends BaseServiceSpec with RegisterApiServi | |
override val userServiceConstructor:(UserInfo) => UserService = | ||
UserService.constructor(app.copy(thurloeDAO = new RegisterApiServiceSpecThurloeDAO)) | ||
|
||
def makeBasicProfile(hasTermsOfService: Boolean): BasicProfile = { | ||
val randomString = MockUtils.randomAlpha() | ||
BasicProfile( | ||
firstName = randomString, | ||
lastName = randomString, | ||
title = randomString, | ||
contactEmail = Some("[email protected]"), | ||
institute = randomString, | ||
researchArea = Some(randomString), | ||
programLocationCity = randomString, | ||
programLocationState = randomString, | ||
programLocationCountry = randomString, | ||
termsOfService = if (hasTermsOfService) Some(termsOfServiceUrl) else None, | ||
department = Some(randomString), | ||
interestInTerra = Some(randomString) | ||
) | ||
} | ||
|
||
"RegisterApiService" - { | ||
"update-preferences API" - { | ||
|
||
|
@@ -151,23 +170,21 @@ final class RegisterApiServiceSpec extends BaseServiceSpec with RegisterApiServi | |
status should be(OK) | ||
} | ||
} | ||
} | ||
|
||
def makeBasicProfile(hasTermsOfService: Boolean): BasicProfile = { | ||
val randomString = MockUtils.randomAlpha() | ||
BasicProfile( | ||
firstName = randomString, | ||
lastName = randomString, | ||
title = randomString, | ||
contactEmail = Some("[email protected]"), | ||
institute = randomString, | ||
researchArea = Some(randomString), | ||
programLocationCity = randomString, | ||
programLocationState = randomString, | ||
programLocationCountry = randomString, | ||
termsOfService = if (hasTermsOfService) Some(termsOfServiceUrl) else None, | ||
department = Some(randomString), | ||
interestInTerra = Some(randomString) | ||
) | ||
"register-with-profile API POST" - { | ||
"should fail if Sam does not register the user" in { | ||
val payload = makeBasicProfile(false) | ||
Post("/users/v1/registerWithProfile", RegisterRequest(acceptsTermsOfService = false, profile = payload)) ~> dummyUserIdHeaders("RegisterApiServiceSpec", "new") ~> sealRoute(newRegisterRoutes) ~> check { | ||
status should be(BadRequest) | ||
} | ||
} | ||
|
||
"should succeed if Sam does register the user" in { | ||
val payload = makeBasicProfile(true) | ||
Post("/users/v1/registerWithProfile", RegisterRequest(acceptsTermsOfService = true, profile = payload)) ~> dummyUserIdHeaders("RegisterApiServiceSpec", "new") ~> sealRoute(newRegisterRoutes) ~> check { | ||
status should be(OK) | ||
} | ||
} | ||
} | ||
|
||
|