/// <summary>
        /// Creates a new test case under the specified automation provider.
        /// </summary>
        /// <param name="testCase">Rhino.Api.Contracts.AutomationProvider.RhinoTestCase by which to create automation provider test case.</param>
        /// <returns>The ID of the newly created entity.</returns>
        public override string CreateTestCase(RhinoTestCase testCase)
        {
            // shortcuts
            var onProject = Configuration.ConnectorConfiguration.Project;

            testCase.Context[ContextEntry.Configuration] = Configuration;
            var testType = $"{testCase.GetCapability(AtlassianCapabilities.TestType, "Test")}";

            // setup context
            testCase.Context["issuetype-id"]                   = $"{jiraClient.GetIssueTypeFields(idOrKey: testType, path: "id")}";
            testCase.Context["project-key"]                    = onProject;
            testCase.Context["test-sets-custom-field"]         = jiraClient.GetCustomField(schema: TestSetSchema);
            testCase.Context["manual-test-steps-custom-field"] = jiraClient.GetCustomField(schema: ManualTestStepSchema);
            testCase.Context["test-plan-custom-field"]         = jiraClient.GetCustomField(schema: AssociatedPlanSchema);

            // setup request body
            var requestBody = testCase.ToJiraXrayIssue();
            var issue       = jiraClient.Create(requestBody);

            // comment
            var comment = Utilities.GetActionSignature(action: "created");

            jiraClient.AddComment(idOrKey: $"{issue.SelectToken("key")}", comment);

            // success
            Logger?.InfoFormat($"Create-Test -Project [{onProject}] -Set [{string.Join(",", testCase?.TestSuites)}] = true");

            // results
            return($"{issue}");
        }
        /// <summary>
        ///     Create the JiraApi, using OAuth 1 for the communication, here the HttpClient is configured
        /// </summary>
        /// <param name="baseUri">Base URL, e.g. https://yourjiraserver</param>
        /// <param name="jiraOAuthSettings">JiraOAuthSettings</param>
        /// <param name="httpSettings">IHttpSettings or null for default</param>
        public static IJiraClient Create(Uri baseUri, JiraOAuthSettings jiraOAuthSettings, IHttpSettings httpSettings = null)
        {
            JiraClient client       = JiraClient.Create(baseUri, httpSettings) as JiraClient;
            var        jiraOAuthUri = client.JiraBaseUri.AppendSegments("plugins", "servlet", "oauth");

            var oAuthSettings = new OAuth1Settings
            {
                TokenUrl          = jiraOAuthUri.AppendSegments("request-token"),
                TokenMethod       = HttpMethod.Post,
                AccessTokenUrl    = jiraOAuthUri.AppendSegments("access-token"),
                AccessTokenMethod = HttpMethod.Post,
                CheckVerifier     = false,
                SignatureType     = OAuth1SignatureTypes.RsaSha1,
                Token             = jiraOAuthSettings.Token,
                ClientId          = jiraOAuthSettings.ConsumerKey,
                CloudServiceName  = jiraOAuthSettings.CloudServiceName,
                RsaSha1Provider   = jiraOAuthSettings.RsaSha1Provider,
                AuthorizeMode     = jiraOAuthSettings.AuthorizeMode,
                AuthorizationUri  = jiraOAuthUri.AppendSegments("authorize")
                                    .ExtendQuery(new Dictionary <string, string>
                {
                    {
                        OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}"
                    },
                    {
                        OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}"
                    }
                })
            };

            // Configure the OAuth1Settings

            client.Behaviour = client.ConfigureBehaviour(OAuth1HttpBehaviourFactory.Create(oAuthSettings), httpSettings);
            return(client);
        }
Beispiel #3
0
        public async Task Test_SearchSnippet()
        {
            // begin-snippet: SearchExample
            var client = JiraClient.Create(TestJiraUri);
            // Preferably use a "bot" user for maintenance
            var username = Environment.GetEnvironmentVariable("jira_test_username");
            var password = Environment.GetEnvironmentVariable("jira_test_password");

            client.SetBasicAuthentication(username, password);

            const string unavailableUser = "******";
            // Find all issues in a certain state and assigned to a user who is not available
            var searchResult = await client.Issue.SearchAsync(Where.And(Where.Assignee.Is(unavailableUser), Where.Status.Is("Building")));

            foreach (var issue in searchResult.Issues)
            {
                // Remote the assignment, to make clear no-one is working on it
                await issue.AssignAsync(User.Nobody);

                // Comment the reason to the issue
                await issue.AddCommentAsync($"{unavailableUser} is currently not available.");
            }

            // end-snippet
        }
Beispiel #4
0
 public JiraConnector(IJiraConfiguration jiraConfiguration, JiraMonitor jiraMonitor)
 {
     jiraConfiguration.Url = jiraConfiguration.Url.Replace(DefaultPostfix, "");
     _jiraConfiguration    = jiraConfiguration;
     _jiraMonitor          = jiraMonitor;
     _jiraClient           = JiraClient.Create(new Uri(jiraConfiguration.Url));
 }
