@@ -1059,44 +1059,44 @@ func TestAcquireTokenSilentHomeTenantAliases1(t *testing.T) {
10591059 defer func () {
10601060 base .Now = originalTime
10611061 }()
1062- for _ , alias := range [] string { "common" , "organizations" } {
1063- mockClient := mock .NewClient ( )
1064- mockClient .AppendResponse (mock .WithBody (mock .GetTenantDiscoveryBody ( lmo , alias )))
1065- mockClient .AppendResponse (mock .WithBody (mock .GetAccessTokenBody ( accessToken , mock . GetIDToken ( homeTenant , fmt . Sprintf ( authorityFmt , lmo , homeTenant )), "rt" , clientInfo , 36000 , 100 )))
1066- mockClient .AppendResponse (mock .WithBody (mock .GetInstanceDiscoveryBody ( lmo , homeTenant )))
1062+ mockClient := mock . NewClient ()
1063+ mockClient . AppendResponse ( mock .WithBody ( mock . GetTenantDiscoveryBody ( lmo , "common" )) )
1064+ mockClient .AppendResponse (mock .WithBody (mock .GetAccessTokenBody ( accessToken , mock . GetIDToken ( homeTenant , fmt . Sprintf ( authorityFmt , lmo , homeTenant )), "rt" , clientInfo , 36000 , 1000 )))
1065+ mockClient .AppendResponse (mock .WithBody (mock .GetInstanceDiscoveryBody ( lmo , homeTenant )))
1066+ mockClient .AppendResponse (mock .WithBody (mock .GetAccessTokenBody ( "accessToken" , mock . GetIDToken ( homeTenant , fmt . Sprintf ( authorityFmt , lmo , homeTenant )), "rt" , clientInfo , 36000 , 1000 )))
10671067
1068- client , err := New ("client-id" , WithAuthority (fmt .Sprintf (authorityFmt , lmo , alias )), WithHTTPClient (mockClient ))
1069- if err != nil {
1070- t .Fatal (err )
1071- }
1072- // the auth flow isn't important, we just need to populate the cache
1073- ar , err := client .AcquireTokenByAuthCode (context .Background (), "code" , "https://localhost" , tokenScope )
1074- if err != nil {
1075- t .Fatal (err )
1076- }
1077- if ar .AccessToken != accessToken {
1078- t .Fatalf ("expected %q, got %q" , accessToken , ar .AccessToken )
1079- }
1080- account := ar .Account
1081- ar , err = client .AcquireTokenSilent (context .Background (), tokenScope , WithSilentAccount (account ))
1082- if err != nil {
1083- t .Fatal (err )
1084- }
1085- if ar .AccessToken != accessToken {
1086- t .Fatalf ("expected %q, got %q" , accessToken , ar .AccessToken )
1087- }
1088- // moving time forward to expire the current token
1089- fixedTime := time .Now ().Add (time .Duration (36001 ) * time .Second )
1090- base .Now = func () time.Time {
1091- return fixedTime
1092- }
1093- // calling the acquire token again
1094- ar , err = client .AcquireTokenSilent (context .Background (), tokenScope , WithSilentAccount (account ))
1095- if err != nil {
1096- t .Fatal (err )
1097- }
1098- if ar .AccessToken != accessToken {
1099- t .Fatalf ("expected %q, got %q" , accessToken , ar .AccessToken )
1100- }
1068+ client , err := New ("common" , WithAuthority (fmt .Sprintf (authorityFmt , lmo , "common" )), WithHTTPClient (mockClient ))
1069+ if err != nil {
1070+ t .Fatal (err )
11011071 }
1072+ // the auth flow isn't important, we just need to populate the cache
1073+ ar , err := client .AcquireTokenByAuthCode (context .Background (), "code" , "https://localhost" , tokenScope )
1074+ if err != nil {
1075+ t .Fatal (err )
1076+ }
1077+ if ar .AccessToken != accessToken {
1078+ t .Fatalf ("expected %q, got %q" , accessToken , ar .AccessToken )
1079+ }
1080+ account := ar .Account
1081+ ar , err = client .AcquireTokenSilent (context .Background (), tokenScope , WithSilentAccount (account ))
1082+ if err != nil {
1083+ t .Fatal (err )
1084+ }
1085+ if ar .AccessToken != accessToken {
1086+ t .Fatalf ("expected %q, got %q" , accessToken , ar .AccessToken )
1087+ }
1088+ // moving time forward to expire the current token
1089+ fixedTime := time .Now ().Add (time .Duration (36001 ) * time .Second )
1090+ base .Now = func () time.Time {
1091+ return fixedTime
1092+ }
1093+ // calling the acquire token again
1094+ ar , err = client .AcquireTokenSilent (context .Background (), tokenScope , WithSilentAccount (account ))
1095+ if err != nil {
1096+ t .Fatal (err )
1097+ }
1098+ if ar .AccessToken != "accessToken" {
1099+ t .Fatalf ("expected %q, got %q" , "accessToken" , ar .AccessToken )
1100+ }
1101+
11021102}
0 commit comments