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); }
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)); }