diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 6012818..b4cbd7b 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -318,7 +318,7 @@ func (h *MenuHandlers) VerifyNewPin(ctx context.Context, sym string, input []byt return res, fmt.Errorf("missing session") } flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin") - if !h.st.Back() { + if string(input) != "0" { pinInput := string(input) // Validate that the PIN is a 4-digit number. if pin.IsValidPIN(pinInput) { @@ -384,6 +384,12 @@ func (h *MenuHandlers) SaveOthersTemporaryPin(ctx context.Context, sym string, i } temporaryPin := string(input) + + // Validate that the input is a 4-digit number. + if !pin.IsValidPIN(temporaryPin) { + return res, nil + } + // Retrieve the blocked number associated with this session blockedNumber, err := store.ReadEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER) if err != nil { @@ -416,7 +422,7 @@ func (h *MenuHandlers) CheckBlockedNumPinMisMatch(ctx context.Context, sym strin if !ok { return res, fmt.Errorf("missing session") } - if h.st.Back() { + if string(input) == "0" { res.FlagReset = append(res.FlagReset, flag_pin_mismatch) return res, nil } @@ -456,7 +462,7 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [ } flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch") - if h.st.Back() { + if string(input) == "0" { res.FlagReset = append(res.FlagReset, flag_pin_mismatch) return res, nil } @@ -601,16 +607,20 @@ func (h *MenuHandlers) ValidateBlockedNumber(ctx context.Context, sym string, in return res, fmt.Errorf("missing session") } - if h.st.Back() { + if string(input) == "0" { res.FlagReset = append(res.FlagReset, flag_unregistered_number) return res, nil } + blockedNumber := string(input) - _, err = store.ReadEntry(ctx, blockedNumber, storedb.DATA_PUBLIC_KEY) - if !phone.IsValidPhoneNumber(blockedNumber) { + formattedNumber, err := phone.FormatPhoneNumber(blockedNumber) + if err != nil { res.FlagSet = append(res.FlagSet, flag_unregistered_number) + logg.ErrorCtxf(ctx, "Failed to format the phone number: %s", blockedNumber, "error", err) return res, nil } + + _, err = store.ReadEntry(ctx, formattedNumber, storedb.DATA_PUBLIC_KEY) if err != nil { if db.IsNotFound(err) { logg.InfoCtxf(ctx, "Invalid or unregistered number") @@ -621,7 +631,7 @@ func (h *MenuHandlers) ValidateBlockedNumber(ctx context.Context, sym string, in return res, err } } - err = store.WriteEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER, []byte(blockedNumber)) + err = store.WriteEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER, []byte(formattedNumber)) if err != nil { return res, nil } diff --git a/menutraversal_test/menu_traversal_test.go b/menutraversal_test/menu_traversal_test.go index 4cf8715..64ea262 100644 --- a/menutraversal_test/menu_traversal_test.go +++ b/menutraversal_test/menu_traversal_test.go @@ -21,7 +21,7 @@ var ( sessionID string src = rand.NewSource(42) g = rand.New(src) - secondarySessionId = "0700000000" + secondarySessionId = "+254700000000" ) var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests") diff --git a/services/registration/confirm_others_new_pin.vis b/services/registration/confirm_others_new_pin.vis index 8409418..50dfb19 100644 --- a/services/registration/confirm_others_new_pin.vis +++ b/services/registration/confirm_others_new_pin.vis @@ -1,4 +1,4 @@ -CATCH pin_entry flag_incorrect_pin 1 +CATCH incorrect_pin flag_incorrect_pin 1 RELOAD retrieve_blocked_number MAP retrieve_blocked_number CATCH invalid_others_pin flag_valid_pin 0 diff --git a/services/registration/enter_other_number.vis b/services/registration/enter_other_number.vis index 9447678..018aad3 100644 --- a/services/registration/enter_other_number.vis +++ b/services/registration/enter_other_number.vis @@ -1,4 +1,4 @@ -CATCH no_admin_privilege flag_admin_privilege 0 +CATCH no_admin_privilege flag_admin_privilege 0 LOAD reset_account_authorized 0 RELOAD reset_account_authorized MOUT back 0 diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis index 2addb56..aa6eabf 100644 --- a/services/registration/old_pin.vis +++ b/services/registration/old_pin.vis @@ -1,7 +1,8 @@ -RELOAD reset_incorrect +RELOAD reset_allow_update MOUT back 0 HALT INCMP _ 0 RELOAD authorize_account CATCH incorrect_pin flag_incorrect_pin 1 +CATCH _ flag_allow_update 0 INCMP new_pin * diff --git a/services/registration/others_pin_mismatch.vis b/services/registration/others_pin_mismatch.vis index 37b3deb..b2421aa 100644 --- a/services/registration/others_pin_mismatch.vis +++ b/services/registration/others_pin_mismatch.vis @@ -3,3 +3,4 @@ MOUT quit 9 HALT INCMP _ 1 INCMP quit 9 +INCMP . * diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index 0344b6a..409b3c8 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -3,12 +3,12 @@ LOAD authorize_account 5 LOAD reset_allow_update 4 LOAD verify_new_pin 2 LOAD save_temporary_pin 1 -LOAD reset_incorrect 0 +LOAD reset_incorrect 0 MOUT change_pin 1 MOUT reset_pin 2 MOUT back 0 HALT INCMP _ 0 -INCMP old_pin 1 +INCMP old_pin 1 INCMP enter_other_number 2 INCMP . * diff --git a/services/registration/pin_reset_mismatch.vis b/services/registration/pin_reset_mismatch.vis index 78318f2..b2421aa 100644 --- a/services/registration/pin_reset_mismatch.vis +++ b/services/registration/pin_reset_mismatch.vis @@ -3,4 +3,4 @@ MOUT quit 9 HALT INCMP _ 1 INCMP quit 9 - +INCMP . * diff --git a/services/registration/pin_reset_success.vis b/services/registration/pin_reset_success.vis index 537a511..a3a143f 100644 --- a/services/registration/pin_reset_success.vis +++ b/services/registration/pin_reset_success.vis @@ -3,3 +3,4 @@ MOUT quit 9 HALT INCMP main 0 INCMP quit 9 +INCMP . *