Beispiel #5
0
        public async Task StartupAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            Log.Debug().WriteLine("StartAsync called!");
            var serverInfo = await JiraClient.Create(new Uri("https://greenshot.atlassian.net")).Server.GetInfoAsync(cancellationToken).ConfigureAwait(false);

            Log.Debug().WriteLine("Jira server version {0}", serverInfo.Version);
            await Task.Delay(100, cancellationToken).ConfigureAwait(false);
        }
Beispiel #6
0
 /// <summary>
 ///     Override the BeginProcessingAsync to connect to our jira
 /// </summary>
 protected override Task BeginProcessingAsync()
 {
     JiraApi = JiraClient.Create(JiraUri);
     if (Username != null)
     {
         JiraApi.SetBasicAuthentication(Username, Password);
     }
     return(Task.FromResult(true));
 }
Beispiel #7
0
        /// <summary>
        /// Creates a bug based on this RhinoTestCase.
        /// </summary>
        /// <param name="testCase">RhinoTestCase by which to create a bug.</param>
        /// <returns>Bug creation results from Jira.</returns>
        public static JToken CreateBug(this RhinoTestCase testCase, JiraClient jiraClient)
        {
            // setup
            var issueBody = testCase.BugMarkdown(jiraClient);

            // post
            var response = jiraClient.Create(issueBody);

            if (response == default)
            {
                return(default);
Beispiel #8
0
 public JiraConnector(
     IJiraConfiguration jiraConfiguration,
     JiraMonitor jiraMonitor,
     ICoreConfiguration coreConfiguration,
     INetworkConfiguration networkConfiguration)
 {
     jiraConfiguration.Url = jiraConfiguration.Url.Replace(DefaultPostfix, "");
     _jiraConfiguration    = jiraConfiguration;
     _jiraMonitor          = jiraMonitor;
     _coreConfiguration    = coreConfiguration;
     _jiraClient           = JiraClient.Create(new Uri(jiraConfiguration.Url), networkConfiguration);
 }
Beispiel #9
0
        /// <summary>
        ///     Default test setup, can also take care of setting the authentication
        /// </summary>
        /// <param name="testOutputHelper"></param>
        /// <param name="doLogin"></param>
        protected TestBase(ITestOutputHelper testOutputHelper, bool doLogin = true)
        {
            // For tests, make sure we get everything
            DefaultJsonHttpContentConverter.Instance.Value.LogThreshold = 0;

            LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper);
            Client   = JiraClient.Create(TestJiraUri);
            Username = Environment.GetEnvironmentVariable("jira_test_username");
            Password = Environment.GetEnvironmentVariable("jira_test_password");

            if (doLogin && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
            {
                Client.SetBasicAuthentication(Username, Password);
            }
        }
        private JToken CreateTestOnJira(RhinoTestCase testCase)
        {
            // shortcuts
            var onProject = Configuration.ConnectorConfiguration.Project;
            var testType  = $"{capabilities[AtlassianCapabilities.TestType]}";

            // setup context
            testCase.Context["issuetype-id"] = $"{jiraClient.GetIssueTypeFields(idOrKey: testType, path: "id")}";
            testCase.Context["project-key"]  = onProject;

            // setup request body
            var issue = jiraClient.Create(testCase.ToJiraCreateRequest()).AsJObject();

            if (issue == default || !issue.ContainsKey("id"))
            {
                logger?.Fatal("Was not able to create a test case.");
                return(default);
Beispiel #11
0
        /// <summary>
        ///     Default test setup, can also take care of setting the authentication
        /// </summary>
        /// <param name="testOutputHelper"></param>
        /// <param name="doLogin"></param>
        protected TestBase(ITestOutputHelper testOutputHelper, bool doLogin = true)
        {
            var defaultJsonHttpContentConverterConfiguration = new DefaultJsonHttpContentConverterConfiguration
            {
                LogThreshold = 0
            };

            HttpBehaviour.Current.SetConfig(defaultJsonHttpContentConverterConfiguration);

            LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper);
            Client   = JiraClient.Create(TestJiraUri);
            Username = Environment.GetEnvironmentVariable("jira_test_username");
            Password = Environment.GetEnvironmentVariable("jira_test_password");

            if (doLogin && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
            {
                Client.SetBasicAuthentication(Username, Password);
            }
        }
Beispiel #12
0
        public OAuthTests(ITestOutputHelper testOutputHelper)
        {
            // A demo Private key, to create a RSACryptoServiceProvider.
            // This was created from a .pem via a tool here http://www.jensign.com/opensslkey/index.html
            const string privateKeyXml = @"<RSAKeyValue><Modulus>tGIwsCH2KKa6vxUDupW92rF68S5SRbgr7Yp0xeadBsb0BruTt4GMrVL7QtiZWM8qUkY1ccMa7LkXD93uuNUnQEsH65s8ryID9P
DeEtCBcxFEZFdcKfyKR+5B+NRLW5lJq10sHzWbJ0EROUmEjoYfi3CtsMkJHYHDL9dZeCqAZHM=</Modulus><Exponent>AQAB</Exponent><P>14DdDg26
CrLhAFQIQLT1KrKVPYr0Wusi2ovZApz2/RnM7a7CWUJuDR3ClW5g9hdi+KQ0ceD5oJYX5Vexv2uk+w==</P><Q>1kfU0+DkXc6I/jXHJ6pDLA5s7dBHzWgDs
BzplSdkVQbKT3MbeYjeByOxzXhulOWLBQW/vxmW4HwU95KTRlj06Q==</Q><DP>SPoBYY3yb0cN/J94P/lHgJMDCNkyUEuJ/PoYndLrrN/8zow8kh91xwlJ6
HJ9cTiQMmTgwaOOxPuu0eI1df4M2w==</DP><DQ>klJaspRPXP877NssM5nAZMU0/O/NGCZ+3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT89
8jusgQ==</DQ><InverseQ>d5Zrr6Q8AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54Lw03eHTNQghS0A==</Inverse
Q><D>WFlbZXlM2r5G6z48tE+RTKLvB1/btgAtq8vLw/5e3KnnbcDD6fZO07m4DRaPjRryrJdsp8qazmUdcY0O1oK4FQfpprknDjP+R1XHhbhkQ4WEwjmxPst
ZMUZaDWF58d3otc23mCzwh3YcUWFu09KnMpzZsK59OfyjtkS44EDWpbE=</D></RSAKeyValue>";

            // Create the RSACryptoServiceProvider for the XML above
            var rsaCryptoServiceProvider = new RSACryptoServiceProvider();

            rsaCryptoServiceProvider.FromXmlString(privateKeyXml);

            // Configure the XUnitLogger for logging
            LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper);

            // Only a few settings for the Jira OAuth are important
            var oAuthSettings = new JiraOAuthSettings
            {
                // Is specified on the linked-applications as consumer key
                ConsumerKey = "lInXLgx6HbF9FFq1ZQN8iSEnhzO3JVuf",
                // This needs to have the private key, the represented public key is set in the linked-applications
                RsaSha1Provider = rsaCryptoServiceProvider,
                // Use a server at Localhost to redirect to, alternative an embedded browser can be used
                AuthorizeMode = AuthorizeModes.LocalhostServer,
                // When using the embbed browser this is directly visible, with the LocalhostServer it's in the info notice after a redirect
                CloudServiceName = "Greenshot Jira",
                // the IOAuth1Token implementation, here it's this, gets the tokens to store & retrieve for later
                Token = this
            };

            // Create the JiraApi for the Uri and the settings
            _jiraApi = JiraClient.Create(TestJiraUri, oAuthSettings);
        }
Beispiel #13
0
        /// <summary>
        /// Internal login which catches the exceptions
        /// </summary>
        /// <returns>true if login was done sucessfully</returns>
        private async Task <bool> DoLoginAsync(string user, string password, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
            {
                return(false);
            }
            _jiraClient = JiraClient.Create(new Uri(JiraConfig.Url));
            _jiraClient.Behaviour.SetConfig(new SvgConfiguration {
                Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height
            });

            _issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraClient);
            LoginInfo loginInfo;

            try
            {
                loginInfo = await _jiraClient.Session.StartAsync(user, password, cancellationToken);

                Monitor = new JiraMonitor();
                await Monitor.AddJiraInstanceAsync(_jiraClient, cancellationToken);

                var favIconUri = _jiraClient.JiraBaseUri.AppendSegments("favicon.ico");
                try
                {
                    FavIcon = await _jiraClient.Server.GetUriContentAsync <Bitmap>(favIconUri, cancellationToken);
                }
                catch (Exception ex)
                {
                    Log.WarnFormat("Couldn't load favicon from {0}", favIconUri);
                    Log.Warn("Exception details: ", ex);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(loginInfo != null);
        }
Beispiel #14
0
 public void TestConstructor()
 {
     Assert.Throws <ArgumentNullException>(() => JiraClient.Create(null));
 }
Beispiel #15
0
        private JiraClient CreateClient()
        {
            var client = JiraClient.Create(this.BaseUrl, this.UserName, this.Password, this, this.ApiType);

            return(client);
        }
Beispiel #16
0
 public bool Connect(Credential credentials)
 {
     client = JiraClient.Create(new Uri(credentials.Uri));
     client.SetBasicAuthentication(credentials.Username, credentials.Password);
     return(true);
 }