Esempio n. 1
0
        private void btnRestTester_Reqest_Click(object sender, RoutedEventArgs e)
        {
            txtRestResponseContent.Document.Blocks.Clear();

            try
            {
                txtRestResponseContent.AppendText(RestConnector.Connect(txtRestUrl.Text,
                                                                        GetRichTextBoxText(txtRestData)));
            }
            catch (Exception ex) {
                txtRestResponseContent.AppendText(ex.Message);
            }
        }
Esempio n. 2
0
        public static void AssemblyInitialize(TestContext context)
        {
            // Check if .runsettings is configured properly
            EnsurePropertiesSet(context.Properties,
                                "ignoreServerCertificateValidation",
                                "webAppUrl",
                                "userName",
                                "password",
                                "sharedSpaceId",
                                "workspaceId");

            var ignoreServerCertificateValidation = context.Properties["ignoreServerCertificateValidation"].ToString();

            if (ignoreServerCertificateValidation != null && ignoreServerCertificateValidation.ToLower().Equals("true"))
            {
                NetworkSettings.IgnoreServerCertificateValidation();
            }
            NetworkSettings.EnableAllSecurityProtocols();

            OctaneConfiguration.Url      = context.Properties["webAppUrl"].ToString();
            OctaneConfiguration.Username = context.Properties["userName"].ToString();
            OctaneConfiguration.Password = context.Properties["password"].ToString();

            var connectionInfo = new UserPassConnectionInfo(OctaneConfiguration.Username, OctaneConfiguration.Password);

            RestConnector.Connect(OctaneConfiguration.Url, connectionInfo);

            var sharedSpaceId = int.Parse(context.Properties["sharedSpaceId"].ToString());
            var workspaceId   = int.Parse(context.Properties["workspaceId"].ToString());

            WorkspaceContext = new WorkspaceContext(sharedSpaceId, workspaceId);
            OctaneConfiguration.WorkSpaceId = WorkspaceContext.WorkspaceId;

            var sharedSpaceContext = new SharedSpaceContext(sharedSpaceId);

            OctaneConfiguration.SharedSpaceId = sharedSpaceContext.SharedSpaceId;

            OctaneConfiguration.SsoLogin        = bool.Parse(context.Properties["ssoLogin"].ToString());
            OctaneConfiguration.CredentialLogin = bool.Parse(context.Properties["credentialLogin"].ToString());

            User = GetWorkspaceUser();

            CurrentRelease = ReleaseUtilities.CreateRelease();

            // create the octaneservices object to be used by the tests
            OctaneServices.Create(OctaneConfiguration.Url,
                                  OctaneConfiguration.SharedSpaceId,
                                  OctaneConfiguration.WorkSpaceId);

            OctaneServices.GetInstance().Connect();
        }
        public void RestConnector_Connect_TestThrowException()
        {
            // This code query string is expired and will return a 400 Bad Request from GoToWebinar

            //Arrange
            string        returnUrl = @"http://scribesoft.com/?code={0}";
            RestConnector connector = new RestConnector();
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add(oauth, returnUrl);

            //Act:
            connector.Connect(properties);
        }
        public void RestConnector_ReConnect_Test()
        {
            //Connect twice to retrieve the access token from storage instead of getting it from the authorize call again
            //Will have to manually log into GoToWebinar with a valid account and pull the 'code' off of the URL, paste it below:

            //arrange
            string code = string.Empty;

            RestConnector connector = new RestConnector();
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add(oauth, string.Format(returnUrl, code));

            //act:
            connector.Connect(properties);

            //grab the access token and serialize it. This simulates what Scribe Online does after the inital call to the Connector:
            properties[oauth] = Scribe.Core.ConnectorApi.Serialization.XmlTextSerializer.Serialize <Dictionary <string, string> >(properties, null, null);
            connector.Connect(properties);

            //Assert:
            Assert.IsTrue(connector.IsConnected);
        }
