@@ -733,8 +733,48 @@ def test_client_id_should_be_a_valid_scope(self):
733
733
"authorization_endpoint" : "https://contoso.com/placeholder" ,
734
734
"token_endpoint" : "https://contoso.com/placeholder" ,
735
735
}))
736
- @patch ("msal.application._init_broker" , new = Mock ()) # Allow testing without pymsalruntime
737
- class TestBrokerFallback (unittest .TestCase ):
736
+ class TestMsalBehaviorWithoutPyMsalRuntimeOrBroker (unittest .TestCase ):
737
+
738
+ @patch ("msal.application._init_broker" , new = Mock (side_effect = ImportError (
739
+ "PyMsalRuntime not installed"
740
+ )))
741
+ def test_broker_should_be_disabled_by_default (self ):
742
+ app = msal .PublicClientApplication (
743
+ "client_id" ,
744
+ authority = "https://login.microsoftonline.com/common" ,
745
+ )
746
+ self .assertFalse (app ._enable_broker )
747
+
748
+ @patch ("msal.application._init_broker" , new = Mock (side_effect = ImportError (
749
+ "PyMsalRuntime not installed"
750
+ )))
751
+ def test_should_error_out_when_opted_in_yet_pymsalruntime_not_installed (self ):
752
+ with self .assertRaises (ImportError ):
753
+ app = msal .PublicClientApplication (
754
+ "client_id" ,
755
+ authority = "https://login.microsoftonline.com/common" ,
756
+ enable_broker_on_mac = True ,
757
+ )
758
+
759
+ @patch ("msal.application._init_broker" , new = Mock (side_effect = RuntimeError (
760
+ "PyMsalRuntime raises RuntimeError when broker initialization failed"
761
+ )))
762
+ def test_should_fallback_when_pymsalruntime_failed_to_initialize_broker (self ):
763
+ app = msal .PublicClientApplication (
764
+ "client_id" ,
765
+ authority = "https://login.microsoftonline.com/common" ,
766
+ enable_broker_on_mac = True ,
767
+ )
768
+ self .assertFalse (app ._enable_broker )
769
+
770
+
771
+ @patch ("sys.platform" , new = "darwin" ) # Pretend running on Mac.
772
+ @patch ("msal.authority.tenant_discovery" , new = Mock (return_value = {
773
+ "authorization_endpoint" : "https://contoso.com/placeholder" ,
774
+ "token_endpoint" : "https://contoso.com/placeholder" ,
775
+ }))
776
+ @patch ("msal.application._init_broker" , new = Mock ()) # Pretend pymsalruntime installed and working
777
+ class TestBrokerFallbackWithDifferentAuthorities (unittest .TestCase ):
738
778
739
779
def test_broker_should_be_disabled_by_default (self ):
740
780
app = msal .PublicClientApplication (
0 commit comments