Merge branch 'lash/async-inputs' into lash/custom-engin

This commit is contained in:
lash 2025-02-05 16:27:10 +00:00
commit 6c77d04284
15 changed files with 72 additions and 33 deletions

View File

@ -1,12 +1,15 @@
package main
import (
"bufio"
"context"
"flag"
"fmt"
"io"
"os"
"os/signal"
"path"
"strings"
"syscall"
"git.defalsify.org/vise.git/engine"
@ -186,11 +189,19 @@ func main() {
os.Exit(1)
}
fmt.Println("")
_, err = fmt.Scanln(&rqs.Input)
in := bufio.NewReader(os.Stdin)
//_, err = fmt.Scanln(&rqs.Input)
s, err := in.ReadString('\n')
if err != nil {
if err == io.EOF {
break
}
logg.ErrorCtxf(ctx, "error in input", "err", err)
fmt.Errorf("error in input: %v", err)
os.Exit(1)
}
rqs.Input = []byte{}
s = strings.TrimSpace(s)
rqs.Input = []byte(s)
}
}

View File

@ -320,12 +320,16 @@ 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")
pinInput := string(input)
// Validate that the PIN is a 4-digit number.
if pin.IsValidPIN(pinInput) {
res.FlagSet = append(res.FlagSet, flag_valid_pin)
if !h.st.Back() {
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.FlagReset = append(res.FlagReset, flag_valid_pin)
res.FlagSet = append(res.FlagSet, flag_valid_pin)
}
return res, nil
@ -414,6 +418,11 @@ func (h *MenuHandlers) CheckBlockedNumPinMisMatch(ctx context.Context, sym strin
if !ok {
return res, fmt.Errorf("missing session")
}
if h.st.Back() {
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
return res, nil
}
// Get blocked number from storage.
store := h.userdataStore
blockedNumber, err := store.ReadEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER)
@ -444,6 +453,11 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [
}
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
if h.st.Back() {
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
return res, nil
}
store := h.userdataStore
hashedTemporaryPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
if err != nil {
@ -575,6 +589,11 @@ func (h *MenuHandlers) ValidateBlockedNumber(ctx context.Context, sym string, in
if !ok {
return res, fmt.Errorf("missing session")
}
if h.st.Back() {
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) {
@ -1213,7 +1232,9 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
logg.ErrorCtxf(ctx, "failed to read AccountPin entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err)
return res, err
}
if len(input) == 4 {
str := string(input)
_, err = strconv.Atoi(str)
if len(input) == 4 && err == nil {
if pin.VerifyPIN(string(AccountPin), string(input)) {
if h.st.MatchFlag(flag_account_authorized, false) {
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
@ -1231,7 +1252,7 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
}
}
} else {
err := h.incrementIncorrectPINAttempts(ctx, sessionId)
err = h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil {
return res, err
}
@ -1248,11 +1269,13 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
// Setback sets the flag_back_set flag when the navigation is back.
func (h *MenuHandlers) SetBack(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
//TODO:
//Add check if the navigation is lateral nav instead of checking the input.
if string(input) == "0" {
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
res.FlagSet = append(res.FlagSet, flag_back_set)
} else {
res.FlagReset = append(res.FlagReset, flag_back_set)
}
return res, nil
}

View File

@ -1843,12 +1843,14 @@ 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)
@ -1886,6 +1888,7 @@ func TestVerifyNewPin(t *testing.T) {
func TestConfirmPin(t *testing.T) {
sessionId := "session123"
mockState := state.NewState(16)
ctx, store := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
@ -1896,6 +1899,7 @@ func TestConfirmPin(t *testing.T) {
userdataStore: store,
flagManager: fm,
accountService: mockAccountService,
st: mockState,
}
tests := []struct {

View File

@ -8,7 +8,7 @@ RELOAD save_others_temporary_pin
MOUT back 0
HALT
INCMP _ 0
LOAD check_pin_mismatch 0
LOAD check_pin_mismatch 6
RELOAD check_pin_mismatch
CATCH others_pin_mismatch flag_pin_mismatch 1
INCMP pin_entry *

View File

@ -1,5 +1,7 @@
CATCH invalid_pin flag_valid_pin 0
LOAD confirm_pin_change 0
MOUT back 0
HALT
INCMP _ 0
RELOAD confirm_pin_change
CATCH pin_reset_mismatch flag_pin_mismatch 1
INCMP * pin_reset_success

View File

@ -4,4 +4,7 @@ RELOAD reset_account_authorized
MOUT back 0
HALT
INCMP _ 0
LOAD validate_blocked_number 6
RELOAD validate_blocked_number
CATCH unregistered_number flag_unregistered_number 1
INCMP enter_others_new_pin *

View File

@ -1,6 +1,3 @@
LOAD validate_blocked_number 6
RELOAD validate_blocked_number
CATCH unregistered_number flag_unregistered_number 1
LOAD retrieve_blocked_number 0
RELOAD retrieve_blocked_number
MAP retrieve_blocked_number

View File

@ -1,13 +1,7 @@
LOAD authorize_account 12
RELOAD authorize_account
CATCH incorrect_pin flag_incorrect_pin 1
CATCH old_pin flag_allow_update 0
MOUT back 0
HALT
INCMP _ 0
LOAD save_temporary_pin 6
LOAD verify_new_pin 0
RELOAD save_temporary_pin
RELOAD verify_new_pin
CATCH invalid_pin flag_valid_pin 0
INCMP * confirm_pin_change

View File

@ -1,5 +1,5 @@
MOUT quit 9
MOUT back 0
HALT
INCMP pin_management 0
INCMP ^ 0
INCMP quit 9

View File

@ -1,7 +1,7 @@
LOAD reset_allow_update 0
RELOAD reset_incorrect
MOUT back 0
HALT
RELOAD reset_allow_update
INCMP _ 0
RELOAD authorize_account
CATCH incorrect_pin flag_incorrect_pin 1
INCMP new_pin *

View File

@ -1,8 +1,15 @@
LOAD confirm_pin_change 7
LOAD set_back 6
LOAD authorize_account 5
LOAD reset_allow_update 4
LOAD verify_new_pin 2
LOAD save_temporary_pin 1
LOAD reset_incorrect 0
MOUT change_pin 1
MOUT reset_pin 2
MOUT back 0
HALT
INCMP my_account 0
INCMP _ 0
INCMP old_pin 1
INCMP enter_other_number 2
INCMP . *

View File

@ -1,6 +1,6 @@
MOUT retry 1
MOUT quit 9
HALT
INCMP confirm_pin_change 1
INCMP _ 1
INCMP quit 9

View File

@ -4,5 +4,5 @@ LOAD reset_others_pin 6
MOUT back 0
MOUT quit 9
HALT
INCMP pin_management 0
INCMP ^ 0
INCMP quit 9

View File

@ -1,6 +1,3 @@
LOAD confirm_pin_change 0
RELOAD confirm_pin_change
CATCH pin_reset_mismatch flag_pin_mismatch 1
MOUT back 0
MOUT quit 9
HALT

View File

@ -1,7 +1,8 @@
LOAD reset_unregistered_number 0
RELOAD reset_unregistered_number
MOUT back 0
MOUT retry 1
MOUT quit 9
HALT
INCMP ^ 0
INCMP _ 1
INCMP quit 9
INCMP . *