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) {} } }
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); }
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); }
public BadFetcher(FetchResponse resp) { this.resp = resp; this.message = "barf"; }
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; }
public FetchException( FetchResponse response, string message ) : base(message) { this.response = response; }