@@ -164,6 +164,79 @@ func TestAcquireTokenByCredential(t *testing.T) {
164164 }
165165}
166166
167+ func TestRegionAutoEnable_EmptyRegion_EnvRegion (t * testing.T ) {
168+ cred , err := NewCredFromSecret (fakeSecret )
169+ if err != nil {
170+ t .Fatal (err )
171+ }
172+
173+ envRegion := "envRegion"
174+ err = os .Setenv ("MSAL_FORCE_REGION" , envRegion )
175+ if err != nil {
176+ t .Fatal (err )
177+ }
178+ defer os .Unsetenv ("MSAL_FORCE_REGION" )
179+
180+ lmo := "login.microsoftonline.com"
181+ tenant := "tenant"
182+ mockClient := mock.Client {}
183+ client , err := New (fmt .Sprintf (authorityFmt , lmo , tenant ), fakeClientID , cred , WithHTTPClient (& mockClient ))
184+ if err != nil {
185+ t .Fatal (err )
186+ }
187+
188+ if client .base .AuthParams .AuthorityInfo .Region != envRegion {
189+ t .Fatalf ("wanted %q, got %q" , envRegion , client .base .AuthParams .AuthorityInfo .Region )
190+ }
191+ }
192+
193+ func TestRegionAutoEnable_SpecifiedRegion_EnvRegion (t * testing.T ) {
194+ cred , err := NewCredFromSecret (fakeSecret )
195+ if err != nil {
196+ t .Fatal (err )
197+ }
198+
199+ envRegion := "envRegion"
200+ err = os .Setenv ("MSAL_FORCE_REGION" , envRegion )
201+ if err != nil {
202+ t .Fatal (err )
203+ }
204+ defer os .Unsetenv ("MSAL_FORCE_REGION" )
205+
206+ lmo := "login.microsoftonline.com"
207+ tenant := "tenant"
208+ mockClient := mock.Client {}
209+ testRegion := "region"
210+ client , err := New (fmt .Sprintf (authorityFmt , lmo , tenant ), fakeClientID , cred , WithHTTPClient (& mockClient ), WithAzureRegion (testRegion ))
211+ if err != nil {
212+ t .Fatal (err )
213+ }
214+
215+ if client .base .AuthParams .AuthorityInfo .Region != testRegion {
216+ t .Fatalf ("wanted %q, got %q" , testRegion , client .base .AuthParams .AuthorityInfo .Region )
217+ }
218+ }
219+
220+ func TestRegionAutoEnable_DisableMsalForceRegion (t * testing.T ) {
221+ cred , err := NewCredFromSecret (fakeSecret )
222+ if err != nil {
223+ t .Fatal (err )
224+ }
225+
226+ lmo := "login.microsoftonline.com"
227+ tenant := "tenant"
228+ mockClient := mock.Client {}
229+ testRegion := "DisableMsalForceRegion"
230+ client , err := New (fmt .Sprintf (authorityFmt , lmo , tenant ), fakeClientID , cred , WithHTTPClient (& mockClient ), WithAzureRegion (testRegion ))
231+ if err != nil {
232+ t .Fatal (err )
233+ }
234+
235+ if client .base .AuthParams .AuthorityInfo .Region != "" {
236+ t .Fatalf ("wanted empty, got %q" , client .base .AuthParams .AuthorityInfo .Region )
237+ }
238+ }
239+
167240func TestAcquireTokenOnBehalfOf (t * testing.T ) {
168241 // this test is an offline version of TestOnBehalfOf in integration_test.go
169242 cred , err := NewCredFromSecret (fakeSecret )
0 commit comments