Skip to content

Commit

Permalink
fix test file and merge conflicts locally
Browse files Browse the repository at this point in the history
  • Loading branch information
NkwaTambe committed Jan 9, 2025
1 parent d1abea0 commit edaa817
Showing 1 changed file with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
package com.adorsys.webank.serviceimpl;
import static org.junit.jupiter.api.Assertions.*;

import com.twilio.rest.api.v2010.account.MessageCreator;

import com.adorsys.webank.exceptions.HashComputationException;
import org.junit.jupiter.api.Test;
import com.adorsys.webank.exceptions.FailedToSendOTPException;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import static org.mockito.ArgumentMatchers.any;
import com.twilio.*;
import com.twilio.rest.api.v2010.account.*;
import com.twilio.type.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.*;
import org.mockito.*;
import org.mockito.junit.jupiter.*;
import org.springframework.test.util.*;

@ExtendWith(MockitoExtension.class)
import java.nio.charset.*;
import java.security.*;
import java.util.*;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;

@ExtendWith(MockitoExtension.class)
public class OtpServiceTest {


OtpServiceImpl otpServiceImpl = new OtpServiceImpl();

@InjectMocks
Expand Down Expand Up @@ -61,7 +52,6 @@ void testTwilioConnection() {
assertDoesNotThrow(() -> Twilio.init("testAccountSid", "testAuthToken"));
}


@Test
void testSendOtpSuccessfully() {
// Mock the MessageCreator and Message
Expand Down Expand Up @@ -91,20 +81,23 @@ void testSendOtpSuccessfully() {
// Update the assertion to check Base64 format
assertTrue(otpHash.matches("[a-zA-Z0-9+/=]+"), "OTP hash should be a valid Base64 string");
}
}

@Test
void testComputeHashWithValidInputs() throws NoSuchAlgorithmException {
String otp = "1234";
String phoneNumber = "+237654066316";
String publicKey = "public-key-123";
String salt = "unique-salt";

// Expected hash computation
String input = otp + phoneNumber + publicKey + salt;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = digest.digest(input.getBytes(StandardCharsets.UTF_8));
String expectedHash = Base64.getEncoder().encodeToString(hashBytes);

// Compute hash using the method
String actualHash = otpServiceImpl.computeHash(otp, phoneNumber, publicKey, salt);

assertNotNull(actualHash, "Hash should not be null");
assertEquals(expectedHash, actualHash, "Hashes should match");
}
Expand All @@ -115,10 +108,10 @@ void testComputeHashWithEmptyInputs() {
String phoneNumber = "";
String publicKey = "";
String salt = "";

String actualHash = otpServiceImpl.computeHash(otp, phoneNumber, publicKey, salt);

assertNotNull(actualHash, "Hash should not be null");
assertFalse(actualHash.isEmpty(), "Hash should not be empty");
}


}

0 comments on commit edaa817

Please sign in to comment.