Beispiel #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) {}
            }
        }
Beispiel #2
0
 public void Test(FetchResponse actual)
 {
     TestTools.Assert(actual.code == this.code);
     TestTools.Assert(actual.finalUri.Equals(this.final));
     TestTools.Assert(
     Encoding.GetEncoding(actual.charset).GetString(
     actual.data) == this.body);
 }
Beispiel #3
0
        public TestFetcher(Uri userUri, string userPage, AssociationInfo ainfo)
        {
            this.assoc = ainfo;
            this.getResponses = new Hashtable();

            byte[] data = Encoding.UTF8.GetBytes(userPage);
            FetchResponse resp = new FetchResponse(
            HttpStatusCode.OK, userUri, "UTF-8", data, data.Length);
            this.getResponses.Add(userUri, resp);
        }
Beispiel #4
0
 public BadFetcher(FetchResponse resp)
 {
     this.resp = resp;
     this.message = "barf";
 }
Beispiel #5
0
        private static AuthRequest ParseIdentityInfo(FetchResponse response)
        {
            string server = null;
            string deleg = null;
            string rel, href;
            foreach (NameValueCollection attrs in LinkParser.ParseLinkAttrs(response.data, response.length, response.charset))
            {
            rel = attrs["rel"];
            if (rel != null)
            {
            href = attrs["href"];
            if (rel == "openid.server" && server == null)
            if (href != null)
                server = href;

            if (rel == "openid.delegate" && deleg == null)
            if (href != null)
                deleg = href;
            }
            }

            if (server == null)
            throw new ParseException();

            AuthRequest request = new AuthRequest();

            request.serverUri = UriUtil.NormalizeUri(server);

            if (deleg == null)
            request.serverId = response.finalUri;
            else
            request.serverId = UriUtil.NormalizeUri(deleg);

            return request;
        }
Beispiel #6
0
        public FetchException( FetchResponse response, 
				string message )
            : base(message)
        {
            this.response = response;
        }