Skip to content
Snippets Groups Projects
Commit bfe6b25d authored by MEDEDJI Setondji's avatar MEDEDJI Setondji :speech_balloon:
Browse files

Etape 1 rendu

parent 9915409c
No related branches found
No related tags found
No related merge requests found
File added
......@@ -5,13 +5,16 @@ import authentication.Strength;
public class AuthenticationByBiometryService implements AuthenticationService {
private DirectoryInterface directory;
private StrengthEstimationServiceInterface strengthEstimationService;
private Strength strength;
public AuthenticationByBiometryService(DirectoryInterface directory, StrengthEstimationServiceInterface strengthEstimationService) {
public AuthenticationByBiometryService(DirectoryInterface directory, Strength strength) {
this.directory = directory;
this.strengthEstimationService = strengthEstimationService;
this.strength = strength;
}
public void setDirectory(DirectoryInterface directory) {
this.directory = directory;
}
@Override
public boolean isAMatch(String identifier, String autenthicationData) {
......
......@@ -5,8 +5,15 @@ import authentication.Strength;
public class AuthenticationByPasswordService implements AuthenticationService {
private DirectoryInterface directory;
private StrengthEstimationServiceInterface strengthEstimationService;
public void setStrengthEstimationService(StrengthEstimationServiceInterface strengthEstimationService) {
this.strengthEstimationService = strengthEstimationService;
}
public AuthenticationByPasswordService(DirectoryInterface directory, StrengthEstimationServiceInterface strengthEstimationService) {
this.directory = directory;
this.strengthEstimationService = strengthEstimationService;
......@@ -23,28 +30,34 @@ public class AuthenticationByPasswordService implements AuthenticationService {
public Strength dataStrenth(String autenthicationData) {
int datasize = autenthicationData.length();
int alphabetSize = 142;
int strength = strengthEstimationService.equivalentBitLength(alphabetSize,datasize)
int strength = strengthEstimationService.equivalentBitLength(alphabetSize,datasize);
Strength result = null ;
if( strength >= 0 && strength <= 49 ) {
return Strength.VERY_WEAK;
result = Strength.VERY_WEAK;
}
if( strength >= 50 && strength <= 79 ) {
return Strength.WEAK;
else if ( strength >= 50 && strength <= 79 ) {
result = Strength.WEAK;
}
if ( strength >= 80 && strength <= 99 ) {
return Strength.REGULAR;
else if ( strength >= 80 && strength <= 99 ) {
result = Strength.REGULAR;
}
if ( strength >= 100 ) {
return Strength.STRONG;
else if ( strength >= 100 ) {
result = Strength.STRONG;
}
return result;
}
private boolean isMatch(String identifier, String autenthicationData) {
String match = directory.getMatch(identifier);
return match.equals(autenthicationData);
public void setDirectory(DirectoryInterface directory) {
this.directory = directory;
}
}
//private StrengthEstimationServiceInterface dataStrenth(String autenthicationData) {
// int alphabetSize = 0;
// int datasize = autenthicationData.length();
//return strengthEstimationService.equivalentBitLength(alphabetSize, datasize);
}
//}
package interfacemanualmocking;
import java.util.HashMap;
import java.util.Map;
public class MockDirectory implements DirectoryInterface{
private Map<String, String> dataMap;
public MockDirectory() {
dataMap = new HashMap<>();
dataMap.put("regix", "azerty");
dataMap.put("setondji", "mdpFort222");
}
@Override
public String getMatch(String identifier) {
System.out.println(dataMap.get(identifier));
return dataMap.get(identifier);
}
}
package interfacemanualmocking;
public class MockStrengthEstimationService implements StrengthEstimationServiceInterface{
private int dataSize;
private int alphabetSize;
public MockStrengthEstimationService() {
this.dataSize = 0;
this.alphabetSize = 0;
}
@Override
public int equivalentBitLength(int alphabetSize, int datasize) {
if(datasize > 0 && datasize < ((20 * 49)/ 142)){
return 10;
}
if (datasize < ((20 * 79)/ 142)){
return 60;
}
if (datasize < ((20 * 99)/ 142)){
return 82;
}
if (datasize >= 20){
return 110;
}
return alphabetSize;
}
}
import interfacemanualmocking.AuthenticationByBiometryService;
import interfacemanualmocking.AuthenticationByPasswordService;
import interfacemanualmocking.MockDirectory;
import interfacemanualmocking.MockStrengthEstimationService;
import org.junit.jupiter.api.*;
import static authentication.Strength.*;
import static authentication.Strength.STRONG;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class AuthenticationByBiometryServiceTest {
private MockDirectory directory;
private AuthenticationByBiometryService authenticationByBiometryService;
@BeforeAll
static void setUpBeforeClass() throws Exception {
System.out.println("Before all");
}
@AfterAll
static void tearDownAfterClass() throws Exception {
System.out.println("After all");
}
@BeforeEach
void setUp() {
directory = new MockDirectory();
authenticationByBiometryService = new AuthenticationByBiometryService(directory, STRONG);
authenticationByBiometryService.setDirectory(directory);
}
@AfterEach
void tearDown() throws Exception {
System.out.println("After each");
}
@Test
void testIsAMatch() {
assertThat(authenticationByBiometryService.isAMatch("regix", "azerty")).isTrue();
}
@Test
void testDataStrenth() {
assertThat(authenticationByBiometryService.dataStrenth("azerty")).isEqualTo(STRONG);
assertThat(authenticationByBiometryService.dataStrenth("azertyuiopqsdfghjklmwxcvbn1234567890")).isEqualTo(STRONG);
}
}
import interfacemanualmocking.AuthenticationByPasswordService;
import interfacemanualmocking.MockDirectory;
import interfacemanualmocking.MockStrengthEstimationService;
import org.junit.jupiter.api.*;
import static authentication.Strength.*;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class AuthenticationByPasswordServiceTest {
private MockDirectory directory;
private MockStrengthEstimationService strengthEstimationService;
private AuthenticationByPasswordService authenticationByPasswordService;
@BeforeAll
static void setUpBeforeClass() throws Exception {
System.out.println("Before all");
}
@AfterAll
static void tearDownAfterClass() throws Exception {
System.out.println("After all");
}
@BeforeEach
void setUp() {
directory = new MockDirectory();
strengthEstimationService = new MockStrengthEstimationService();
authenticationByPasswordService = new AuthenticationByPasswordService(directory, strengthEstimationService);
authenticationByPasswordService.setDirectory(directory);
authenticationByPasswordService.setStrengthEstimationService(strengthEstimationService);
}
@AfterEach
void tearDown() throws Exception {
System.out.println("After each");
}
@Test
void testIsAMatch() {
assertThat(authenticationByPasswordService.isAMatch("regix", "azerty")).isTrue();
assertThat(authenticationByPasswordService.isAMatch("setondji", "mdpFo222")).isFalse();
}
@Test
void testDataStrenth() {
assertThat(authenticationByPasswordService.dataStrenth("az")).isEqualTo(VERY_WEAK);
assertThat(authenticationByPasswordService.dataStrenth("azerTY")).isEqualTo(WEAK);
assertThat(authenticationByPasswordService.dataStrenth("azertyFFDD5")).isEqualTo(REGULAR);
assertThat(authenticationByPasswordService.dataStrenth("azertyuiopqsdfghjklmwxcvbn1234567890")).isEqualTo(STRONG);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment