예제 #1
0
        void preauth_fed_workplacejoined_asProxy_success(object px)
        {
            preauth_fed_asProxy_success_signal.Reset();
            WebProxy proxy = px as WebProxy;

            authTokenPresent   = false;
            accessToWebApp     = false;
            backendTlsCaptured = false;
            lock (managedThreads)
            {
                System.Threading.Thread t = new System.Threading.Thread(AsyncInstallAndPublishApp1AndAccess);
                t.Start();
                managedThreads.Add(t);
            }

            DateTime start   = DateTime.Now;
            int      timeout = 10;

            while ((DateTime.Now - start).TotalMinutes < timeout)
            {
                lock (resourceLocker)
                {
                    if (first != null)
                    {
                        first.Text = Encoding.UTF8.GetString(first.Data);
                        if (first.ParsedHttpRequest != null)
                        {
                            if (first.ParsedHttpRequest.Method == HttpRequest.HttpMethod.POST)
                            {
                            }
                            if (first.ParsedHttpRequest.RequestUrl.Path.ToLower() == Constraints.EstablishTrustUrl.ToLower())
                            {
                                if (proxyCert == null)
                                {
                                    if (first.ParsedHttpRequest.Body == null)
                                    {
                                        requestIs100Continue = true;
                                    }
                                    establishTrustRequest = first.ParsedHttpRequest;
                                    if (!requestIs100Continue)
                                    {
                                        //already full request
                                        retriveProxyCert();
                                        proxy.SetClientCertificate(proxyCert);
                                    }
                                }
                            }
                            else if (first.ParsedHttpRequest.RequestUrl.Path.ToLower() == Constraints.RenewTrustUrl.ToLower())
                            {
                                first.Ignore = true;
                            }
                            else if (first.ParsedHttpRequest.RequestUrl.Path.ToLower().Contains(Constraints.BackEndProxyTLSUrl.ToLower()))
                            {
                                backendTlsCaptured = true;
                            }
                            else if (first.ParsedHttpRequest.RequestUrl.Path.ToLower().Contains(EnvironmentConfig.App1Name.ToLower()))
                            {
                                accessToWebApp = true;
                                break;
                            }
                        }
                        else if (first.Sender == SenderType.Target)
                        {
                            if (first.ParsedHttpResponse == null)
                            {
                                first.ParsedHttpResponse = new HttpResponse();
                                first.ParsedHttpResponse.Parse(Encoding.UTF8.GetString(first.Data));
                            }
                            HttpResponse res = first.ParsedHttpResponse;

                            if (res.StatusCode == System.Net.HttpStatusCode.TemporaryRedirect)
                            {
                                string loc = res.GetHeaderFieldValue(System.Net.HttpResponseHeader.Location);
                                BaseTestSite.Assert.IsNotNull(loc, "location cannot be null for HTTP 307");
                                Url u = new Url(loc);
                                List <KeyValuePair <string, string> > pairs = u.GetQueryPairs();

                                foreach (KeyValuePair <string, string> p in pairs)
                                {
                                    if (p.Key.ToLower() == "authtoken")
                                    {
                                        authTokenPresent = true;
                                    }
                                }
                            }
                        }
                        else if (proxyCert == null && requestIs100Continue && first.ParsedHttpRequest == null)
                        {
                            establishTrustRequest.Body += first.Text;
                            retriveProxyCert();
                            proxy.SetClientCertificate(proxyCert);
                        }
                        second = first;
                        first  = null;
                    }
                }
                System.Threading.Thread.Sleep(150);
            }

            preauth_fed_asProxy_success_signal.Set();
        }