Esempio n. 5
0
        public static void InitConnection(TestContext context)
        {
            if (!restConnector.IsConnected())
            {
                string host     = ConfigurationManager.AppSettings["webAppUrl"];
                string password = ConfigurationManager.AppSettings["password"];
                userName = ConfigurationManager.AppSettings["userName"];
                restConnector.Connect(host, userName, password);


                sharedSpaceId = int.Parse(ConfigurationManager.AppSettings["sharedSpaceId"]);
                workspaceId   = int.Parse(ConfigurationManager.AppSettings["workspaceId"]);

                workspaceContext   = new WorkspaceContext(sharedSpaceId, workspaceId);
                sharedSpaceContext = new SharedSpaceContext(sharedSpaceId);
            }
        }
        public static void InitConnection(TestContext context)
        {
            if (!restConnector.IsConnected())
            {
                string ignoreServerCertificateValidation = ConfigurationManager.AppSettings["ignoreServerCertificateValidation"];
                if (ignoreServerCertificateValidation != null && ignoreServerCertificateValidation.ToLower().Equals("true"))
                {
                    NetworkSettings.IgnoreServerCertificateValidation();
                }
                NetworkSettings.EnableAllSecurityProtocols();

                host = ConfigurationManager.AppSettings["webAppUrl"];

                // If webAppUrl is empty we do not try to connect.
                if (string.IsNullOrWhiteSpace(host))
                {
                    return;
                }

                ConnectionInfo connectionInfo;
                string         clientId = ConfigurationManager.AppSettings["clientId"];
                if (clientId != null)
                {
                    userName       = clientId;
                    connectionInfo = new APIKeyConnectionInfo(clientId, ConfigurationManager.AppSettings["clientSecret"]);
                }
                else
                {
                    userName       = ConfigurationManager.AppSettings["userName"];
                    password       = ConfigurationManager.AppSettings["password"];
                    connectionInfo = new UserPassConnectionInfo(userName, password);
                }

                lwssoAuthenticationStrategy = new LwssoAuthenticationStrategy(connectionInfo);
                restConnector.Connect(host, lwssoAuthenticationStrategy);


                var sharedSpaceId = int.Parse(ConfigurationManager.AppSettings["sharedSpaceId"]);
                var workspaceId   = int.Parse(ConfigurationManager.AppSettings["workspaceId"]);

                workspaceContext   = new WorkspaceContext(sharedSpaceId, workspaceId);
                sharedSpaceContext = new SharedSpaceContext(sharedSpaceId);
            }
        }
 private void OnLoginClick(object sender, EventArgs args)
 {
     try
     {
         lblStatus.Text      = "Authenticating ...";
         lblStatus.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(85)))), ((int)(((byte)(85)))), ((int)(((byte)(85)))));
         bool connected = restConnector.Connect(txtServer.Text, new UserPassConnectionInfo(txtName.Text, txtPassword.Text));
         if (connected)
         {
             btnAuthenticate.Enabled = true;
             Application.DoEvents();
             lblStatus.Text = "";
             LoadSharedSpaces();
         }
         else
         {
             lblStatus.Text      = "Failed to authenticate. Validate connection URL is in format http://<domain>:<port>";
             lblStatus.ForeColor = Color.Red;
         }
     }
     catch (Exception e)
     {
         Exception innerException = e.InnerException ?? e;
         String    exMessage      = "";
         if (innerException.Message.Contains("401"))
         {
             exMessage = "Failed to authenticate. Validate your username and password.";
         }
         else if (innerException.Message.Contains("404"))
         {
             exMessage = "Failed to authenticate. Validate connection URL is in format http://<domain>:<port>";
         }
         else
         {
             exMessage = "Failed to authenticate : " + innerException.Message;
         }
         lblStatus.Text      = exMessage;
         lblStatus.ForeColor = Color.Red;
     }
 }
