@@ -12,6 +12,7 @@ type AuthTestSpec struct {
1212 TimeDriftSeconds int64
1313 CustomAuthSecretBytes []byte
1414 AuthOk bool
15+ RetryAttempts int64
1516}
1617
1718var authTestSpecs = []AuthTestSpec {
@@ -38,24 +39,28 @@ var authTestSpecs = []AuthTestSpec{
3839 TimeDriftSeconds : - 1 - maxTimeDriftSeconds ,
3940 CustomAuthSecretBytes : nil ,
4041 AuthOk : false ,
42+ RetryAttempts : 5 ,
4143 },
4244 {
4345 Name : "JWT Authentication: Negative time drift, within limit, correct secret" ,
4446 TimeDriftSeconds : 1 - maxTimeDriftSeconds ,
4547 CustomAuthSecretBytes : nil ,
4648 AuthOk : true ,
49+ RetryAttempts : 5 ,
4750 },
4851 {
4952 Name : "JWT Authentication: Positive time drift, exceeding limit, correct secret" ,
5053 TimeDriftSeconds : maxTimeDriftSeconds + 1 ,
5154 CustomAuthSecretBytes : nil ,
5255 AuthOk : false ,
56+ RetryAttempts : 5 ,
5357 },
5458 {
5559 Name : "JWT Authentication: Positive time drift, within limit, correct secret" ,
5660 TimeDriftSeconds : maxTimeDriftSeconds - 1 ,
5761 CustomAuthSecretBytes : nil ,
5862 AuthOk : true ,
63+ RetryAttempts : 5 ,
5964 },
6065}
6166
@@ -78,26 +83,38 @@ func GenerateAuthTestSpec(authTestSpec AuthTestSpec) TestSpec {
7883 TerminalBlockNumber : 0 ,
7984 }
8085 testSecret = authTestSpec .CustomAuthSecretBytes
81- testTime = time .Now ()
86+ // Time drift test cases are reattempted in order to mitigate false negatives
87+ retryAttemptsLeft = authTestSpec .RetryAttempts
8288 )
83- if testSecret == nil {
84- testSecret = defaultJwtTokenSecretBytes
85- }
86- if authTestSpec .TimeDriftSeconds != 0 {
87- testTime = testTime .Add (time .Second * time .Duration (authTestSpec .TimeDriftSeconds ))
88- }
89- if err := t .Engine .PrepareAuthCallToken (testSecret , testTime ); err != nil {
90- t .Fatalf ("FAIL (%s): Unable to prepare the auth token: %v" , t .TestName , err )
91- }
92- err := t .Engine .c .CallContext (t .Engine .Ctx (), & tConf , "engine_exchangeTransitionConfigurationV1" , tConf )
93- if authTestSpec .AuthOk {
94- if err != nil {
95- t .Fatalf ("FAIL (%s): Authentication was supposed to pass authentication but failed: %v" , t .TestName , err )
89+
90+ for {
91+ var testTime = time .Now ()
92+ if testSecret == nil {
93+ testSecret = defaultJwtTokenSecretBytes
94+ }
95+ if authTestSpec .TimeDriftSeconds != 0 {
96+ testTime = testTime .Add (time .Second * time .Duration (authTestSpec .TimeDriftSeconds ))
97+ }
98+ if err := t .Engine .PrepareAuthCallToken (testSecret , testTime ); err != nil {
99+ t .Fatalf ("FAIL (%s): Unable to prepare the auth token: %v" , t .TestName , err )
100+ }
101+ err := t .Engine .c .CallContext (t .Engine .Ctx (), & tConf , "engine_exchangeTransitionConfigurationV1" , tConf )
102+ if (authTestSpec .AuthOk && err == nil ) || (! authTestSpec .AuthOk && err != nil ) {
103+ // Test passed
104+ return
96105 }
97- } else {
98- if err == nil {
99- t .Fatalf ("FAIL (%s): Authentication was supposed to fail authentication but passed" , t .TestName )
106+ if retryAttemptsLeft == 0 {
107+ if err != nil {
108+ // Test failed because unexpected error
109+ t .Fatalf ("FAIL (%s): Authentication was supposed to pass authentication but failed: %v" , t .TestName , err )
110+ } else {
111+ // Test failed because unexpected success
112+ t .Fatalf ("FAIL (%s): Authentication was supposed to fail authentication but passed" , t .TestName )
113+ }
100114 }
115+ retryAttemptsLeft --
116+ // Wait at least a second before trying again
117+ time .Sleep (time .Second )
101118 }
102119 }
103120 return TestSpec {
0 commit comments