Exemple #1
0
        public void TestUserIsAuthorizedIfNotRuleIsDefinedForUrl()
        {
            MockWebClientApplication            mockApplication  = new MockWebClientApplication();
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew <MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew <MockVirtualPathUtility, IVirtualPathUtilityService>();

            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            MockHttpContext mockContext = new MockHttpContext();

            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();

            module.TestHandleAuthorization(mockApplication, mockContext);

            Assert.AreEqual("~/files.asx", mockRulesCatalog.LastGetRuleUrl);
        }
        public void TestAuthorizationServiceIsAskedForAuthorizationRule()
        {
            MockWebClientApplication mockApplication = new MockWebClientApplication();
            MockAuthorizationService mockAuthorizationService =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationService, IAuthorizationService>();
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew<MockVirtualPathUtility, IVirtualPathUtilityService>();
            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            mockRulesCatalog.GetRuleReturnValue = new string[] {"AuthorizationRule"};
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();
            module.TestHandleAuthorization(mockApplication, mockContext);

            Assert.AreEqual("~/files.asx", mockRulesCatalog.LastGetRuleUrl);
            Assert.AreEqual("AuthorizationRule", mockAuthorizationService.LastContext);
        }
Exemple #3
0
        public void TestWebAuthorizationExceptionThrownIfNotAuthorized()
        {
            MockWebClientApplication mockApplication          = new MockWebClientApplication();
            MockAuthorizationService mockAuthorizationService =
                mockApplication.RootContainer.Services.AddNew <MockAuthorizationService, IAuthorizationService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew <MockVirtualPathUtility, IVirtualPathUtilityService>();

            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            mockAuthorizationService.ShouldAuthorize   = false;
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew <MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();

            mockRulesCatalog.GetRuleReturnValue = new string[] { "AuthorizationRule" };
            MockHttpContext mockContext = new MockHttpContext();

            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();

            module.TestHandleAuthorization(mockApplication, mockContext);
        }
        public void TestWebAuthorizationExceptionThrownIfNotAuthorized()
        {
            MockWebClientApplication mockApplication = new MockWebClientApplication();
            MockAuthorizationService mockAuthorizationService =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationService, IAuthorizationService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew<MockVirtualPathUtility, IVirtualPathUtilityService>();
            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            mockAuthorizationService.ShouldAuthorize = false;
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();
            mockRulesCatalog.GetRuleReturnValue = new string[] {"AuthorizationRule"};
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();
            module.TestHandleAuthorization(mockApplication, mockContext);
        }