public static void BaseInitialize(TestContext context)
        {
            TestClassBase.Initialize(context);

            // load ptfconfig properties
            EnvironmentConfig.LoadParameters(BaseTestSite);
            EnvironmentConfig.CheckParameters(BaseTestSite);

            // initialize controller adapter
            SutAdapter      = BaseTestSite.GetAdapter <ISUTControlAdapter>();
            AsyncSutAdapter = new SUTControlAdapterAsync(SutAdapter);

            // initialize client adapter
            ClientAdapter = BaseTestSite.GetAdapter <IMSADFSPIPClientAdapter>();
            if (!m_sslCertBinded)
            {
                ClientAdapter.BindCertificate(new X509Certificate2(
                                                  EnvironmentConfig.TLSServerCertificatePath,
                                                  EnvironmentConfig.TLSServerCertificatePassword));
                m_sslCertBinded = true;
            }

            // initialize server data model and handler factory
            ServerDataModel = ServerDataModel.InitiateServerDataModel();
        }
        public void S3_RemoveApplication_NotPublished_Fail()
        {
            // remove the published application
            ServerDataModel.ResetPublishedEndpoint();
            // trigger the client to remove an application asynchronously
            // so that it does not block the main thread
            var sut = AsyncSutAdapter.TriggerRemoveApplicationAsync();

            TestSite.Log.Add(LogEntryKind.Comment, "Triggering proxy client to remove a web application");

            // start receiving client request
            // when request comes, forward it to the corresponding handler
            while ((CurrentRequest = ClientAdapter.ExpectRequest()) != null)
            {
                TestSite.Log.Add(LogEntryKind.Comment, "Received request for " + CurrentRequest.RequestUri.AbsolutePath);

                CurrentHandler = (ProxyRequestHandlerBase)Factory.GetRequestHandler(CurrentRequest);
                TestSite.Assert.IsTrue(CurrentHandler.VerifyRequest(out VerifyMessage), VerifyMessage);

                if (CurrentHandler is DeleteProxyPublishSettingsRequestHandler)
                {
                    CurrentResponse = ((DeleteProxyPublishSettingsRequestHandler)CurrentHandler)
                                      .GetNotFoundResponse();
                }
                else
                {
                    CurrentResponse = CurrentHandler.GetResponse();
                }

                ClientAdapter.SendResponse(CurrentResponse);
                TestSite.Log.Add(LogEntryKind.Comment, "Response has been sent to the client.");
            }

            TestSite.Assert.IsFalse(sut.Result.Return, "Client acted correctly with 404 response.");
        }
        public HttpResponseMessage GetSuccessResponse()
        {
            ServerDataModel.AddProxyTrustCertificate(JSONObject.Parse <ProxyTrustRenewal>(Request.Content.GetString()));

            return(new HttpResponseMessage(200)
            {
                ContentType = TextHtmlContent
            });
        }
Example #4
0
        public HttpResponseMessage GetSuccessResponse()
        {
            var response = new HttpResponseMessage(200)
            {
                ContentType = ApplicationJsonContent
            };

            response.Content.SetString(ServerDataModel.GetSerializedProxyRelyingPartyTrust());
            return(response);
        }
        public HttpResponseMessage GetSuccessResponse()
        {
            var response = new HttpResponseMessage(200)
            {
                ContentType = TextHtmlContent
            };

            response.Content.SetString(ServerDataModel.GetFederationMetadata());
            return(response);
        }
        public HttpResponseMessage GetSuccessResponse()
        {
            var response = new HttpResponseMessage(200)
            {
                ContentType = TextHtmlContent
            };

            response.Content.SetString(ServerDataModel.GetSerializedStsConfiguration());
            return(response);
        }
Example #7
0
        public override bool VerifyRequest(out string message)
        {
            // parse query string parameters
            var param = ParseFedauthQueryString(Request.RequestUri.Query);

            // check version
            if (param.Version != "1.0")
            {
                message = "Version of the protocol MUST be 1.0.";
                return(false);
            }

            // check Action
            if (!param.Action.EqualsIgnoreCase("signin"))
            {
                message = "Action on authentication request MUST be signin";
                return(false);
            }

            // check Realm
            if (!param.Realm.EqualsIgnoreCase(Constraints.DefaultProxyRelyingPartyTrustIdentifier))
            {
                message = "Realm MUST be [Client State].ProxyRelyingPartyTrustIdentifier.";
                return(false);
            }

            // retrieve published application
            var endpoint = ServerDataModel.GetPublishedEndpoint((string)DynamicObject.InitialUrl);

            if (endpoint == null)
            {
                message = "Endpoint with the url was not found.";
                return(false);
            }

            // check AppRealm
            // There is an TDI here, the AppRealm is the relying party ID, not the URL of the endpoint
            if (!param.AppRealm.EqualsIgnoreCase(endpoint.ADFSRelyingPartyID))
            {
                message = "AppRealm must match the relying party ID.";
                return(false);
            }

            // check ReturnUrl
            if (!param.ReturnUrl.EqualsIgnoreCase(endpoint.FrontendUrl))
            {
                message = "ReturnUrl must match the URL of the published application.";
                return(false);
            }

            // validation passed
            message = "Query string parameters vefified.";
            return(true);
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            Factory.RegisterRequestHandler <PostProxyEstablishTrustRequestHandler>();
            Factory.RegisterRequestHandler <PostProxyTrustRequestHandler>();
            Factory.RegisterRequestHandler <GetProxyTrustRequestHandler>();
            Factory.RegisterRequestHandler <GetFederationMetadataRequestHandler>();

            ServerDataModel.SetPublishedEndpoint();
        }
        public override HttpResponseMessage GetResponse()
        {
            var requestedEntry = JSONObject.Parse <StoreEntry>(Request.Content.GetString());

            ServerDataModel.AddStoreEntry(requestedEntry);
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                ContentType = ApplicationJsonContent
            };

            response.Content.SetString(ServerDataModel.GetSerializedStoreEntry(requestedEntry.key));
            return(response);
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            // initialize mock client to visit the proxy
            MockClient = new MockClient(IPAddress.Parse(EnvironmentConfig.SUTIP));

            // make sure there is an application published
            ServerDataModel.SetPublishedEndpoint();

            // make sure the application proxy is deployed
            TestSite.Assert.IsTrue(SutAdapter.IsApplicationProxyConfigured(),
                                   "The Application must be deployed before running this test case.");
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            // register request handlers used by this test class
            Factory.RegisterRequestHandler <DeleteProxyPublishSettingsRequestHandler>();

            // make sure the application proxy is installed on the client
            TestSite.Assert.IsTrue(SutAdapter.IsApplicationProxyConfigured(),
                                   "Application proxy must be configured before removing applications");

            // set an application published before removing it
            ServerDataModel.SetPublishedEndpoint();
        }
