Ejemplo n.º 1
0
        public void BadFetch()
        {
            Uri userUrl = new Uri("http://who.cares/");
            IAssociationStore store = new MemoryStore();
            Consumer consumer;

            ArrayList cases = new ArrayList();
            cases.Add(null);
            cases.Add(HttpStatusCode.NotFound);
            cases.Add(HttpStatusCode.BadRequest);
            cases.Add(HttpStatusCode.InternalServerError);

            byte[] data = Encoding.UTF8.GetBytes("Who cares?");
            FetchResponse resp;
            foreach (object code in cases)
            {
            if (code == null)
            resp = null;
            else
            resp = new FetchResponse((HttpStatusCode) code, userUrl, "UTF-8", data, data.Length);

            consumer = new Consumer(store, new BadFetcher(resp));
            try
            {
            consumer.BeginAuth(userUrl);
            TestTools.Assert(false, String.Format("Consumer failed to raise FetchException: {0}", code.ToString()));
            }
            catch (FetchException e) {}
            }
        }
Ejemplo n.º 2
0
        public void BadParse()
        {
            IAssociationStore store = new MemoryStore();
            Uri userUrl = new Uri("http://user.example.com/");

            string[] cases =
            { "",
              "http://not.in.a.link.tag/",
              "<link rel=\"openid.server\" href=\"not.in.html.or.head\" />"
            };

            Fetcher fetcher;
            Consumer consumer;
            foreach (string userPage in cases)
            {
            fetcher = new TestFetcher(userUrl, userPage, null);
            consumer = new Consumer(store, fetcher);
            try {
            consumer.BeginAuth(userUrl);
            TestTools.Assert(false, String.Format("Shouldn't have succeeded with user_page=[{0}]", userPage));
            }
            catch (ParseException e) {}

            }
        }
Ejemplo n.º 3
0
        private void Success(Uri userUri, Uri delegateUri, string links, Consumer.Mode immediate)
        {
            MemoryStore store = new MemoryStore();

            string mode;
            if (immediate == Consumer.Mode.IMMEDIATE)
            mode = "checkid_immediate";
            else
            mode = "checkid_setup";

            string userPage = String.Format(USER_PAGE_PAT, links);
            string test_handle = "Snarky";
            AssociationInfo info = new AssociationInfo(
                Encoding.ASCII.GetBytes("another 20-byte key."), test_handle);
            Fetcher fetcher = new TestFetcher(userUri, userPage, info);

            Consumer consumer = new Consumer(store, fetcher);

            AuthRequest request = consumer.BeginAuth(userUri);
            Uri returnTo = new Uri(consumerUri.AbsoluteUri, true);
            string trustRoot = consumerUri.AbsoluteUri;
            Uri redirectUri = consumer.CreateRedirect(immediate, request, returnTo, trustRoot);

            NameValueCollection q = FormParser.Parse(Encoding.UTF8.GetBytes(redirectUri.Query.Substring(1)));

            string errmsg = redirectUri.AbsoluteUri;
            TestTools.Assert(q.Count == 5, errmsg);
            TestTools.Assert(q["openid.mode"] == mode, errmsg);
            TestTools.Assert(q["openid.identity"] == delegateUri.AbsoluteUri, errmsg);
            TestTools.Assert(q["openid.trust_root"] == trustRoot, errmsg);
            TestTools.Assert(q["openid.assoc_handle"] == test_handle, errmsg);
            TestTools.Assert(q["openid.return_to"] == returnTo.AbsoluteUri, errmsg);

            TestTools.Assert(redirectUri.AbsoluteUri.StartsWith(serverUri.AbsoluteUri), errmsg);

            NameValueCollection query = new NameValueCollection();
            query.Add("openid.mode", "id_res");
            query.Add("openid.return_to", returnTo.AbsoluteUri);
            query.Add("openid.identity", delegateUri.AbsoluteUri);
            query.Add("openid.assoc_handle", test_handle);

            Association assoc = store.GetAssociation(serverUri, test_handle);
            string sig = assoc.SignDict(new string[] { "mode", "return_to", "identity" }, query, "openid.");

            query.Add("openid.sig", sig);
            query.Add("openid.signed", "mode,return_to,identity");

            object result;
            Consumer.Status status = consumer.CompleteAuth(request.token, query, out result);
            TestTools.Assert(status == Consumer.Status.SUCCESS);
            TestTools.Assert(((Uri)result).AbsoluteUri == userUri.AbsoluteUri, String.Format("info:{0}\nuserUri:{1}", info, userUri));
        }