コード例 #1
0
 def test_get_credentials_empty_configuration(self):
     test_obj = JenkinsConfigParser()
     sample_config=StringIO("")
     test_obj.readfp(sample_config)
     
     self.assertEqual(test_obj.get_credentials("http://localhost:8080"), None, 
                      "Empty config files should provide empty credentials")
コード例 #2
0
    def easy_connect(url, credentials=None, ssl_verify=False):
        """Factory method to simplify creating connections to Jenkins servers

        :param str url:
            Full URL of the Jenkins instance to connect to. Must be
            a valid running Jenkins instance.
        :param tuple credentials:
            A 2-element tuple with the username and password for authenticating to the URL
            If omitted, credentials will be loaded from any pyjen config files found on the system
            If no credentials can be found, anonymous access will be used
        :param bool ssl_verify:
            Indicates whether the SSL certificate of the Jenkins instance should be checked upon connection.
            For Jenkins instances hosted behind HTTPS using self-signed certificates this may cause connection
            errors when enabled. Defaults to disabled (False)
        :returns:
            Jenkins object, pre-configured with the appropriate credentials and connection parameters for the given URL.
        :rtype: :class:`.Jenkins`
        """
        # If no explicit credentials provided, load credentials from any config files
        if credentials is None:
            config = JenkinsConfigParser()
            config.read(JenkinsConfigParser.get_default_configfiles())
            credentials = config.get_credentials(url)

        http_io = DataRequester(url, ssl_verify)
        http_io.credentials = credentials
        retval = Jenkins(http_io)
        return retval
コード例 #3
0
 def test_empty_section(self):
     test_url = "http://localhost:8080"
     sample_config=StringIO("[http://localhost:8080]")
     test_obj = JenkinsConfigParser()
     test_obj.readfp(sample_config)
     
     self.assertEqual(test_obj.get_credentials(test_url), None, 
                      "Undefined credentials should be reported as empty")
コード例 #4
0
 def test_get_credentials_no_password(self):
     test_url = "http://localhost:8080"
     
     sample_config=StringIO("[http://localhost:8080]\n" +
     "username=jdoe\n")
     test_obj = JenkinsConfigParser()
     test_obj.readfp(sample_config)
     
     self.assertRaises(InvalidUserParamsError, test_obj.get_credentials, test_url)
コード例 #5
0
 def test_get_credentials_anonymous(self):
     test_url = "http://localhost:8080"
     sample_config=StringIO("[http://localhost:8080]\n" +
     "username=\n" +
     "password=\n")
     test_obj = JenkinsConfigParser()
     test_obj.readfp(sample_config)
     
     self.assertEqual(test_obj.get_credentials(test_url), None, 
                      "Config explicitly declares empty username and password which should \
                      be reported as empty credentials")
コード例 #6
0
 def test_get_credentials(self):
     test_url = "http://localhost:8080"
     expected_username = "******"
     expected_password = "******"
             
     sample_config=StringIO("[http://localhost:8080]\n" +
                            "username=jdoe\n" +
                            "password=Password123\n")
     test_obj = JenkinsConfigParser()
     test_obj.readfp(sample_config)
     
     actual_credentials = test_obj.get_credentials(test_url)
     self.assertEqual(actual_credentials[0], expected_username)
     self.assertEqual(actual_credentials[1], expected_password)
コード例 #7
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_get_credentials_empty_configuration():
    test_obj = JenkinsConfigParser()
    sample_config = StringIO("")
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials("http://localhost:8080") is None
コード例 #8
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_empty_section():
    test_url = "http://localhost:8080"
    sample_config = StringIO("[http://localhost:8080]")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials(test_url) is None
コード例 #9
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_get_credentials_no_username():
    test_url = "http://localhost:8080"

    sample_config = StringIO("""[http://localhost:8080]
password=Password123
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    with pytest.raises(InvalidUserParamsError):
        test_obj.get_credentials(test_url)
コード例 #10
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_get_credentials_anonymous():
    test_url = "http://localhost:8080"
    sample_config = StringIO("""[http://localhost:8080]
username=
password=
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials(test_url) is None
コード例 #11
0
 def test_get_default_configfiles(self):
     default_config_files = JenkinsConfigParser.get_default_configfiles()
     
     # Currently we look in 2 locations for config files
     self.assertEqual(len(default_config_files), 2)
     
     # The least privileged location should be the users home folder
     self.assertTrue(default_config_files[0].startswith(os.path.join(os.path.expanduser("~"))))
     
     # the next most privileged location is the local working folder
     self.assertTrue(default_config_files[1].startswith(os.getcwd()))
     
     # In any case, each path must point to the expected config file name
     if platform.system() == "Windows":
         expected_filename = "pyjen.cfg"
     else:
         expected_filename = ".pyjen"
     for filename in default_config_files:
         self.assertTrue(filename.endswith(expected_filename))
コード例 #12
0
ファイル: jenkins.py プロジェクト: tylerml/pyjen
    def __init__(self, url, credentials=None, ssl_cert=True):
        super(Jenkins, self).__init__()
        self._log = logging.getLogger(__name__)

        # If no explicit credentials provided,
        # load credentials from any config files
        if credentials is None:
            config = JenkinsConfigParser()
            config.read(JenkinsConfigParser.get_default_configfiles())
            creds = config.get_credentials(url)
        else:
            creds = credentials

        self._api = JenkinsAPI(url, creds, ssl_cert)
コード例 #13
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_get_credentials():
    test_url = "http://localhost:8080"
    expected_username = "******"
    expected_password = "******"

    sample_config = StringIO("""[http://localhost:8080]
username=jdoe
password=Password123
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    actual_credentials = test_obj.get_credentials(test_url)
    assert actual_credentials[0] == expected_username
    assert actual_credentials[1] == expected_password
コード例 #14
0
ファイル: test_user_params.py プロジェクト: tylerml/pyjen
def test_get_default_configfiles():
    default_config_files = JenkinsConfigParser.get_default_configfiles()

    # Currently we look in 2 locations for config files
    assert len(default_config_files) == 2

    # The least privileged location should be the users home folder
    assert default_config_files[0].startswith(
        os.path.join(os.path.expanduser("~")))

    # the next most privileged location is the local working folder
    assert default_config_files[1].startswith(os.getcwd())

    # In any case, each path must point to the expected config file name
    if platform.system() == "Windows":
        expected_filename = "pyjen.cfg"
    else:
        expected_filename = ".pyjen"
    for filename in default_config_files:
        assert filename.endswith(expected_filename)