Compare commits
No commits in common. "599f7a2857143279e48ed297a23c09a4daacc33f" and "78c033e61c6e7ffd97e37537bb8e2f93f2956f13" have entirely different histories.
599f7a2857
...
78c033e61c
@ -71,10 +71,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
|
|||||||
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
||||||
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||||
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
||||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
|
||||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
|
||||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
|
||||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
return ussdHandlers, nil
|
||||||
}
|
}
|
||||||
|
@ -216,74 +216,6 @@ func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resou
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) 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")
|
|
||||||
pinInput := string(input)
|
|
||||||
// Validate that the PIN is a 4-digit number
|
|
||||||
if isValidPIN(pinInput) {
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_valid_pin)
|
|
||||||
} else {
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_valid_pin)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
|
||||||
if !ok {
|
|
||||||
return res, fmt.Errorf("missing session")
|
|
||||||
}
|
|
||||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
|
||||||
|
|
||||||
accountPIN := string(input)
|
|
||||||
|
|
||||||
// Validate that the PIN is a 4-digit number
|
|
||||||
if !isValidPIN(accountPIN) {
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
store := h.userdataStore
|
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN))
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
|
||||||
if !ok {
|
|
||||||
return res, fmt.Errorf("missing session")
|
|
||||||
}
|
|
||||||
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
|
|
||||||
|
|
||||||
store := h.userdataStore
|
|
||||||
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if bytes.Equal(temporaryPin, input) {
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
|
|
||||||
} else {
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_pin_mismatch)
|
|
||||||
}
|
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(temporaryPin))
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetResetSingleEdit sets and resets flags to allow gradual editing of profile information.
|
// SetResetSingleEdit sets and resets flags to allow gradual editing of profile information.
|
||||||
func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
@ -390,6 +322,9 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return res, fmt.Errorf("a family name cannot be less than one character")
|
return res, fmt.Errorf("a family name cannot be less than one character")
|
||||||
}
|
}
|
||||||
@ -546,23 +481,27 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
if len(input) == 4 {
|
|
||||||
if bytes.Equal(input, AccountPin) {
|
if err == nil {
|
||||||
if h.st.MatchFlag(flag_account_authorized, false) {
|
if len(input) == 4 {
|
||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
if bytes.Equal(input, AccountPin) {
|
||||||
res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized)
|
if h.st.MatchFlag(flag_account_authorized, false) {
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_allow_update, flag_account_authorized)
|
||||||
|
} else {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_allow_update)
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res.FlagSet = append(res.FlagSet, flag_allow_update)
|
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
|
||||||
return res, nil
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,22 +569,6 @@ func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuitWithHelp displays helpline information then exits the menu
|
|
||||||
func (h *Handlers) QuitWithHelp(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
|
|
||||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
|
||||||
|
|
||||||
code := codeFromCtx(ctx)
|
|
||||||
l := gotext.NewLocale(translationDir, code)
|
|
||||||
l.AddDomain("default")
|
|
||||||
|
|
||||||
res.Content = l.Get("For more help,please call: 0757628885")
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// VerifyYob verifies the length of the given input
|
// VerifyYob verifies the length of the given input
|
||||||
func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
@ -1696,148 +1696,3 @@ func TestGetProfile(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVerifyNewPin(t *testing.T) {
|
|
||||||
sessionId := "session123"
|
|
||||||
|
|
||||||
fm, _ := NewFlagManager(flagsPath)
|
|
||||||
|
|
||||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockDataStore,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
accountService: mockCreateAccountService,
|
|
||||||
}
|
|
||||||
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},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test with invalid pin",
|
|
||||||
input: []byte("12345"),
|
|
||||||
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 expectations were met
|
|
||||||
mockDataStore.AssertExpectations(t)
|
|
||||||
|
|
||||||
//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 TestSaveTemporaryPIn(t *testing.T) {
|
|
||||||
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new instance of UserDataStore
|
|
||||||
mockStore := new(mocks.MockUserDataStore)
|
|
||||||
|
|
||||||
// Define test data
|
|
||||||
sessionId := "session123"
|
|
||||||
PIN := "1234"
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(PIN)).Return(nil)
|
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockStore,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the method
|
|
||||||
res, err := h.SaveTemporaryPin(ctx, "save_temporary_pin", []byte(PIN))
|
|
||||||
|
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, resource.Result{}, res)
|
|
||||||
|
|
||||||
// Assert all expectations were met
|
|
||||||
mockStore.AssertExpectations(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfirmPin(t *testing.T) {
|
|
||||||
sessionId := "session123"
|
|
||||||
|
|
||||||
fm, _ := NewFlagManager(flagsPath)
|
|
||||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockDataStore,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
accountService: mockCreateAccountService,
|
|
||||||
}
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input []byte
|
|
||||||
temporarypin []byte
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Test with correct pin confirmation",
|
|
||||||
input: []byte("1234"),
|
|
||||||
temporarypin: []byte("1234"),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_pin_mismatch},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
// Set up the expected behavior of the mock
|
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(tt.temporarypin)).Return(nil)
|
|
||||||
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN).Return(tt.temporarypin, nil)
|
|
||||||
|
|
||||||
//Call the function under test
|
|
||||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
|
||||||
|
|
||||||
// Assert that expectations were met
|
|
||||||
mockDataStore.AssertExpectations(t)
|
|
||||||
|
|
||||||
//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")
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -22,7 +22,6 @@ const (
|
|||||||
DATA_OFFERINGS
|
DATA_OFFERINGS
|
||||||
DATA_RECIPIENT
|
DATA_RECIPIENT
|
||||||
DATA_AMOUNT
|
DATA_AMOUNT
|
||||||
DATA_TEMPORARY_PIN
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func typToBytes(typ DataTyp) []byte {
|
func typToBytes(typ DataTyp) []byte {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
# Variables to match files in the current directory
|
# Variables to match files in the current directory
|
||||||
INPUTS = $(wildcard ./*.vis)
|
INPUTS = $(wildcard ./*.vis)
|
||||||
TXTS = $(wildcard ./*.txt.orig)
|
TXTS = $(wildcard ./*.txt.orig)
|
||||||
VISE_PATH := ../../go-vise
|
|
||||||
|
|
||||||
# Rule to build .bin files from .vis files
|
# Rule to build .bin files from .vis files
|
||||||
%.vis:
|
%.vis:
|
||||||
go run $(VISE_PATH)/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
go run ../../go-vise/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||||
@echo "Built $(basename $@).bin from $(basename $@).vis"
|
@echo "Built $(basename $@).bin from $(basename $@).vis"
|
||||||
|
|
||||||
# Rule to copy .orig files to .txt
|
# Rule to copy .orig files to .txt
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Confirm your new PIN:
|
|
@ -1,7 +0,0 @@
|
|||||||
CATCH invalid_pin flag_valid_pin 0
|
|
||||||
MOUT back 0
|
|
||||||
HALT
|
|
||||||
INCMP _ 0
|
|
||||||
INCMP * pin_reset_success
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Thibitisha PIN yako mpya:
|
|
@ -1,2 +0,0 @@
|
|||||||
LOAD quit_with_help 0
|
|
||||||
HALT
|
|
@ -1 +0,0 @@
|
|||||||
The PIN you entered is invalid.The PIN must be different from your current PIN.For help call +254757628885
|
|
@ -1,3 +0,0 @@
|
|||||||
MOUT back 0
|
|
||||||
HALT
|
|
||||||
INCMP _ 0
|
|
@ -1 +0,0 @@
|
|||||||
PIN mpya na udhibitisho wa pin mpya hazilingani.Tafadhali jaribu tena.Kwa usaidizi piga simu +254757628885.
|
|
@ -6,7 +6,3 @@ msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
|
|||||||
|
|
||||||
msgid "Thank you for using Sarafu. Goodbye!"
|
msgid "Thank you for using Sarafu. Goodbye!"
|
||||||
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
||||||
|
|
||||||
|
|
||||||
msgid "For more help,please call: 0757628885"
|
|
||||||
msgstr "Kwa usaidizi zaidi,piga: 0757628885"
|
|
||||||
|
@ -10,6 +10,6 @@ HALT
|
|||||||
INCMP send 1
|
INCMP send 1
|
||||||
INCMP quit 2
|
INCMP quit 2
|
||||||
INCMP my_account 3
|
INCMP my_account 3
|
||||||
INCMP help 4
|
INCMP quit 4
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Enter a new four number pin
|
|
@ -1,13 +0,0 @@
|
|||||||
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
|
|
||||||
INCMP * confirm_pin_change
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
Weka PIN mpya ya nne nambari:
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Enter your old PIN
|
|
@ -1,7 +0,0 @@
|
|||||||
LOAD reset_allow_update 0
|
|
||||||
MOUT back 0
|
|
||||||
HALT
|
|
||||||
RELOAD reset_allow_update
|
|
||||||
INCMP _ 0
|
|
||||||
INCMP new_pin *
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Weka PIN yako ya zamani:
|
|
@ -4,5 +4,3 @@ MOUT guard_pin 3
|
|||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP old_pin 1
|
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
The PIN is not a match. Try again
|
|
@ -1,6 +0,0 @@
|
|||||||
MOUT retry 1
|
|
||||||
MOUT quit 9
|
|
||||||
HALT
|
|
||||||
INCMP confirm_pin_change 1
|
|
||||||
INCMP quit 9
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Your PIN change request has been successful
|
|
@ -1,10 +0,0 @@
|
|||||||
LOAD confirm_pin_change 0
|
|
||||||
RELOAD confirm_pin_change
|
|
||||||
CATCH pin_reset_mismatch flag_pin_mismatch 1
|
|
||||||
MOUT back 0
|
|
||||||
MOUT quit 9
|
|
||||||
HALT
|
|
||||||
INCMP main 0
|
|
||||||
INCMP quit 9
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Ombi lako la kubadili PIN limefanikiwa
|
|
Loading…
Reference in New Issue
Block a user