Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
RDCC-2067: Referring to New S2S Secret & Addressing All Sonar Issues …
Browse files Browse the repository at this point in the history
…in Master (#466)

* RDCC-2067: referring to new S2S Secret in values, bootstrap & values.preview.template yaml files

* RDCC-2067: updating S2S Name in tests

* RDCC-2067: addressing all Sonar Issue in Master

* Bumping chart version

Co-authored-by: Jenkins <nobody@nowhere>
Co-authored-by: hmcts-jenkins-rd <62425331+hmcts-jenkins-rd[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 3, 2021
1 parent 1c1ef72 commit 5f56f21
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion charts/rd-profile-sync/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
appVersion: "0.1"
description: Reference data service for professional users
name: rd-profile-sync
version: 0.0.10
version: 0.0.11
2 changes: 1 addition & 1 deletion charts/rd-profile-sync/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ java:
keyVaults:
rd:
secrets:
- professional-api-s2s-secret
- profile-sync-s2s-secret
- OAUTH2-AUTH
2 changes: 1 addition & 1 deletion charts/rd-profile-sync/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ java:
keyVaults:
rd:
secrets:
- professional-api-s2s-secret
- profile-sync-s2s-secret
- profile-sync-POSTGRES-PASS
- AppInsightsInstrumentationKey
- OAUTH2-CLIENT-SECRET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setupS2sAndIdamStubs() throws Exception {
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("rd_professional_api")));
.withBody("rd_profile_sync")));

