generated from ministryofjustice/hmpps-template-kotlin
-
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.
CDPS-1054: Added basic tests for prototype functionality and applied …
…auto-formating.
- Loading branch information
Showing
10 changed files
with
288 additions
and
26 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
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
45 changes: 45 additions & 0 deletions
45
...tegrationapi/common/config/UserEnhancedOAuth2ClientCredentialGrantRequestConverterTest.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,45 @@ | ||
package uk.gov.justice.digital.hmpps.personintegrationapi.common.config | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest | ||
import org.springframework.security.oauth2.client.registration.ClientRegistration | ||
import org.springframework.security.oauth2.core.AuthorizationGrantType | ||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod | ||
import org.springframework.util.LinkedMultiValueMap | ||
import uk.gov.justice.digital.hmpps.personintegrationapi.config.UserEnhancedOAuth2ClientCredentialGrantRequestConverter | ||
|
||
class UserEnhancedOAuth2ClientCredentialGrantRequestConverterTest { | ||
|
||
private lateinit var oAuth2ClientCredentialsGrantRequest: OAuth2ClientCredentialsGrantRequest | ||
|
||
private val underTest: UserEnhancedOAuth2ClientCredentialGrantRequestConverter = | ||
UserEnhancedOAuth2ClientCredentialGrantRequestConverter() | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
oAuth2ClientCredentialsGrantRequest = OAuth2ClientCredentialsGrantRequest(CLIENT_REGISTRATION) | ||
} | ||
|
||
@Test | ||
fun `client credentials grant request has the username added`() { | ||
val response = underTest.enhanceWithUsername(oAuth2ClientCredentialsGrantRequest, TEST_USERNAME) | ||
assertThat((response.body as LinkedMultiValueMap<*, *>)["username"]).isEqualTo(listOf(TEST_USERNAME)) | ||
} | ||
|
||
companion object { | ||
const val TEST_USERNAME = "TEST_USERNAME" | ||
val CLIENT_REGISTRATION: ClientRegistration = | ||
ClientRegistration | ||
.withRegistrationId("test_id") | ||
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC) | ||
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS) | ||
.tokenUri("oauth/token") | ||
.scope("read") | ||
.userNameAttributeName("id") | ||
.clientName("Client Name") | ||
.clientId("client-id") | ||
.clientSecret("client-secret").build() | ||
} | ||
} |
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
Oops, something went wrong.