Example #12
0
        /// <summary>
        /// Get an instance of ServerDataModel.
        /// </summary>
        /// <returns>
        /// An instance of ServerDataModel
        /// </returns>
        public static ServerDataModel InitiateServerDataModel()
        {
            // if the instance already exists
            if (_model != null)
            {
                return(_model);
            }

            // or create a new instance with default settings
            _model = new ServerDataModel();

            _storeDataFile = EnvironmentConfig.DataStorePath;
            // XML-syncing is disabled at present
            // the ServerDataModel instance gets instantiated first,
            // if the value stored in the XML file is not the same
            // as the current value, it overrides the current value.

            return(_model);
        }
        public void S5_WebAccess_AdfsPreauth_QueryStringBased_Success()
        {
            // make a request to the proxy with authToken
            var client = MockClient.MakeWebAccessRequestAsync(new Uri(EnvironmentConfig.App1Url),
                                                              ServerDataModel.GetAuthToken());

            TestSite.Log.Add(LogEntryKind.Comment, "Sending preauthenticated web access request to the proxy...");

            // auto-hanlde all other requests to the server until we get
            // the request to the web application.
            var replayedRequest = WaitForReqeust(EnvironmentConfig.App1Url);

            // once we get the redirected request, it means that the proxy has
            // validated the authToken and redirect the request to the internal
            // url correctly.
            TestSite.Assert.IsTrue(replayedRequest != null, "Preauthenticated request successfully redirected.");

            // After successful preauthentication the proxy MUST remove the authToken
            // parameter with its value before replaying the request to the internal URL.
            TestSite.Assert.IsTrue(!replayedRequest.RequestUri.Query.ContainsIgnoreCase("authToken"),
                                   "No authToken parameter contained in the replayed request.");
        }
        public void S6_ActiveClientAuth_AccessDenied()
        {
            ServerDataModel.ResetPublishedEndpoint();
            TestSite.Log.Add(LogEntryKind.Comment, "Reset Published Endpoint");
            System.Threading.Thread.Sleep(1000 * 30);
            // make a request to the proxy with authToken
            var sut = AsyncSutAdapter.TriggerPublishNonClaimsAppAsync();

            TestSite.Log.Add(LogEntryKind.Comment, "Triggering proxy client to publish a web application");

            System.Threading.Thread.Sleep(1000 * 60);

            TestSite.Log.Add(LogEntryKind.Comment, "Client start to access webapp");

            System.Threading.Thread.Sleep(1000 * 60);

            // make a request to the proxy with authToken
            var client = MockClient.MakeWebRequestWithBasicAuth(new Uri(EnvironmentConfig.App2Url),
                                                                ServerDataModel.GetIncorrectBasicAuthorizationHeader());

            TestSite.Assert.IsTrue(client.StatusCode == HttpStatusCode.Unauthorized, "Preauthenticated request failed redirected as access denied.");
        }
        public HttpResponseMessage GetSuccessResponse()
        {
            var response = new HttpResponseMessage(200)
            {
                ContentType = ApplicationJsonContent
            };

            // if the absolute path ENDs with store url, it means to get all the store entries
            if (Regex.IsMatch(Request.RequestUri.AbsolutePath, Constraints.StoreUrl + "$", RegexOptions.IgnoreCase))
            {
                response.Content.SetString(ServerDataModel.GetSerializedStoreEntry());
            }
            else
            {
                // otherwise, get a specific entry
                var entryKey = Request.RequestUri.AbsolutePath.Substring(
                    Request.RequestUri.AbsolutePath.IndexOf(Constraints.StoreUrl, 0,
                                                            StringComparison.InvariantCultureIgnoreCase) +
                    Constraints.StoreUrl.Length + 1);
                response.Content.SetString(ServerDataModel.GetSerializedStoreEntry(entryKey));
            }
            return(response);
        }
Example #16
0
        public HttpResponseMessage GetSuccessResponse()
        {
            ServerDataModel.AddProxyRelyingPartyTrust(JSONObject.Parse <ProxyRelyingPartyTrust>(Request.Content.GetString()));

            return(new HttpResponseMessage(200));
        }
Example #17
0
 public ProxyRequestHandlerFactory(ServerDataModel serverDataModel)
 {
     _handlerPool     = new List <IRequestHandler>();
     _serverDataModel = serverDataModel;
 }