generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e742551
commit 247be97
Showing
43 changed files
with
1,058 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Suppressed as we do not process any untrusted YML content | ||
# Note: this will be resolved in Spring Boot 3.2: https://github.com/spring-projects/spring-boot/issues/35982 | ||
CVE-2022-1471 exp:2023-12-01 |
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
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
37 changes: 35 additions & 2 deletions
37
...ts/hdc-licences-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt
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 |
---|---|---|
@@ -1,25 +1,58 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.annotation.PostConstruct | ||
import jakarta.persistence.EntityManager | ||
import jakarta.transaction.Transactional | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.data.generator.IdGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator | ||
import uk.gov.justice.digital.hmpps.entity.Borough | ||
import uk.gov.justice.digital.hmpps.entity.CommunityManagerEntity | ||
import uk.gov.justice.digital.hmpps.entity.District | ||
import uk.gov.justice.digital.hmpps.entity.Person | ||
import uk.gov.justice.digital.hmpps.entity.ProbationArea | ||
import uk.gov.justice.digital.hmpps.entity.StaffEntity | ||
import uk.gov.justice.digital.hmpps.entity.Team | ||
import uk.gov.justice.digital.hmpps.entity.User | ||
import uk.gov.justice.digital.hmpps.set | ||
import uk.gov.justice.digital.hmpps.user.AuditUserRepository | ||
|
||
@Component | ||
@ConditionalOnProperty("seed.database") | ||
class DataLoader( | ||
private val auditUserRepository: AuditUserRepository | ||
private val auditUserRepository: AuditUserRepository, | ||
private val entityManager: EntityManager | ||
) : ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@PostConstruct | ||
fun saveAuditUser() { | ||
auditUserRepository.save(UserGenerator.AUDIT_USER) | ||
} | ||
|
||
@Transactional | ||
override fun onApplicationEvent(are: ApplicationReadyEvent) { | ||
// Perform dev/test database setup here, using JPA repositories and generator classes... | ||
val probationArea = ProbationArea(id = id(), code = "TST", description = "Test") | ||
val borough = Borough(id = id(), code = "PDU", description = "Probation Delivery Unit", probationArea = probationArea) | ||
.also { probationArea.set(ProbationArea::boroughs, setOf(it)) } | ||
val district = District(id = id(), code = "LAU", description = "Local Admin Unit", borough = borough) | ||
.also { borough.set(Borough::districts, setOf(it)) } | ||
val team1 = Team(id = id(), code = "TEAM01", description = "Team 1", district = district, probationArea = probationArea) | ||
val team2 = Team(id = id(), code = "TEAM02", description = "Team 2", district = district, probationArea = probationArea) | ||
val staff = StaffEntity(id = id(), code = "STAFF01", forename = "Test", surname = "Staff", teams = listOf(team1, team2)) | ||
val user = User(id = id(), username = "test.user", staff = staff) | ||
.also { staff.set(StaffEntity::user, it) } | ||
val person = Person(id = id(), nomsNumber = "PERSON1") | ||
val previousManager = CommunityManagerEntity(id = id(), person = person, staff = staff, team = team1, active = false) | ||
val currentManager = CommunityManagerEntity(id = id(), person = person, staff = staff, team = team2, active = true) | ||
.also { staff.set(StaffEntity::communityManagers, setOf(it)) } | ||
.also { person.set(Person::communityManagers, listOf(it)) } | ||
|
||
listOf(probationArea, borough, district, team1, team2, staff, user, person, previousManager, currentManager) | ||
.forEach(entityManager::persist) | ||
} | ||
|
||
private fun id() = IdGenerator.getAndIncrement() | ||
} |
8 changes: 4 additions & 4 deletions
8
projects/hdc-licences-and-delius/src/dev/resources/local-public-key.pub
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo3hw1/oChbttEOxEH4NUDrH+Y | ||
n2x0DavAmDjMbhcSiQ6+/t8Nz/N03BauWzFOGBtftnQrHfnF+O7RAKj8zMjcbIq4 | ||
QrYeXEpnaFCGEwTtOBpxvSEWPrLEpr1gCarBQZDp67ag+SYqrDgkn2Vme/dMvMUQ | ||
xUO3DT6jg9921J6TlwIDAQAB | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMwjPPJWNVkkbz1rvp5gfIgikJ | ||
tiar18XcBScET2wOs7nAviD0nBzLByMGfexX0LQz3J9+S0Ut/bSqPyrgPe9Wc5s9 | ||
6JwH6biAYzuLOVhLXBpmwGP6FpZIoSA+VkwApLN9j8qPBvAYrIftpTWsEq090VUE | ||
WHvs4bqvS01yN7IPTwIDAQAB | ||
-----END PUBLIC KEY----- |
49 changes: 49 additions & 0 deletions
49
projects/hdc-licences-and-delius/src/dev/resources/schema.ldif
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,49 @@ | ||
dn: dc=moj,dc=com | ||
dc: moj | ||
objectclass: top | ||
objectclass: domain | ||
|
||
dn: ou=Users,dc=moj,dc=com | ||
ou: Users | ||
objectclass: top | ||
objectclass: organizationalUnit | ||
|
||
dn: cn=ndRoleCatalogue,ou=Users,dc=moj,dc=com | ||
cn: ndRoleCatalogue | ||
objectclass: top | ||
objectclass: javaContainer | ||
|
||
dn: cn=LHDCBT002,cn=ndRoleCatalogue,ou=Users,dc=moj,dc=com | ||
cn: LHDCBT002 | ||
description: Digital Licence Create | ||
objectclass: top | ||
objectClass: NDRole | ||
|
||
dn: cn=LHDCBT003,cn=ndRoleCatalogue,ou=Users,dc=moj,dc=com | ||
cn: LHDCBT003 | ||
description: Digital Licence Vary | ||
objectclass: top | ||
objectClass: NDRole | ||
|
||
dn: cn=test.user,ou=Users,dc=moj,dc=com | ||
cn: test.user | ||
objectclass: NDUser | ||
objectclass: inetOrgPerson | ||
objectclass: top | ||
givenName: Test | ||
sn: User | ||
mail: [email protected] | ||
|
||
dn: cn=LHDCBT002,cn=test.user,ou=Users,dc=moj,dc=com | ||
cn: LHDCBT002 | ||
objectclass: top | ||
objectClass: NDRoleAssociation | ||
|
||
dn: cn=inactive.user,ou=Users,dc=moj,dc=com | ||
cn: inactive.user | ||
objectclass: NDUser | ||
objectclass: inetOrgPerson | ||
objectclass: top | ||
givenName: Inactive | ||
sn: User | ||
endDate: 20000101 |
2 changes: 1 addition & 1 deletion
2
.../hdc-licences-and-delius/src/dev/resources/simulations/__files/hmpps-auth-token-body.json
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
31 changes: 0 additions & 31 deletions
31
...ces-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
...delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProviderIntegrationTest.kt
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,74 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.security.withOAuth2Token | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class ProviderIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
lateinit var wireMockServer: WireMockServer | ||
|
||
@Test | ||
fun `providers are returned successfully`() { | ||
mockMvc | ||
.perform(get("/providers").withOAuth2Token(wireMockServer)) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("length()", equalTo(1))) | ||
.andExpect(jsonPath("[0].code", equalTo("TST"))) | ||
.andExpect(jsonPath("[0].description", equalTo("Test"))) | ||
} | ||
|
||
@Test | ||
fun `single provider is returned successfully`() { | ||
mockMvc | ||
.perform(get("/providers/TST").withOAuth2Token(wireMockServer)) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("code", equalTo("TST"))) | ||
.andExpect(jsonPath("description", equalTo("Test"))) | ||
.andExpect(jsonPath("localAdminUnits.length()", equalTo(1))) | ||
.andExpect(jsonPath("localAdminUnits[0].code", equalTo("LAU"))) | ||
.andExpect(jsonPath("localAdminUnits[0].description", equalTo("Local Admin Unit"))) | ||
} | ||
|
||
@Test | ||
fun `non-existent provider returns 404`() { | ||
mockMvc | ||
.perform(get("/providers/DOESNOTEXIST").withOAuth2Token(wireMockServer)) | ||
.andExpect(status().isNotFound) | ||
} | ||
|
||
@Test | ||
fun `local admin unit is returned successfully`() { | ||
mockMvc | ||
.perform(get("/providers/TST/localAdminUnits/LAU").withOAuth2Token(wireMockServer)) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("code", equalTo("LAU"))) | ||
.andExpect(jsonPath("description", equalTo("Local Admin Unit"))) | ||
.andExpect(jsonPath("teams.length()", equalTo(2))) | ||
.andExpect(jsonPath("teams[0].code", equalTo("TEAM01"))) | ||
.andExpect(jsonPath("teams[0].description", equalTo("Team 1"))) | ||
.andExpect(jsonPath("teams[1].code", equalTo("TEAM02"))) | ||
.andExpect(jsonPath("teams[1].description", equalTo("Team 2"))) | ||
} | ||
|
||
@Test | ||
fun `non-existent local admin unit returns 404`() { | ||
mockMvc | ||
.perform(get("/providers/TST/localAdminUnits/DOESNOTEXIST").withOAuth2Token(wireMockServer)) | ||
.andExpect(status().isNotFound) | ||
} | ||
} |
Oops, something went wrong.