s2sService.stubFor(WireMock.post(urlEqualTo("/lease"))
.willReturn(aResponse()
Expand Down
2 changes: 1 addition & 1 deletion src/integrationTest/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ idam:

s2s-auth:
totp_secret: ${S2S_SECRET:AAAAAAAAAAAAAAAA}
microservice: rd_professional_api
microservice: rd_profile_sync
url: ${S2S_URL:http://127.0.0.1:8990}
s2s-authorised:
services: ${SYNC_S2S_AUTHORISED_SERVICES:rd_professional_api}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Set<IdamClient.User> getSyncFeed(String bearerToken, String searchQuery)t

try {
List<String> headerCount = responseEntity.getHeaders().get("X-Total-Count");
if (headerCount != null && headerCount.size() > 0
if (headerCount != null && !headerCount.isEmpty()
&& !headerCount.get(0).isEmpty()) {

totalCount = Integer.parseInt(headerCount.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Optional<Object> decode(Response response, Object clazz) {
public static ResponseEntity<Object> toResponseEntity(Response response, Object clazz) {
Optional<Object> payload = decode(response, clazz);

return new ResponseEntity<Object>(
return new ResponseEntity<>(
payload.orElse(null),
convertHeaders(response.headers()),
HttpStatus.valueOf(response.status()));
Expand All @@ -58,7 +58,7 @@ public static ResponseEntity<Object> toResponseEntity(Response response, TypeRe
log.error("error while reading the body", ex);
}

return new ResponseEntity<Object>(
return new ResponseEntity<>(
payload.orElse(null),
convertHeaders(response.headers()),
HttpStatus.valueOf(response.status()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
prefixed: false
paths: /mnt/secrets/rd
aliases:
professional-api-s2s-secret: S2S_SECRET
profile-sync-s2s-secret: S2S_SECRET
profile-sync-POSTGRES-PASS: spring.datasource.password
OAUTH2-CLIENT-SECRET: idam.api-redirect-uri
OAUTH2-AUTH: idam.api.authorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public void test_create_exception_correctly() {
String message = "this-is-a-test-message";
UserProfileSyncException exception = new UserProfileSyncException(HttpStatus.NOT_FOUND, message);

assertThat(exception).hasMessage(message);
assertThat(exception).isInstanceOf(RuntimeException.class);
assertThat(exception)
.hasMessage(message)
.isInstanceOf(RuntimeException.class);
assertThat(exception.getHttpStatus()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getErrorMessage()).isEqualTo("this-is-a-test-message");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ServiceTokenGeneratorConfigurationTest {
@Test
public void testServiceAuthTokenGenerator() {
final String secret = "A6A6PRLRFWQLKP6";
final String microService = "rd_professional_api";
final String microService = "rd_profile_sync";
final ServiceAuthorisationApi serviceAuthorisationApiMock = Mockito.mock(ServiceAuthorisationApi.class);

AuthTokenGenerator authTokenGenerator = sut.serviceAuthTokenGenerator(secret, microService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void shouldReturnHashCode() {
ProfileSyncAudit syncJobAudit = new ProfileSyncAudit(LocalDateTime.now(), status);
ProfileSyncAuditDetailsId syncAuditDetailsId = new ProfileSyncAuditDetailsId(syncJobAudit, userId);
int userIdValue = syncAuditDetailsId.hashCode();
assertThat(userIdValue).isNotEqualTo(0);
assertThat(userIdValue).isNotZero();
}

@Test
Expand All @@ -44,7 +44,7 @@ public void shouldReturnEqual() {
ProfileSyncAuditDetailsId syncAuditDetailsId = new ProfileSyncAuditDetailsId(syncJobAudit, userId);
ProfileSyncAuditDetailsId syncAuditDetailsIdOne = new ProfileSyncAuditDetailsId(syncJobAudit, userId);
assertEquals(syncAuditDetailsIdOne, syncAuditDetailsId);
assertThat(syncAuditDetailsId.hashCode()).isEqualTo(syncAuditDetailsIdOne.hashCode());
assertThat(syncAuditDetailsId.hashCode()).hasSameHashCodeAs(syncAuditDetailsIdOne.hashCode());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void findAllProfileSyncAuditDetails() {
assertThat(profileSyncAuditDetail.getCreated()).isNotNull();
assertThat(profileSyncAuditDetail.getErrorDescription()).isNotNull();
assertThat(profileSyncAuditDetail.getErrorDescription()).isEqualTo("success");
assertThat(profileSyncAuditDetail.getStatusCode()).isNotEqualTo(0);
assertThat(profileSyncAuditDetail.getStatusCode()).isNotZero();
assertThat(profileSyncAuditDetail.getStatusCode()).isEqualTo(200);

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ public void shouldResolveAndReturnIdamStatusByIdamFlagsActive() {
sb.append("true");
sb.append("false");
String status = sut.resolveIdamStatus(sb);
assertThat(status).isEqualTo(IdamStatus.ACTIVE.name());
assertThat(status).isNotEqualTo(IdamStatus.PENDING.name());
assertThat(status).isNotEqualTo(IdamStatus.SUSPENDED.name());
assertThat(status)
.isEqualTo(IdamStatus.ACTIVE.name())
.isNotEqualTo(IdamStatus.PENDING.name())
.isNotEqualTo(IdamStatus.SUSPENDED.name());
}

@Test
Expand All @@ -167,17 +168,19 @@ public void shouldResolveAndReturnIdamStatusByIdamFlagsPending() {
sb.append("false");
sb.append("true");
String status = sut.resolveIdamStatus(sb);
assertThat(status).isNotEqualTo(IdamStatus.ACTIVE.name());
assertThat(status).isEqualTo(IdamStatus.PENDING.name());
assertThat(status).isNotEqualTo(IdamStatus.SUSPENDED.name());
assertThat(status)
.isNotEqualTo(IdamStatus.ACTIVE.name())
.isEqualTo(IdamStatus.PENDING.name())
.isNotEqualTo(IdamStatus.SUSPENDED.name());
}

@Test
public void shouldResolveAndReturnIdamStatusByIdamFlagsSuspending() {
StringBuilder sb = new StringBuilder();
String status = sut.resolveIdamStatus(sb);
assertThat(status).isEqualTo(IdamStatus.SUSPENDED.name());
assertThat(status).isNotEqualTo(IdamStatus.ACTIVE.name());
assertThat(status).isNotEqualTo(IdamStatus.PENDING.name());
assertThat(status)
.isEqualTo(IdamStatus.SUSPENDED.name())
.isNotEqualTo(IdamStatus.ACTIVE.name())
.isNotEqualTo(IdamStatus.PENDING.name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void findUserThrowExceptionWith400() throws IOException {
Optional<GetUserProfileResponse> getUserProfileResponse = sut.findUser(bearerToken, s2sToken, id);

assertThat(getUserProfileResponse).isNull();
assertThat(getUserProfileResponse.isPresent()).isFalse();
assertThat(getUserProfileResponse).isNotPresent();
verify(userProfileClientMock, times(1)).findUser(any(), any(), any());
}

Expand All @@ -102,7 +102,7 @@ public void findUserThrowExceptionWith401WithNoBody() throws IOException {
Optional<GetUserProfileResponse> getUserProfileResponse = sut.findUser(bearerToken, s2sToken, id);

assertThat(getUserProfileResponse).isNull();
assertThat(getUserProfileResponse.isPresent()).isFalse();
assertThat(getUserProfileResponse).isNotPresent();
verify(userProfileClientMock, times(1)).findUser(any(), any(), any());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void testToResponseEntityThrowError() throws IOException {
@Test
public void testToResponseEntityThrowErrorDecode() throws IOException {
when(bodyMock.asReader(Charset.defaultCharset())).thenThrow(IOException.class);
Optional actual = JsonFeignResponseUtil.decode(this.responseMock, String.class);
Optional<Object> actual = JsonFeignResponseUtil.decode(this.responseMock, String.class);

assertThat(actual.isPresent()).isFalse();
assertThat(actual).isNotPresent();
}

@Test
Expand Down

0 comments on commit 5f56f21

Please sign in to comment.