logdb #56
| @ -364,29 +364,6 @@ func (h *MenuHandlers) ResetIncorrectPin(ctx context.Context, sym string, input | |||||||
| 	return res, nil | 	return res, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // VerifyNewPin checks if a new PIN meets the required format criteria.
 |  | ||||||
| func (h *MenuHandlers) VerifyNewPin(ctx context.Context, sym string, input []byte) (resource.Result, error) { |  | ||||||
| 	res := resource.Result{} |  | ||||||
| 	_, ok := ctx.Value("SessionId").(string) |  | ||||||
| 	if !ok { |  | ||||||
| 		return res, fmt.Errorf("missing session") |  | ||||||
| 	} |  | ||||||
| 	flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin") |  | ||||||
| 	if string(input) != "0" { |  | ||||||
| 		pinInput := string(input) |  | ||||||
| 		// Validate that the PIN is a 4-digit number.
 |  | ||||||
| 		if pin.IsValidPIN(pinInput) { |  | ||||||
| 			res.FlagSet = append(res.FlagSet, flag_valid_pin) |  | ||||||
| 		} else { |  | ||||||
| 			res.FlagReset = append(res.FlagReset, flag_valid_pin) |  | ||||||
| 		} |  | ||||||
| 	} else { |  | ||||||
| 		res.FlagSet = append(res.FlagSet, flag_valid_pin) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return res, nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // SaveTemporaryPin saves the valid PIN input to the DATA_TEMPORARY_VALUE,
 | // SaveTemporaryPin saves the valid PIN input to the DATA_TEMPORARY_VALUE,
 | ||||||
| // during the account creation process
 | // during the account creation process
 | ||||||
| // and during the change PIN process.
 | // and during the change PIN process.
 | ||||||
|  | |||||||
| @ -1843,52 +1843,6 @@ func TestGetProfile(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestVerifyNewPin(t *testing.T) { |  | ||||||
| 	sessionId := "session123" |  | ||||||
| 
 |  | ||||||
| 	fm, _ := NewFlagManager(flagsPath) |  | ||||||
| 	mockState := state.NewState(16) |  | ||||||
| 
 |  | ||||||
| 	flag_valid_pin, _ := fm.GetFlag("flag_valid_pin") |  | ||||||
| 	mockAccountService := new(mocks.MockAccountService) |  | ||||||
| 	h := &MenuHandlers{ |  | ||||||
| 		flagManager:    fm, |  | ||||||
| 		accountService: mockAccountService, |  | ||||||
| 		st:             mockState, |  | ||||||
| 	} |  | ||||||
| 	ctx := context.WithValue(context.Background(), "SessionId", sessionId) |  | ||||||
| 
 |  | ||||||
| 	tests := []struct { |  | ||||||
| 		name           string |  | ||||||
| 		input          []byte |  | ||||||
| 		expectedResult resource.Result |  | ||||||
| 	}{ |  | ||||||
| 		{ |  | ||||||
| 			name:  "Test with valid pin", |  | ||||||
| 			input: []byte("1234"), |  | ||||||
| 			expectedResult: resource.Result{ |  | ||||||
| 				FlagSet: []uint32{flag_valid_pin}, |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			name:  "Test with invalid pin", |  | ||||||
| 			input: []byte("123"), |  | ||||||
| 			expectedResult: resource.Result{ |  | ||||||
| 				FlagReset: []uint32{flag_valid_pin}, |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 	} |  | ||||||
| 	for _, tt := range tests { |  | ||||||
| 		t.Run(tt.name, func(t *testing.T) { |  | ||||||
| 			//Call the function under test
 |  | ||||||
| 			res, _ := h.VerifyNewPin(ctx, "verify_new_pin", tt.input) |  | ||||||
| 
 |  | ||||||
| 			//Assert that the result set to content is what was expected
 |  | ||||||
| 			assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input") |  | ||||||
| 		}) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestConfirmPinChange(t *testing.T) { | func TestConfirmPinChange(t *testing.T) { | ||||||
| 	sessionId := "session123" | 	sessionId := "session123" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -104,7 +104,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) | |||||||
| 	ls.DbRs.AddLocalFunc("verify_yob", appHandlers.VerifyYob) | 	ls.DbRs.AddLocalFunc("verify_yob", appHandlers.VerifyYob) | ||||||
| 	ls.DbRs.AddLocalFunc("reset_incorrect_date_format", appHandlers.ResetIncorrectYob) | 	ls.DbRs.AddLocalFunc("reset_incorrect_date_format", appHandlers.ResetIncorrectYob) | ||||||
| 	ls.DbRs.AddLocalFunc("initiate_transaction", appHandlers.InitiateTransaction) | 	ls.DbRs.AddLocalFunc("initiate_transaction", appHandlers.InitiateTransaction) | ||||||
| 	ls.DbRs.AddLocalFunc("verify_new_pin", appHandlers.VerifyNewPin) |  | ||||||
| 	ls.DbRs.AddLocalFunc("confirm_pin_change", appHandlers.ConfirmPinChange) | 	ls.DbRs.AddLocalFunc("confirm_pin_change", appHandlers.ConfirmPinChange) | ||||||
| 	ls.DbRs.AddLocalFunc("quit_with_help", appHandlers.QuitWithHelp) | 	ls.DbRs.AddLocalFunc("quit_with_help", appHandlers.QuitWithHelp) | ||||||
| 	ls.DbRs.AddLocalFunc("fetch_community_balance", appHandlers.FetchCommunityBalance) | 	ls.DbRs.AddLocalFunc("fetch_community_balance", appHandlers.FetchCommunityBalance) | ||||||
|  | |||||||
| @ -2,6 +2,5 @@ MOUT back 0 | |||||||
| HALT | HALT | ||||||
| INCMP _ 0 | INCMP _ 0 | ||||||
| RELOAD save_temporary_pin | RELOAD save_temporary_pin | ||||||
| RELOAD verify_new_pin |  | ||||||
| CATCH invalid_pin flag_invalid_pin 1 | CATCH invalid_pin flag_invalid_pin 1 | ||||||
| INCMP confirm_pin_change * | INCMP confirm_pin_change * | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| LOAD set_back 6 | LOAD set_back 6 | ||||||
| LOAD authorize_account 16 | LOAD authorize_account 16 | ||||||
| LOAD reset_allow_update 4 | LOAD reset_allow_update 4 | ||||||
| LOAD verify_new_pin 2 |  | ||||||
| LOAD save_temporary_pin 1 | LOAD save_temporary_pin 1 | ||||||
| LOAD reset_incorrect 0 | LOAD reset_incorrect 0 | ||||||
| LOAD reset_invalid_pin 6 | LOAD reset_invalid_pin 6 | ||||||
|  | |||||||
| @ -2,7 +2,5 @@ LOAD reset_invalid_pin 6 | |||||||
| HALT | HALT | ||||||
| LOAD save_temporary_pin 1 | LOAD save_temporary_pin 1 | ||||||
| RELOAD save_temporary_pin | RELOAD save_temporary_pin | ||||||
| LOAD verify_new_pin 2 |  | ||||||
| RELOAD verify_new_pin |  | ||||||
| CATCH invalid_pin flag_invalid_pin 1 | CATCH invalid_pin flag_invalid_pin 1 | ||||||
| INCMP confirm_pin_change *  | INCMP confirm_pin_change *  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user