Search in sources :

Example 1 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class ForgotPasswordTest method sendWrongAnswerWithNewPassword.

@Test
public void sendWrongAnswerWithNewPassword() {
    ForgotPasswordData forgotPassData = new ForgotPasswordData(null, authQuestionAnswer + "bla");
    Login ansAndPassContainer = new Login(worker.getUsername(), newPass, forgotPassData);
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.FORGOT_PASSWORD_SEND_ANSWER_WITH_NEW_PASSWORD, Serialization.serialize(ansAndPassContainer)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_FOROGT_PASSWORD_WRONG_ANSWER, null).serialize());
    } catch (IOException ยข) {
        fail();
    }
    try {
        ((IForgotPasswordHandler) worker).sendAnswerAndNewPassword(authQuestionAnswer + "bla", newPass);
    } catch (WrongAnswer e) {
        //success
        return;
    } catch (NoSuchUserName e) {
        fail();
    }
    fail();
}
Also used : WrongAnswer(UtilsImplementations.ForgotPasswordHandler.WrongAnswer) IForgotPasswordHandler(UtilsContracts.IForgotPasswordHandler) NoSuchUserName(UtilsImplementations.ForgotPasswordHandler.NoSuchUserName) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testAddRemoveWorker.

@Test
public void testAddRemoveWorker() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    //test add worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
        fail();
    }
    assert result != null;
    HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert map.containsKey(workerName);
    assertEquals(false, map.get(workerName));
    //test remove worker
    try {
        sqlConnection.removeWorker(null, workerName);
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientNotExist e) {
        fail();
    }
    assert result != null;
    map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert !map.containsKey(workerName);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 3 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class CustomerRegistration_FinalStepScreen method registerButtonPressed.

@FXML
void registerButtonPressed(ActionEvent __) {
    ICustomer customer = InjectionFactory.getInstance(Customer.class);
    ICustomerProfile iProfile = TempCustomerProfilePassingData.customerProfile;
    CustomerProfile profile = new CustomerProfile(iProfile.getUserName(), TempCustomerProfilePassingData.password, iProfile.getFirstName(), iProfile.getLastName(), iProfile.getPhoneNumber(), iProfile.getEmailAddress(), iProfile.getCity(), iProfile.getStreet(), iProfile.getBirthdate(), iProfile.getAllergens(), new ForgotPasswordData(TempCustomerProfilePassingData.sequrityQuestion, TempCustomerProfilePassingData.sequrityAnswer));
    try {
        customer.registerNewCustomer(profile);
        AbstractApplicationScreen.setScene("/CustomerLoginScreen/CustomerLoginScreen.fxml");
        TempCustomerProfilePassingData.clear();
    } catch (SMException e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
}
Also used : ICustomer(CustomerContracts.ICustomer) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ICustomerProfile(BasicCommonClasses.ICustomerProfile) ICustomerProfile(BasicCommonClasses.ICustomerProfile) CustomerProfile(BasicCommonClasses.CustomerProfile) SMException(SMExceptions.SMException) FXML(javafx.fxml.FXML)

Example 4 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testWorkerCanSetSecurityQA.

@Test
public void testWorkerCanSetSecurityQA() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ForgotPasswordData p = new ForgotPasswordData("question", "answer");
    String result = null;
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setSecurityQAWorker(workerName, p);
        result = sqlConnection.getSecurityQuestionWorker(workerName);
        assertTrue(sqlConnection.verifySecurityAnswerWorker(workerName, "answer"));
        assertEquals("question", result);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 5 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testWorkerCanLoginWithNewPassword.

@Test
public void testWorkerCanLoginWithNewPassword() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setPasswordWorker(workerName, "newPass");
        //try to login with new password
        int sessionID = sqlConnection.loginWorker(workerName, "newPass");
        sqlConnection.logout(sessionID, workerName);
    } catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Aggregations

ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)14 Test (org.junit.Test)11 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)9 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)9 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)9 Login (BasicCommonClasses.Login)8 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)6 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)4 CustomerProfile (BasicCommonClasses.CustomerProfile)3 CommandWrapper (ClientServerApi.CommandWrapper)3 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)2 IForgotPasswordHandler (UtilsContracts.IForgotPasswordHandler)2 NoSuchUserName (UtilsImplementations.ForgotPasswordHandler.NoSuchUserName)2 WrongAnswer (UtilsImplementations.ForgotPasswordHandler.WrongAnswer)2 IOException (java.io.IOException)2 FXML (javafx.fxml.FXML)2 ICustomerProfile (BasicCommonClasses.ICustomerProfile)1 ICustomer (CustomerContracts.ICustomer)1 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)1 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)1