Merge pull request 'Set crucial missing flags if the data exists' (#100) from sync-flags into master
Reviewed-on: #100
This commit is contained in:
commit
3d57150465
@ -83,6 +83,7 @@ func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, inpu
|
|||||||
// CheckBlockedStatus:
|
// CheckBlockedStatus:
|
||||||
// 1. Checks whether the DATA_SELF_PIN_RESET is 1 and sets the flag_account_pin_reset
|
// 1. Checks whether the DATA_SELF_PIN_RESET is 1 and sets the flag_account_pin_reset
|
||||||
// 2. resets the account blocked flag if the PIN attempts have been reset by an admin.
|
// 2. resets the account blocked flag if the PIN attempts have been reset by an admin.
|
||||||
|
// 3. Sets key flags (language and PIN) if the data exists
|
||||||
func (h *MenuHandlers) CheckBlockedStatus(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) CheckBlockedStatus(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@ -90,11 +91,30 @@ func (h *MenuHandlers) CheckBlockedStatus(ctx context.Context, sym string, input
|
|||||||
flag_account_blocked, _ := h.flagManager.GetFlag("flag_account_blocked")
|
flag_account_blocked, _ := h.flagManager.GetFlag("flag_account_blocked")
|
||||||
flag_account_pin_reset, _ := h.flagManager.GetFlag("flag_account_pin_reset")
|
flag_account_pin_reset, _ := h.flagManager.GetFlag("flag_account_pin_reset")
|
||||||
|
|
||||||
|
flag_pin_set, _ := h.flagManager.GetFlag("flag_pin_set")
|
||||||
|
flag_language_set, _ := h.flagManager.GetFlag("flag_language_set")
|
||||||
|
pinFlagSet := h.st.MatchFlag(flag_pin_set, true)
|
||||||
|
languageFlagSet := h.st.MatchFlag(flag_language_set, true)
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only check the data if the flag isn't set
|
||||||
|
if !pinFlagSet {
|
||||||
|
accountPin, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN)
|
||||||
|
if len(accountPin) > 0 {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_pin_set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !languageFlagSet {
|
||||||
|
languageCode, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_SELECTED_LANGUAGE_CODE)
|
||||||
|
if len(languageCode) > 0 {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_language_set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_pin_reset)
|
res.FlagReset = append(res.FlagReset, flag_account_pin_reset)
|
||||||
|
|
||||||
selfPinReset, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SELF_PIN_RESET)
|
selfPinReset, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SELF_PIN_RESET)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
|
"git.defalsify.org/vise.git/state"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
@ -93,16 +94,24 @@ func TestCheckBlockedStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
||||||
flag_account_pin_reset, _ := fm.GetFlag("flag_account_pin_reset")
|
flag_account_pin_reset, _ := fm.GetFlag("flag_account_pin_reset")
|
||||||
|
flag_pin_set, _ := fm.GetFlag("flag_pin_set")
|
||||||
|
flag_language_set, _ := fm.GetFlag("flag_language_set")
|
||||||
|
|
||||||
|
// Set the flag in the State
|
||||||
|
mockState := state.NewState(128)
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
currentWrongPinAttempts string
|
currentWrongPinAttempts string
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
|
languageSet bool
|
||||||
|
PinSet bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Currently blocked account",
|
name: "Currently blocked account",
|
||||||
@ -118,6 +127,16 @@ func TestCheckBlockedStatus(t *testing.T) {
|
|||||||
FlagReset: []uint32{flag_account_pin_reset, flag_account_blocked},
|
FlagReset: []uint32{flag_account_pin_reset, flag_account_blocked},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Valid account with reset language and PIN flags",
|
||||||
|
currentWrongPinAttempts: "0",
|
||||||
|
languageSet: true,
|
||||||
|
PinSet: true,
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagReset: []uint32{flag_account_pin_reset, flag_account_blocked},
|
||||||
|
FlagSet: []uint32{flag_pin_set, flag_language_set},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -126,6 +145,18 @@ func TestCheckBlockedStatus(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tt.languageSet {
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_SELECTED_LANGUAGE_CODE, []byte("eng")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.PinSet {
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN, []byte("hasedPinValue")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res, err := h.CheckBlockedStatus(ctx, "", []byte(""))
|
res, err := h.CheckBlockedStatus(ctx, "", []byte(""))
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user