Skip to content

Commit

Permalink
possible quality gate fix (#408)
Browse files Browse the repository at this point in the history
* possible quality gate fix

* added more unit test to improve coverage
  • Loading branch information
jitumiah authored Jul 8, 2020
1 parent 02ed6b2 commit 5161789
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
44 changes: 1 addition & 43 deletions src/main/java/uk/gov/hmcts/reform/idam/web/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,49 +65,7 @@
import static java.util.Optional.ofNullable;
import static uk.gov.hmcts.reform.idam.web.UserController.GENERIC_ERROR_KEY;
import static uk.gov.hmcts.reform.idam.web.UserController.GENERIC_SUB_ERROR_KEY;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.CLIENTID;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.CLIENT_ID;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.CODE;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.CONTACT_US_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.COOKIES_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.EMAIL;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.ERRORPAGE_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.ERROR_MSG;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.ERROR_SUB_MSG;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.EXPIRED_PASSWORD_RESET_LINK_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.FORGOTPASSWORDSUCCESS_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.FORGOTPASSWORD_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.HAS_ERRORS;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.HAS_LOGIN_FAILED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.HAS_OTP_CHECK_FAILED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.HAS_OTP_SESSION_EXPIRED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.HAS_POLICY_CHECK_FAILED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.INDEX_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.INVALID_PIN;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.IS_ACCOUNT_LOCKED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.IS_ACCOUNT_SUSPENDED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.JWT;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.LOGIN_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.LOGIN_WITH_PIN_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.PAGE_NOT_FOUND_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.PASSWORD;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.PRIVACY_POLICY_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.REDIRECTURI;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.REDIRECT_URI;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.RESETPASSWORD_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.RESPONSE_TYPE;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.SCOPE;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.SELF_REGISTRATION_ENABLED;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.STALE_USER_RESET_PASSWORD_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.STATE;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.TACTICAL_ACTIVATE_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.TACTICAL_RESET_PWD_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.TERMS_AND_CONDITIONS_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.UPLIFT_LOGIN_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.UPLIFT_REGISTER_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.USERCREATED_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.USERNAME;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.VERIFICATION_VIEW;
import static uk.gov.hmcts.reform.idam.web.helper.MvcKeys.*;

@Slf4j
@Controller
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/uk/gov/hmcts/reform/idam/web/AppControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,31 @@ public void login_onAuthenticateThrowsNotFoundWithStaleUserRegistrationCode_retu
}


@Test
public void login_onAuthenticateThrowsNotFoundWithStaleUserRegistrationCode_withNonStaleUserResponseCode_returnLoginView() throws Exception {

List<String> cookieList = singletonList(AUTHENTICATE_SESSION_COOKE);
given(spiService.authenticate(eq(USER_EMAIL), eq(USER_PASSWORD), eq(USER_IP_ADDRESS))).willReturn(cookieList);
given(spiService.authorize(any(), eq(cookieList))).willThrow(new HttpClientErrorException(HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN.name(), HAS_LOGIN_FAILED_RESPONSE.getBytes(), null));
given(policyService.evaluatePoliciesForUser(any(), any(), any()))
.willReturn(PolicyService.EvaluatePoliciesAction.ALLOW);

given(spiService.authorize(any(), eq(cookieList))).willThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.name(), "{\"code\":\"someErrorCode\"}".getBytes(), null));

mockMvc.perform(post(LOGIN_ENDPOINT).with(csrf())
.header(X_FORWARDED_FOR, USER_IP_ADDRESS)
.param(USERNAME_PARAMETER, USER_EMAIL)
.param(PASSWORD_PARAMETER, USER_PASSWORD)
.param(REDIRECT_URI, REDIRECT_URI)
.param(STATE_PARAMETER, STATE)
.param(RESPONSE_TYPE_PARAMETER, RESPONSE_TYPE)
.param(CLIENT_ID_PARAMETER, CLIENT_ID)
.param(SCOPE_PARAMETER, CUSTOM_SCOPE))
.andExpect(status().isOk())
.andExpect(view().name(LOGIN_VIEW));
}


@Test
public void login_onAuthenticateThrowsNotFoundWithStaleUserRegistrationCode_withBadResponseDate_returnLoginView() throws Exception {

Expand Down

0 comments on commit 5161789

Please sign in to comment.