set and reset admin flag using persister's state
This commit is contained in:
parent
fe74dbb848
commit
9a63234470
@ -16,11 +16,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla().WithDomain("menutraversaltest")
|
logg = logging.NewVanilla().WithDomain("menutraversaltest")
|
||||||
testData = driver.ReadData()
|
testData = driver.ReadData()
|
||||||
sessionID string
|
sessionID string
|
||||||
src = rand.NewSource(42)
|
src = rand.NewSource(42)
|
||||||
g = rand.New(src)
|
g = rand.New(src)
|
||||||
|
secondarySessionId = "0700000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
|
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
|
||||||
@ -97,7 +98,43 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccountCreationSuccessful(t *testing.T) {
|
func TestAccountCreationSuccessful(t *testing.T) {
|
||||||
en, fn, eventChannel := testutil.TestEngine(sessionID)
|
en, fn, eventChannel, _, _ := testutil.TestEngine(sessionID)
|
||||||
|
defer fn()
|
||||||
|
ctx := context.Background()
|
||||||
|
sessions := testData
|
||||||
|
for _, session := range sessions {
|
||||||
|
groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful")
|
||||||
|
for _, group := range groups {
|
||||||
|
for i, step := range group.Steps {
|
||||||
|
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||||
|
cont, err := en.Exec(ctx, []byte(step.Input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
|
||||||
|
}
|
||||||
|
if !cont {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
w := bytes.NewBuffer(nil)
|
||||||
|
_, err = en.Flush(ctx, w)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err)
|
||||||
|
}
|
||||||
|
b := w.Bytes()
|
||||||
|
match, err := step.MatchesExpectedContent(b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error compiling regex for step '%s': %v", step.Input, err)
|
||||||
|
}
|
||||||
|
if !match {
|
||||||
|
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<-eventChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSecondaryAccount(t *testing.T) {
|
||||||
|
en, fn, eventChannel, _, _ := testutil.TestEngine(secondarySessionId)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -140,7 +177,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
edgeCaseSessionID := v.String()
|
edgeCaseSessionID := v.String()
|
||||||
en, fn, _ := testutil.TestEngine(edgeCaseSessionID)
|
en, fn, _, _, _ := testutil.TestEngine(edgeCaseSessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -176,7 +213,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainMenuHelp(t *testing.T) {
|
func TestMainMenuHelp(t *testing.T) {
|
||||||
en, fn, _ := testutil.TestEngine(sessionID)
|
en, fn, _, _, _ := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -218,7 +255,7 @@ func TestMainMenuHelp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainMenuQuit(t *testing.T) {
|
func TestMainMenuQuit(t *testing.T) {
|
||||||
en, fn, _ := testutil.TestEngine(sessionID)
|
en, fn, _, _, _ := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -259,7 +296,7 @@ func TestMainMenuQuit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMyAccount_MyAddress(t *testing.T) {
|
func TestMyAccount_MyAddress(t *testing.T) {
|
||||||
en, fn, _ := testutil.TestEngine(sessionID)
|
en, fn, _, _, _ := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -303,7 +340,7 @@ func TestMyAccount_MyAddress(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainMenuSend(t *testing.T) {
|
func TestMainMenuSend(t *testing.T) {
|
||||||
en, fn, _ := testutil.TestEngine(sessionID)
|
en, fn, _, _, _ := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -354,9 +391,12 @@ func TestGroups(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load test groups: %v", err)
|
log.Fatalf("Failed to load test groups: %v", err)
|
||||||
}
|
}
|
||||||
en, fn, _ := testutil.TestEngine(sessionID)
|
en, fn, _, pe, flagParser := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
flag_admin_privilege, _ := flagParser.GetFlag("flag_admin_privilege")
|
||||||
|
|
||||||
// Create test cases from loaded groups
|
// Create test cases from loaded groups
|
||||||
tests := driver.CreateTestCases(groups)
|
tests := driver.CreateTestCases(groups)
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -377,9 +417,19 @@ func TestGroups(t *testing.T) {
|
|||||||
balance := extractBalance(b)
|
balance := extractBalance(b)
|
||||||
attempts := extractRemainingAttempts(b)
|
attempts := extractRemainingAttempts(b)
|
||||||
|
|
||||||
|
st := pe.GetState()
|
||||||
|
|
||||||
|
if st != nil {
|
||||||
|
st.SetFlag(flag_admin_privilege)
|
||||||
|
if tt.Name == "menu_my_account_reset_others_pin_with_no_privileges" {
|
||||||
|
st.ResetFlag(flag_admin_privilege)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
expectedContent := []byte(tt.ExpectedContent)
|
expectedContent := []byte(tt.ExpectedContent)
|
||||||
expectedContent = bytes.Replace(expectedContent, []byte("{balance}"), []byte(balance), -1)
|
expectedContent = bytes.Replace(expectedContent, []byte("{balance}"), []byte(balance), -1)
|
||||||
expectedContent = bytes.Replace(expectedContent, []byte("{attempts}"), []byte(attempts), -1)
|
expectedContent = bytes.Replace(expectedContent, []byte("{attempts}"), []byte(attempts), -1)
|
||||||
|
expectedContent = bytes.Replace(expectedContent, []byte("{secondary_session_id}"), []byte(secondarySessionId), -1)
|
||||||
|
|
||||||
tt.ExpectedContent = string(expectedContent)
|
tt.ExpectedContent = string(expectedContent)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user