Esempio n. 8
0
        public ALMOctaneConnection(string host, string userName, string password, string sharedSpaceId, string workspaceId)
        {
            RestConnector = new RestConnector();
            EntityService = new EntityService(RestConnector);
            SharedspaceId = sharedSpaceId;
            WorkspaceId   = workspaceId;

            LwssoAuthenticationStrategy lwssoAuthenticationStrategy;

            //WorkspaceContext workspaceContext;
            //SharedSpaceContext sharedSpaceContext;

            NetworkSettings.IgnoreServerCertificateValidation();
            NetworkSettings.EnableAllSecurityProtocols();

            ConnectionInfo connectionInfo;

            connectionInfo = new UserPassConnectionInfo(userName, password);
            lwssoAuthenticationStrategy = new LwssoAuthenticationStrategy(connectionInfo);
            RestConnector.Connect(host, lwssoAuthenticationStrategy);
            //workspaceContext = new WorkspaceContext(sharedSpaceId, workspaceId);
            //sharedSpaceContext = new SharedSpaceContext(sharedSpaceId);
        }
        public static OctaneApis CreateOctaneConnection(ConnectionDetails connectionDetails)
        {
            Log.Debug($"Validate connection to Octane {connectionDetails.Host} and sharedspace {connectionDetails.SharedSpace}");
            var start         = DateTime.Now;
            var restConnector = new RestConnector();

            //1.validate connectivity
            try
            {
                restConnector.Connect(connectionDetails.Host, new APIKeyConnectionInfo(connectionDetails.ClientId, connectionDetails.ClientSecret));
            }
            catch (Exception ex)
            {
                var    innerException = ExceptionHelper.GetMostInnerException(ex);
                string msg;

                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (innerException.Message.Contains("401"))
                {
                    msg = $"Connection to ALM Octane not authorized, please check ALM Octane client id and secret!";
                }
                else if (innerException.Message.Contains("No connection could be made because the target machine actively refused it"))
                {
                    msg = $"ALM Octane server ({connectionDetails.Host}) could not be reached! Please check ALM Octane is availble on specified port.";
                }
                else if (innerException.Message.Contains("The handshake failed due to an unexpected packet format."))
                {
                    if (connectionDetails.Host.Contains("https"))
                    {
                        msg =
                            $"ALM Octane server ({connectionDetails.Host}) could not be reached! Please check if server supports https connection";
                    }
                    else
                    {
                        msg =
                            $"ALM Octane server ({connectionDetails.Host}) could not be reached (seems like a http/https problem) ! Please check connection url and port";
                    }
                }
                else
                {
                    msg =
                        $"ALM Octane server ({connectionDetails.Host}) could not be reached\n please check ALM Octane location Url\\IP and proxy settings";
                }

                Log.Error(msg, innerException);

                throw new Exception(msg, innerException);
            }

            //2.validate sharedspace exist
            try
            {
                var workspacesUrl = $"/api/shared_spaces/{connectionDetails.SharedSpace}/workspaces?limit=1";
                restConnector.ExecuteGet(workspacesUrl, null);
            }
            catch (Exception ex)
            {
                var msg = $"Could not connect to ALM Octane : sharedspace {connectionDetails.SharedSpace} does not exist";
                Log.Error(msg, ex);
                throw new Exception(msg);
            }

            //validate authorization
            try
            {
                string request = $"/internal-api/shared_spaces/{connectionDetails.SharedSpace}/analytics/ci/servers/connectivity/status";
                restConnector.ExecuteGet(request, null);
            }
            catch (Exception ex)
            {
                if (ex.InnerException is MqmRestException restEx && restEx.StatusCode == HttpStatusCode.Forbidden)
                {
                    const string msg = "Could not connect to ALM Octane : Provided credentials are not sufficient for requested resource";
                    Log.Error(msg);
                    throw new Exception(msg);
                }