Compare commits
2 Commits
4d72ae0313
...
8d477356f3
Author | SHA1 | Date | |
---|---|---|---|
8d477356f3 | |||
7f3294a8a2 |
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -907,37 +908,79 @@ 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 incorrect pin reset",
|
name: "Test when incorrect PIN attempts is 2",
|
||||||
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(context.Background(), "reset_incorrect_pin", tt.input)
|
res, err := h.ResetIncorrectPin(ctx, "reset_incorrect_pin", tt.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -2190,3 +2233,55 @@ 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\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -95,7 +95,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1235",
|
"input": "1235",
|
||||||
"expectedContent": "Incorrect PIN\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -107,8 +107,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",
|
||||||
@ -141,7 +140,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1235",
|
"input": "1235",
|
||||||
"expectedContent": "Incorrect PIN\n1:Retry\n9:Quit"
|
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
@ -153,8 +152,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",
|
||||||
@ -195,7 +193,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1",
|
"input": "1",
|
||||||
"expectedContent": "Enter your year of birth\n0:Back"
|
"expectedContent": "Enter your year of birth\n0:Back"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"input": "1940",
|
"input": "1940",
|
||||||
@ -258,7 +256,6 @@
|
|||||||
"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"
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -444,9 +441,3 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user