Beispiel #1
0
        public async Task BrokerSilentRequestTestExecutorAsync(bool brokerConfiguredByUser, bool brokerIsInstalledAndInvokable)
        {
            string brokerID = "*****@*****.**";

            using (var harness = new MockHttpTestHarness(TestConstants.AuthorityHomeTenant))
            {
                // resul will be from the cache
                TokenCacheHelper.PopulateCache(harness.Cache.Accessor,
                                               TestConstants.Uid,
                                               TestConstants.Utid,
                                               TestConstants.ClientId,
                                               TestConstants.ProductionPrefCacheEnvironment,
                                               brokerID);

                IBroker mockBroker = Substitute.For <IBroker>();
                mockBroker.IsBrokerInstalledAndInvokable().ReturnsForAnyArgs(brokerIsInstalledAndInvokable);

                harness.ServiceBundle.Config.BrokerCreatorFunc = (app, config, logger) => mockBroker;

                var parameters = harness.CreateRequestParams(
                    harness.Cache,
                    null,
                    TestConstants.ExtraQueryParameters,
                    null,
                    authorityOverride: AuthorityInfo.FromAuthorityUri(TestConstants.AuthorityCommonTenant, false));
                parameters.AppConfig.IsBrokerEnabled = brokerConfiguredByUser;

                var silentParameters = new AcquireTokenSilentParameters()
                {
                    Account = new Account(TestConstants.HomeAccountId, TestConstants.DisplayableId, TestConstants.ProductionPrefCacheEnvironment),
                };

                var request = new SilentRequest(harness.ServiceBundle, parameters, silentParameters);

                var result = await request.RunAsync(default).ConfigureAwait(false);
Beispiel #2
0
        private IBroker CreateMockBroker()
        {
            IBroker mockBroker = Substitute.For <IBroker>();

            mockBroker.IsBrokerInstalledAndInvokable().ReturnsForAnyArgs(true);
            mockBroker.AcquireTokenUsingBrokerAsync(null).ReturnsForAnyArgs(TestConstants.CreateMsalTokenResponse());
            return(mockBroker);
        }
Beispiel #3
0
        public override bool CanBrokerSupportSilentAuth()
        {
            IBroker broker = CreateBroker(null);

            if (broker.IsBrokerInstalledAndInvokable())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }