@@ -426,9 +426,7 @@ func TestDefaultIdentityProviderResponseParser(t *testing.T) {
426
426
parser := & defaultIdentityProviderResponseParser {}
427
427
t .Run ("Default IdentityProviderResponseParser with type AuthResult" , func (t * testing.T ) {
428
428
t .Parallel ()
429
- authResult := & public.AuthResult {
430
- ExpiresOn : time .Now ().Add (time .Hour ).UTC (),
431
- }
429
+ authResult := testAuthResult (time .Now ().Add (time .Hour ).UTC ())
432
430
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
433
431
authResult )
434
432
assert .NoError (t , err )
@@ -530,9 +528,7 @@ func TestDefaultIdentityProviderResponseParser(t *testing.T) {
530
528
})
531
529
t .Run ("Default IdentityProviderResponseParser with expired token" , func (t * testing.T ) {
532
530
t .Parallel ()
533
- authResult := & public.AuthResult {
534
- ExpiresOn : time .Now ().Add (- time .Hour ).UTC (),
535
- }
531
+ authResult := testAuthResult (time .Now ().Add (- time .Hour ))
536
532
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
537
533
authResult )
538
534
assert .NoError (t , err )
@@ -542,9 +538,7 @@ func TestDefaultIdentityProviderResponseParser(t *testing.T) {
542
538
})
543
539
t .Run ("Default IdentityProviderResponseParser with token that expired" , func (t * testing.T ) {
544
540
t .Parallel ()
545
- authResult := & public.AuthResult {
546
- ExpiresOn : time .Now ().Add (- time .Hour ).UTC (),
547
- }
541
+ authResult := testAuthResult (time .Now ().Add (- time .Hour ))
548
542
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
549
543
authResult )
550
544
assert .NoError (t , err )
@@ -626,9 +620,7 @@ func TestEntraidTokenManager_GetToken(t *testing.T) {
626
620
)
627
621
assert .NoError (t , err )
628
622
629
- authResult := & public.AuthResult {
630
- ExpiresOn : time .Now ().Add (- time .Hour ).UTC (),
631
- }
623
+ authResult := testAuthResult (time .Now ().Add (- time .Hour ))
632
624
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
633
625
authResult )
634
626
assert .NoError (t , err )
@@ -730,9 +722,7 @@ func TestEntraidTokenManager_durationToRenewal(t *testing.T) {
730
722
731
723
// get token that expires before the lower bound
732
724
assert .NotPanics (t , func () {
733
- expiresSoon := & public.AuthResult {
734
- ExpiresOn : time .Now ().Add (tm .lowerBoundDuration - time .Minute ).UTC (),
735
- }
725
+ expiresSoon := testAuthResult (time .Now ().Add (tm .lowerBoundDuration - time .Minute ).UTC ())
736
726
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
737
727
expiresSoon )
738
728
assert .NoError (t , err )
@@ -750,9 +740,7 @@ func TestEntraidTokenManager_durationToRenewal(t *testing.T) {
750
740
// get token that expires after the lower bound and expirationRefreshRatio to 1
751
741
assert .NotPanics (t , func () {
752
742
tm .expirationRefreshRatio = 1
753
- expiresAfterlb := & public.AuthResult {
754
- ExpiresOn : time .Now ().Add (tm .lowerBoundDuration + time .Hour ).UTC (),
755
- }
743
+ expiresAfterlb := testAuthResult (time .Now ().Add (tm .lowerBoundDuration + time .Hour ).UTC ())
756
744
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
757
745
expiresAfterlb )
758
746
assert .NoError (t , err )
@@ -790,9 +778,7 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
790
778
791
779
expiresIn := time .Second
792
780
expiresOn := time .Now ().Add (expiresIn ).UTC ()
793
- authResult := & public.AuthResult {
794
- ExpiresOn : expiresOn ,
795
- }
781
+ authResult := testAuthResult (expiresOn )
796
782
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
797
783
authResult )
798
784
assert .NoError (t , err )
@@ -851,9 +837,8 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
851
837
852
838
expiresIn := time .Second
853
839
expiresOn := time .Now ().Add (expiresIn ).UTC ()
854
- res := & public.AuthResult {
855
- ExpiresOn : expiresOn ,
856
- }
840
+
841
+ res := testAuthResult (expiresOn )
857
842
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
858
843
res )
859
844
assert .NoError (t , err )
@@ -862,9 +847,7 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
862
847
var start , stop time.Time
863
848
idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
864
849
expiresOn := time .Now ().Add (expiresIn ).UTC ()
865
- res := & public.AuthResult {
866
- ExpiresOn : expiresOn ,
867
- }
850
+ res := testAuthResult (expiresOn )
868
851
response := idpResponse .(* authResult )
869
852
response .AuthResultVal = res
870
853
if atomic .LoadInt32 (& twice ) == 1 {
@@ -920,17 +903,13 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
920
903
921
904
expiresIn := time .Second
922
905
expiresOn := time .Now ().Add (expiresIn ).UTC ()
923
- res := & public.AuthResult {
924
- ExpiresOn : expiresOn ,
925
- }
906
+ res := testAuthResult (expiresOn )
926
907
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
927
908
res )
928
909
assert .NoError (t , err )
929
910
idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
930
911
expiresOn := time .Now ().Add (expiresIn ).UTC ()
931
- res := & public.AuthResult {
932
- ExpiresOn : expiresOn ,
933
- }
912
+ res := testAuthResult (expiresOn )
934
913
response := idpResponse .(* authResult )
935
914
response .AuthResultVal = res
936
915
}).Return (idpResponse , nil )
@@ -976,17 +955,14 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
976
955
977
956
expiresIn := time .Second
978
957
expiresOn := time .Now ().Add (expiresIn ).UTC ()
979
- res := & public.AuthResult {
980
- ExpiresOn : expiresOn ,
981
- }
958
+
959
+ res := testAuthResult (expiresOn )
982
960
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
983
961
res )
984
962
assert .NoError (t , err )
985
963
idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
986
964
expiresOn := time .Now ().Add (expiresIn ).UTC ()
987
- res := & public.AuthResult {
988
- ExpiresOn : expiresOn ,
989
- }
965
+ res := testAuthResult (expiresOn )
990
966
response := idpResponse .(* authResult )
991
967
response .AuthResultVal = res
992
968
}).Return (idpResponse , nil )
@@ -1025,18 +1001,14 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
1025
1001
1026
1002
expiresIn := time .Second
1027
1003
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1028
- res := & public.AuthResult {
1029
- ExpiresOn : expiresOn ,
1030
- }
1004
+ res := testAuthResult (expiresOn )
1031
1005
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
1032
1006
res )
1033
1007
assert .NoError (t , err )
1034
1008
1035
1009
noErrCall := idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
1036
1010
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1037
- res := & public.AuthResult {
1038
- ExpiresOn : expiresOn ,
1039
- }
1011
+ res := testAuthResult (expiresOn )
1040
1012
response := idpResponse .(* authResult )
1041
1013
response .AuthResultVal = res
1042
1014
}).Return (idpResponse , nil )
@@ -1083,18 +1055,14 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
1083
1055
1084
1056
expiresIn := time .Second
1085
1057
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1086
- res := & public.AuthResult {
1087
- ExpiresOn : expiresOn ,
1088
- }
1058
+ res := testAuthResult (expiresOn )
1089
1059
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
1090
1060
res )
1091
1061
assert .NoError (t , err )
1092
1062
1093
1063
noErrCall := idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
1094
1064
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1095
- res := & public.AuthResult {
1096
- ExpiresOn : expiresOn ,
1097
- }
1065
+ res := testAuthResult (expiresOn )
1098
1066
response := idpResponse .(* authResult )
1099
1067
response .AuthResultVal = res
1100
1068
}).Return (idpResponse , nil )
@@ -1153,18 +1121,16 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
1153
1121
1154
1122
expiresIn := time .Second
1155
1123
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1156
- res := & public.AuthResult {
1157
- ExpiresOn : expiresOn ,
1158
- }
1124
+ res := testAuthResult (expiresOn )
1125
+ res .IDToken .Oid = "test"
1159
1126
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
1160
1127
res )
1161
1128
assert .NoError (t , err )
1162
1129
1163
1130
noErrCall := idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
1164
1131
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1165
- res := & public.AuthResult {
1166
- ExpiresOn : expiresOn ,
1167
- }
1132
+ res := testAuthResult (expiresOn )
1133
+ res .IDToken .Oid = "test"
1168
1134
response := idpResponse .(* authResult )
1169
1135
response .AuthResultVal = res
1170
1136
}).Return (idpResponse , nil )
@@ -1239,18 +1205,14 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
1239
1205
1240
1206
expiresIn := time .Second
1241
1207
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1242
- res := & public.AuthResult {
1243
- ExpiresOn : expiresOn ,
1244
- }
1208
+ res := testAuthResult (expiresOn )
1245
1209
idpResponse , err := shared .NewIDPResponse (shared .ResponseTypeAuthResult ,
1246
1210
res )
1247
1211
assert .NoError (t , err )
1248
1212
1249
1213
noErrCall := idp .On ("RequestToken" ).Run (func (args mock.Arguments ) {
1250
1214
expiresOn := time .Now ().Add (expiresIn ).UTC ()
1251
- res := & public.AuthResult {
1252
- ExpiresOn : expiresOn ,
1253
- }
1215
+ res := testAuthResult (expiresOn )
1254
1216
response := idpResponse .(* authResult )
1255
1217
response .AuthResultVal = res
1256
1218
}).Return (idpResponse , nil )
@@ -1295,3 +1257,11 @@ func TestEntraidTokenManager_Streaming(t *testing.T) {
1295
1257
mock .AssertExpectationsForObjects (t , idp , listener )
1296
1258
})
1297
1259
}
1260
+
1261
+ func testAuthResult (expiersOn time.Time ) * public.AuthResult {
1262
+ r := & public.AuthResult {
1263
+ ExpiresOn : expiersOn ,
1264
+ }
1265
+ r .IDToken .Oid = "test"
1266
+ return r
1267
+ }
0 commit comments