public void CreateRequestsReturnsEmpty()
        {
            MockHttpRequest.RegisterMockResponse(new Uri("http://host/"), "text/html", "<html/>");
            var consumer = TestSupport.CreateRelyingParty(null);

            CollectionAssert.IsEmpty(consumer.CreateRequests("http://host/", realm, returnTo));
        }
Example #2
0
        public void Redirects()
        {
            UntrustedWebRequest.WhitelistHosts.Add("localhost");
            UntrustedWebResponse resp = new UntrustedWebResponse(
                new Uri("http://localhost/req"), new Uri("http://localhost/resp"),
                new WebHeaderCollection(), HttpStatusCode.OK, "text/html", null, new MemoryStream());

            MockHttpRequest.RegisterMockResponse(resp);
            Assert.AreSame(resp, UntrustedWebRequest.Request(new Uri("http://localhost/req")));
        }
Example #3
0
        public void DiscoveryRequireSslWithInsecureXrdsInSecureHtmlHead()
        {
            var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20, false);
            Uri secureClaimedUri   = TestSupport.GetFullUrl("/secureId", null, true);

            string html = string.Format("<html><head><meta http-equiv='X-XRDS-Location' content='{0}'/></head><body></body></html>",
                                        insecureXrdsSource);

            MockHttpRequest.RegisterMockResponse(secureClaimedUri, "text/html", html);

            Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true);

            Assert.AreEqual(0, userSuppliedIdentifier.Discover().Count());
        }
Example #4
0
        public void DiscoveryRequireSslWithInsecureXrdsInSecureHttpHeader()
        {
            var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20, false);
            Uri secureClaimedUri   = TestSupport.GetFullUrl("/secureId", null, true);

            string html = "<html><head></head><body></body></html>";
            WebHeaderCollection headers = new WebHeaderCollection {
                { "X-XRDS-Location", insecureXrdsSource }
            };

            MockHttpRequest.RegisterMockResponse(secureClaimedUri, secureClaimedUri, "text/html", headers, html);

            Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true);

            Assert.AreEqual(0, userSuppliedIdentifier.Discover().Count());
        }
Example #5
0
        public void RelativeRedirect()
        {
            UntrustedWebRequest.WhitelistHosts.Add("localhost");
            UntrustedWebResponse resp1 = new UntrustedWebResponse(
                new Uri("http://localhost/dir/file1"), new Uri("http://localhost/dir/file1"),
                new WebHeaderCollection {
                { HttpResponseHeader.Location, "file2" },
            }, HttpStatusCode.Redirect, "text/html", null, new MemoryStream());

            MockHttpRequest.RegisterMockResponse(resp1);
            UntrustedWebResponse resp2 = new UntrustedWebResponse(
                new Uri("http://localhost/dir/file2"), new Uri("http://localhost/dir/file2"),
                new WebHeaderCollection(), HttpStatusCode.OK, "text/html", null, new MemoryStream());

            MockHttpRequest.RegisterMockResponse(resp2);
            Assert.AreSame(resp2, UntrustedWebRequest.Request(new Uri("http://localhost/dir/file1")));
        }
Example #6
0
        void discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect, WebHeaderCollection headers)
        {
            Protocol      protocol  = Protocol.Lookup(version);
            UriIdentifier claimedId = TestSupport.GetFullUrl(url);
            UriIdentifier userSuppliedIdentifier = TestSupport.GetFullUrl(
                "Discovery/htmldiscovery/redirect.aspx?target=" + url);

            if (expectedLocalId == null)
            {
                expectedLocalId = claimedId;
            }
            Identifier idToDiscover = useRedirect ? userSuppliedIdentifier : claimedId;

            string contentType;

            if (url.EndsWith("html"))
            {
                contentType = "text/html";
            }
            else if (url.EndsWith("xml"))
            {
                contentType = "application/xrds+xml";
            }
            else
            {
                throw new InvalidOperationException();
            }
            MockHttpRequest.RegisterMockResponse(new Uri(idToDiscover), claimedId, contentType,
                                                 headers ?? new WebHeaderCollection(), TestSupport.LoadEmbeddedFile(url));

            ServiceEndpoint se = idToDiscover.Discover().FirstOrDefault();

            Assert.IsNotNull(se, url + " failed to be discovered.");
            Assert.AreSame(protocol, se.Protocol);
            Assert.AreEqual(claimedId, se.ClaimedIdentifier);
            Assert.AreEqual(expectedLocalId, se.ProviderLocalIdentifier);
            Assert.AreEqual(expectSreg ? 2 : 1, se.ProviderSupportedServiceTypeUris.Length);
            Assert.IsTrue(Array.IndexOf(se.ProviderSupportedServiceTypeUris, protocol.ClaimedIdentifierServiceTypeURI) >= 0);
            Assert.AreEqual(expectSreg, se.IsExtensionSupported(new ClaimsRequest()));
        }
Example #7
0
        public void DiscoveryRequireSslWithInsecureXrdsButSecureLinkTags()
        {
            var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20, false);
            Uri secureClaimedUri   = TestSupport.GetFullUrl("/secureId", null, true);

            Identifier localIdForLinkTag = TestSupport.GetDelegateUrl(TestSupport.Scenarios.AlwaysDeny, true);
            string     html = string.Format(@"
	<html><head>
		<meta http-equiv='X-XRDS-Location' content='{0}'/> <!-- this one will be insecure and ignored -->
		<link rel='openid2.provider' href='{1}' />
		<link rel='openid2.local_id' href='{2}' />
	</head><body></body></html>"    ,
                                            HttpUtility.HtmlEncode(insecureXrdsSource),
                                            HttpUtility.HtmlEncode(TestSupport.GetFullUrl("/" + TestSupport.ProviderPage, null, true).AbsoluteUri),
                                            HttpUtility.HtmlEncode(localIdForLinkTag.ToString())
                                            );

            MockHttpRequest.RegisterMockResponse(secureClaimedUri, "text/html", html);

            Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true);

            Assert.AreEqual(localIdForLinkTag, userSuppliedIdentifier.Discover().Single().ProviderLocalIdentifier);
        }