Skip to content

Commit

Permalink
Pivotal ID # 186859974: Switch URl on basis of user upload mode (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan-EBI authored May 30, 2024
1 parent 08df1f4 commit 5951019
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ac.uk.ebi.biostd.client.api

import ac.uk.ebi.biostd.client.integration.web.GeneralOperations
import ebi.ac.uk.api.dto.UserGroupDto
import ebi.ac.uk.api.security.UserProfile
import ebi.ac.uk.commons.http.builder.linkedMultiValueMapOf
import ebi.ac.uk.commons.http.ext.RequestParams
import ebi.ac.uk.commons.http.ext.getForObject
Expand Down Expand Up @@ -47,4 +48,8 @@ class CommonOperationsClient(
val body = linkedMapOf("groupName" to groupName, "userName" to userName)
client.put(GROUP_URL, RequestParams(body = body))
}

override fun getProfile(): UserProfile {
return client.getForObject("/auth/profile")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ interface GeneralOperations {
groupName: String,
userName: String,
)

fun getProfile(): UserProfile
}

interface StatsOperations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class UserProfile(
val orcid: String,
val allow: List<String>,
val deny: List<String>,
val uploadType: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal class PmcSingleSubmissionSubmitterTest(private val tempFolder: Temporar
"orcid" to "orcid"
"allow" to jsonArray("allow")
"deny" to jsonArray("deny")
"uploadType" to "nfs"
}.toString(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal class PmcSubmissionSubmitterTest {
"orcid" to "orcid"
"allow" to jsonArray("allow")
"deny" to jsonArray("deny")
"uploadType" to "nfs"
}.toString(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class SecurityPermission(val accessType: AccessType, val accessTag: String)
sealed interface UserFolder {
val relativePath: Path
val path: Path
val type: String
}

data class FtpUserFolder(
Expand All @@ -36,9 +37,13 @@ data class FtpUserFolder(
* The File system ftp path. Used to access ftp files as file system file.
*/
override val path: Path,
) : UserFolder
) : UserFolder {
override val type = "ftp"
}

data class NfsUserFolder(override val relativePath: Path, override val path: Path) : UserFolder
data class NfsUserFolder(override val relativePath: Path, override val path: Path) : UserFolder {
override val type = "nfs"
}

fun NfsUserFolder.resolve(subPath: String): Path = path.resolve(subPath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package ac.uk.ebi.biostd.itest.test.security

import ac.uk.ebi.biostd.client.exception.WebClientException
import ac.uk.ebi.biostd.client.integration.web.SecurityWebClient
import ac.uk.ebi.biostd.itest.common.SecurityTestService
import ac.uk.ebi.biostd.itest.entities.FtpSuperUser
import ac.uk.ebi.biostd.itest.entities.TestUser
import ac.uk.ebi.biostd.itest.itest.getWebClient
import ac.uk.ebi.biostd.persistence.repositories.UserDataRepository
import ebi.ac.uk.api.security.CheckUserRequest
import ebi.ac.uk.api.security.LoginRequest
import ebi.ac.uk.api.security.RegisterRequest
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.BeforeAll
Expand All @@ -23,6 +27,7 @@ import kotlin.test.assertNotNull
class SecurityApiTest(
@LocalServerPort val serverPort: Int,
@Autowired private val userDataRepository: UserDataRepository,
@Autowired val securityTestService: SecurityTestService,
) {
private lateinit var webClient: SecurityWebClient

Expand Down Expand Up @@ -74,6 +79,37 @@ class SecurityApiTest(
assertThat(user.email).isEqualTo("case-insensitive-inactive@mail.org")
}

@Test
fun `22-6 check ftp home type user`() =
runTest {
securityTestService.ensureUserRegistration(FtpSuperUser)
val client = getWebClient(serverPort, FtpSuperUser)

val result = client.getProfile()

assertThat(result.uploadType).isEqualTo("ftp")
}

@Test
fun `22-7 check Nfs home type user`() =
runTest {
securityTestService.ensureUserRegistration(NfsUser)
val client = getWebClient(serverPort, NfsUser)

val result = client.getProfile()

assertThat(result.uploadType).isEqualTo("nfs")
}

object NfsUser : TestUser {
override val username = "New Nfs User"
override val email = "new-nfs-biostudies-mgmt@ebi.ac.uk"
override val password = "12345"
override val superUser = true

override fun asRegisterRequest() = RegisterRequest(username, email, password)
}

object NewUser : TestUser {
override val username = "New User"
override val email = "new-biostudies-mgmt@ebi.ac.uk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
| SecurityApiTest | 22-3 | login when inactive | |
| SecurityApiTest | 22-4 | case insensitive user registration | |
| SecurityApiTest | 22-5 | case insensitive inactive registration | |
| SecurityApiTest | 22-6 | check ftp home type user | |
| SecurityApiTest | 22-7 | check Nfs home type user | |
| SubmissionDraftListApiTest | 23-1 | get draft by key | Shows how to get drafts, paginated or not. |
| SubmissionDraftListApiTest | 23-2 | get drafts without pagination | |
| SubmissionDraftListApiTest | 23-3 | get drafts with pagination | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SecurityMapper {
orcid = user.orcid.orEmpty(),
allow = getAllow(user),
secret = user.userFolder.relativePath.toString(),
uploadType = user.userFolder.type,
)
}

Expand Down

0 comments on commit 5951019

Please sign in to comment.