Skip to content

Commit

Permalink
ES-391 (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: ase-101 <[email protected]>
Signed-off-by: Sreang Rathanak <[email protected]>
  • Loading branch information
ase-101 authored and Sreang Rathanak committed Jan 15, 2024
1 parent 6c32715 commit d2d896c
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void setUp() {
registrationService, "resendAttempts", 3);
ReflectionTestUtils.setField(
registrationService, "resendDelay", 30);
ReflectionTestUtils.setField(
registrationService, "challengeTimeout", 60);
ReflectionTestUtils.setField(registrationService, getIdentityEndpoint, getIdentityEndpoint);
ReflectionTestUtils.setField(registrationService, "objectMapper", new ObjectMapper());
ReflectionTestUtils.setField(registrationService, "otpLength", 6);
Expand All @@ -109,7 +111,7 @@ public void doVerifyChallenge_thenPass() {
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challengeInfo.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);


Expand Down Expand Up @@ -147,7 +149,7 @@ public void doVerifyChallenge_thenIdentifierAlreadyRegisterError() {
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challengeInfo.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);
RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
IdentityResponse identityResponse = new IdentityResponse();
Expand Down Expand Up @@ -190,7 +192,7 @@ public void doVerifyChallenge_toResetPassword_thenIdentifierNotFound() {
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challengeInfo.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
Expand Down Expand Up @@ -236,7 +238,7 @@ public void doVerifyChallenge_toResetPassword_thenIdentifierNotFound_WhenIdRepoR
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challengeInfo.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
Expand Down Expand Up @@ -282,6 +284,7 @@ public void doVerifyChallenge_toResetPassword_withOTPMismatchFormat_thenChalleng
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down Expand Up @@ -312,6 +315,7 @@ public void doVerifyChallenge_toResetPassword_withKBAMismatchFormat_thenChalleng
challengeInfoKBA.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down Expand Up @@ -349,7 +353,7 @@ public void doVerifyChallenge_toResetPassword_thenInvalidKBAChallenge() {
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
Expand Down Expand Up @@ -408,7 +412,7 @@ public void doVerifyChallenge_toResetPassword_thenFullNameMismatch() {
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
Expand Down Expand Up @@ -466,7 +470,7 @@ public void doVerifyChallenge_toResetPassword_thenSuccess() {
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256,
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

Expand Down Expand Up @@ -517,6 +521,7 @@ public void doVerifyChallenge_withInvalidFormatForOTPChallenge_thenFail() {
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down Expand Up @@ -554,7 +559,7 @@ public void doVerifyChallenge_toResetPassword_thenIdentityInactive() {
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

RestResponseWrapper<IdentityResponse> restResponseWrapper = new RestResponseWrapper<>();
Expand Down Expand Up @@ -605,7 +610,7 @@ public void doVerifyChallenge_toResetPassword_thenKBAChallengeNotFound() {
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256,
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

Expand Down Expand Up @@ -664,7 +669,7 @@ public void doVerifyChallenge_toResetPassword_thenFetchIdentityFailed() {
challengeInfoOTP.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);
when(selfTokenRestTemplate.exchange(
eq(getIdentityEndpoint),
Expand Down Expand Up @@ -724,7 +729,7 @@ public void doVerifyChallenge_withChallengeNotMatch_thenFail() throws Exception
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", Purpose.REGISTRATION);
registrationTransaction.setChallengeHash("failed");
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down Expand Up @@ -752,6 +757,7 @@ public void doVerifyChallenge_withIdentifierNotMatch_throwsException() throws Ex
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", Purpose.REGISTRATION);
registrationTransaction.setChallengeHash(challengeInfo.getChallenge());
registrationTransaction.setIdentifier("failed");
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down Expand Up @@ -1768,6 +1774,7 @@ public void doVerifyChallenge_withExpiredChallenge_thenFail() throws Exception {
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", Purpose.REGISTRATION);
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(2));
when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction);

try {
Expand Down

0 comments on commit d2d896c

Please sign in to comment.