Compare commits
No commits in common. "8d477356f38e26112d89e0e70e3e48caa50a991f" and "4d72ae0313ad78052979c0ddcfbe25de94185fd3" have entirely different histories.
8d477356f3
...
4d72ae0313
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -908,79 +907,37 @@ func TestResetAccountAuthorized(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIncorrectPinReset(t *testing.T) {
|
func TestIncorrectPinReset(t *testing.T) {
|
||||||
sessionId := "session123"
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
||||||
flag_account_blocked, _ := fm.parser.GetFlag("flag_account_blocked")
|
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
attempts uint8
|
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test when incorrect PIN attempts is 2",
|
name: "Test incorrect pin reset",
|
||||||
input: []byte(""),
|
input: []byte(""),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagReset: []uint32{flag_incorrect_pin},
|
FlagReset: []uint32{flag_incorrect_pin},
|
||||||
Content: "1", //Expected remaining PIN attempts
|
|
||||||
},
|
},
|
||||||
attempts: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test incorrect pin reset when incorrect PIN attempts is 1",
|
|
||||||
input: []byte(""),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_incorrect_pin},
|
|
||||||
Content: "2", //Expected remaining PIN attempts
|
|
||||||
},
|
|
||||||
attempts: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test incorrect pin reset when incorrect PIN attempts is 1",
|
|
||||||
input: []byte(""),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_incorrect_pin},
|
|
||||||
Content: "2", //Expected remaining PIN attempts
|
|
||||||
},
|
|
||||||
attempts: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test incorrect pin reset when incorrect PIN attempts is 3(account expected to be blocked)",
|
|
||||||
input: []byte(""),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_incorrect_pin},
|
|
||||||
FlagSet: []uint32{flag_account_blocked},
|
|
||||||
},
|
|
||||||
attempts: 3,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(strconv.Itoa(int(tt.attempts)))); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the Handlers instance with the mock flag manager
|
// Create the Handlers instance with the mock flag manager
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm.parser,
|
||||||
userdataStore: store,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.ResetIncorrectPin(ctx, "reset_incorrect_pin", tt.input)
|
res, err := h.ResetIncorrectPin(context.Background(), "reset_incorrect_pin", tt.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -2233,55 +2190,3 @@ func TestGetVoucherDetails(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expectedResult, res)
|
assert.Equal(t, expectedResult, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCountIncorrectPINAttempts(t *testing.T) {
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
sessionId := "session123"
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
attempts := uint8(2)
|
|
||||||
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: store,
|
|
||||||
}
|
|
||||||
err := store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(strconv.Itoa(int(attempts))))
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
err = h.countIncorrectPINAttempts(ctx, sessionId)
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
attemptsAfterCount, err := store.ReadEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS)
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
pinAttemptsValue, _ := strconv.ParseUint(string(attemptsAfterCount), 0, 64)
|
|
||||||
pinAttemptsCount := uint8(pinAttemptsValue)
|
|
||||||
expectedAttempts := attempts + 1
|
|
||||||
assert.Equal(t, pinAttemptsCount, expectedAttempts)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResetIncorrectPINAttempts(t *testing.T) {
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
sessionId := "session123"
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
|
|
||||||
err := store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(string("2")))
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: store,
|
|
||||||
}
|
|
||||||
h.resetIncorrectPINAttempts(ctx, sessionId)
|
|
||||||
incorrectAttempts, err := store.ReadEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
assert.Equal(t, "0", string(incorrectAttempts))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1235",
|
"input": "1235",
|
||||||
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -95,7 +95,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1235",
|
"input": "1235",
|
||||||
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -108,6 +108,7 @@
|
|||||||
{
|
{
|
||||||
"input": "0",
|
"input": "0",
|
||||||
"expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back"
|
"expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back"
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "0",
|
"input": "0",
|
||||||
@ -140,7 +141,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1235",
|
"input": "1235",
|
||||||
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -153,6 +154,7 @@
|
|||||||
{
|
{
|
||||||
"input": "0",
|
"input": "0",
|
||||||
"expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back"
|
"expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back"
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "0",
|
"input": "0",
|
||||||
@ -256,6 +258,7 @@
|
|||||||
"input": "0",
|
"input": "0",
|
||||||
"expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit"
|
"expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit"
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -441,3 +444,9 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user