public void Initialize() { TestCommon.ResetInternalStaticCaches(); _serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, clientId: ClientId); _logger = _serviceBundle.ApplicationLogger; _platformProxy = _serviceBundle.PlatformProxy; _crypto = _platformProxy.CryptographyManager; }
public void Setup() { TestCommon.ResetInternalStaticCaches(); _testReceiver = new _TestReceiver(); var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, clientId: ClientId); _telemetryManager = new TelemetryManager(serviceBundle.Config, serviceBundle.PlatformProxy, _testReceiver.HandleTelemetryEvents); _trackingEvent = new _TestEvent("tracking event", CorrelationId); }
public void Initialize() { TestCommon.ResetInternalStaticCaches(); _myReceiver = new MyReceiver(); _serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, clientId: ClientId); _logger = _serviceBundle.DefaultLogger; _platformProxy = _serviceBundle.PlatformProxy; _crypto = _platformProxy.CryptographyManager; _telemetryManager = new TelemetryManager(_serviceBundle.Config, _platformProxy, _myReceiver.HandleTelemetryEvents); }
public void Setup() { TestCommon.ResetInternalStaticCaches(); _testReceiver = new _TestReceiver(); var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager( null, clientId: ClientId, telemetryCallback: _testReceiver.HandleTelemetryEvents); _requestContext = new RequestContext(serviceBundle, Guid.NewGuid()); _trackingEvent = new _TestEvent("tracking event", CorrelationId); }
public MockHttpAndServiceBundle( TelemetryCallback telemetryCallback = null, LogCallback logCallback = null, bool isExtendedTokenLifetimeEnabled = false) { HttpManager = new MockHttpManager(); ServiceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager( HttpManager, telemetryCallback: telemetryCallback, logCallback: logCallback, isExtendedTokenLifetimeEnabled: isExtendedTokenLifetimeEnabled); }
public void FailedValidationTest() { using (var harness = CreateTestHarness()) { // add mock response for instance validation harness.HttpManager.AddMockHandler( new MockHttpMessageHandler { ExpectedMethod = HttpMethod.Get, ExpectedUrl = "https://login.microsoftonline.com/common/discovery/instance", ExpectedQueryParams = new Dictionary <string, string> { { "api-version", "1.1" }, { "authorization_endpoint", "https%3A%2F%2Flogin.microsoft0nline.com%2Fmytenant.com%2Foauth2%2Fv2.0%2Fauthorize" }, }, ResponseMessage = MockHelpers.CreateFailureMessage( HttpStatusCode.BadRequest, "{\"error\":\"invalid_instance\"," + "\"error_description\":\"AADSTS50049: " + "Unknown or invalid instance. Trace " + "ID: b9d0894d-a9a4-4dba-b38e-8fb6a009bc00 " + "Correlation ID: 34f7b4cf-4fa2-4f35-a59b" + "-54b6f91a9c94 Timestamp: 2016-08-23 " + "20:45:49Z\",\"error_codes\":[50049]," + "\"timestamp\":\"2016-08-23 20:45:49Z\"," + "\"trace_id\":\"b9d0894d-a9a4-4dba-b38e-8f" + "b6a009bc00\",\"correlation_id\":\"34f7b4cf-" + "4fa2-4f35-a59b-54b6f91a9c94\"}") }); Authority instance = Authority.CreateAuthority("https://login.microsoft0nline.com/mytenant.com", true); Assert.IsNotNull(instance); Assert.AreEqual(instance.AuthorityInfo.AuthorityType, AuthorityType.Aad); TestCommon.CreateServiceBundleWithCustomHttpManager(harness.HttpManager, authority: instance.AuthorityInfo.CanonicalAuthority, validateAuthority: true); try { var resolver = new AuthorityEndpointResolutionManager(harness.ServiceBundle); var endpoints = resolver.ResolveEndpointsAsync( instance.AuthorityInfo, null, new RequestContext(harness.ServiceBundle, Guid.NewGuid())) .ConfigureAwait(false).GetAwaiter().GetResult(); Assert.Fail("validation should have failed here"); } catch (Exception exc) { Assert.IsTrue(exc is MsalServiceException); Assert.AreEqual(((MsalServiceException)exc).ErrorCode, "invalid_instance"); } } }
public MockHttpAndServiceBundle( TelemetryCallback telemetryCallback = null, LogCallback logCallback = null, bool isExtendedTokenLifetimeEnabled = false, string authority = ClientApplicationBase.DefaultAuthority) { HttpManager = new MockHttpManager(); ServiceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager( HttpManager, telemetryCallback: telemetryCallback, logCallback: logCallback, isExtendedTokenLifetimeEnabled: isExtendedTokenLifetimeEnabled, authority: authority); }
public void PiiLoggingEnabledTrue_ApiEventFieldsHashedTest() { var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, enablePiiLogging: true); _logger = serviceBundle.DefaultLogger; var correlationId = Guid.NewGuid().AsMatsCorrelationId(); try { var e1 = new ApiEvent(_logger, _crypto, correlationId) { Authority = new Uri("https://login.microsoftonline.com"), AuthorityType = "Aad", TenantId = TenantId, AccountId = UserId, LoginHint = "loginHint" }; _telemetryManager.StartEvent(e1); // do some stuff... e1.WasSuccessful = true; // TenantId and UserId are hashed if (e1.ContainsKey(ApiEvent.TenantIdKey)) { Assert.AreNotEqual(null, e1[ApiEvent.TenantIdKey]); Assert.AreNotEqual(TenantId, e1[ApiEvent.TenantIdKey]); } if (e1.ContainsKey(ApiEvent.UserIdKey)) { Assert.AreNotEqual(null, e1[ApiEvent.UserIdKey]); Assert.AreNotEqual(UserId, e1[ApiEvent.UserIdKey]); } if (e1.ContainsKey(ApiEvent.LoginHintKey)) { Assert.AreNotEqual(null, e1[ApiEvent.LoginHintKey]); Assert.AreNotEqual("loginHint", e1[ApiEvent.LoginHintKey]); } _telemetryManager.StopEvent(e1); } finally { _telemetryManager.Flush(correlationId); } Assert.IsTrue(_myReceiver.EventsReceived.Count > 0); }
public MockHttpAndServiceBundle( LogCallback logCallback = null, bool isExtendedTokenLifetimeEnabled = false, string authority = ClientApplicationBase.DefaultAuthority, TestContext testContext = null, bool isMultiCloudSupportEnabled = false) { HttpManager = new MockHttpManager(testContext); ServiceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager( HttpManager, logCallback: logCallback, isExtendedTokenLifetimeEnabled: isExtendedTokenLifetimeEnabled, authority: authority, isMultiCloudSupportEnabled: isMultiCloudSupportEnabled); }
public void GlobalSetup() { var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, isLegacyCacheEnabled: EnableLegacyCache); _cache = new TokenCache(serviceBundle, false); _response = TestConstants.CreateMsalTokenResponse(TestConstants.Utid); _requestParams = TestCommon.CreateAuthenticationRequestParameters(serviceBundle); _requestParams.Account = new Account(TestConstants.s_userIdentifier, $"1{TestConstants.DisplayableId}", TestConstants.ProductionPrefNetworkEnvironment); AddHostToInstanceCache(serviceBundle, TestConstants.ProductionPrefCacheEnvironment); LegacyTokenCacheHelper.PopulateLegacyCache(serviceBundle.ApplicationLogger, _cache.LegacyPersistence, TokenCacheSize); TokenCacheHelper.AddRefreshTokensToCache(_cache.Accessor, TokenCacheSize); }