diff --git a/VERSION.cmake b/VERSION.cmake index 1c558669..8ebe8b0f 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -1,3 +1,3 @@ SET(LIBREPO_MAJOR "1") -SET(LIBREPO_MINOR "17") -SET(LIBREPO_PATCH "2") +SET(LIBREPO_MINOR "18") +SET(LIBREPO_PATCH "0") diff --git a/librepo.spec b/librepo.spec index 3a5757fe..25dc741c 100644 --- a/librepo.spec +++ b/librepo.spec @@ -28,7 +28,7 @@ %global dnf_conflict 2.8.8 Name: librepo -Version: 1.17.2 +Version: 1.18.0 Release: 1%{?dist} Summary: Repodata downloading library diff --git a/librepo/handle.c b/librepo/handle.c index 27fcbbbd..eec674dc 100644 --- a/librepo/handle.c +++ b/librepo/handle.c @@ -407,6 +407,14 @@ lr_handle_setopt(LrHandle *handle, c_rc = curl_easy_setopt(c_h, CURLOPT_USERPWD, va_arg(arg, char *)); break; + case LRO_USERNAME: + c_rc = curl_easy_setopt(c_h, CURLOPT_USERNAME, va_arg(arg, char *)); + break; + + case LRO_PASSWORD: + c_rc = curl_easy_setopt(c_h, CURLOPT_PASSWORD, va_arg(arg, char *)); + break; + case LRO_PROXY: c_rc = curl_easy_setopt(c_h, CURLOPT_PROXY, va_arg(arg, char *)); break; diff --git a/librepo/handle.h.in b/librepo/handle.h.in index b3c19007..eb242dde 100644 --- a/librepo/handle.h.in +++ b/librepo/handle.h.in @@ -148,12 +148,15 @@ typedef enum { Do not duplicate local metadata, just locate the old one */ LRO_HTTPAUTH, /*!< (long 1 or 0) - Enable all supported method of HTTP authentification. + Enable all supported method of HTTP authentication. This option is DEPRECATED! Use LRO_HTTPAUTHMETHODS */ LRO_USERPWD, /*!< (char *) - User and password for http authetification in format user:password */ + User and password for HTTP authentication in format user:password. + The user and password strings are not URL decoded, so there is no way to send in + a username containing a colon using this option. The option is DEPRECATED! + Use LRO_USERNAME and LRO_PASSWORD */ LRO_PROXY, /*!< (char *) Address of proxy server eg. "proxy-host.com:8080" */ @@ -165,12 +168,14 @@ typedef enum { Type of the proxy used. */ LRO_PROXYAUTH, /*!< (long 1 or 0) - Enable all supported method for proxy authentification. + Enable all supported method for proxy authentication. This option is DEPRECATED! Use LRO_PROXYAUTHMETHODS */ LRO_PROXYUSERPWD, /*!< (char *) - User and password for proxy in format user:password */ + User and password for proxy in format user:password + Both the username and the password are URL decoded before use, so if the username + contains, for example, a colon, it should be encoded as %3A.*/ LRO_PROGRESSCB, /*!< (LrProgressCb) Progress callback */ @@ -429,6 +434,12 @@ typedef enum { Path to a file containing the list of PEM format trusted CA certificates. Used for proxy. */ + LRO_USERNAME, /*!< (char *) + User for HTTP authentication */ + + LRO_PASSWORD, /*!< (char *) + Password for HTTP authentication */ + LRO_SENTINEL, /*!< Sentinel */ } LrHandleOption; /*!< Handle config options */ diff --git a/librepo/python/__init__.py b/librepo/python/__init__.py index 118b9349..a005e703 100644 --- a/librepo/python/__init__.py +++ b/librepo/python/__init__.py @@ -90,6 +90,17 @@ *String or None*. Set username and password for HTTP authentication. Param must be in format 'username:password'. + The user and password strings are not URL decoded, so there is no way to send in + a username containing a colon using this option. The option is DEPRECATED! + Use LRO_USERNAME and LRO_PASSWORD. + +.. data:: LRO_USERNAME + + *String or None*. Set username for HTTP authentication. + +.. data:: LRO_PASSWORD + + *String or None*. Set password for HTTP authentication. .. data:: LRO_PROXY @@ -116,6 +127,8 @@ *String or None*. Set username and password for proxy authentication in format 'username:password'. + Both the username and the password are URL decoded before use, so if the username + contains, for example, a colon, it should be encoded as %3A. .. data:: LRO_PROGRESSCB @@ -1259,6 +1272,14 @@ class Handle(_librepo.Handle): See: :data:`.LRO_USERPWD` + .. attribute:: username: + + See: :data:`.LRO_USERNAME` + + .. attribute:: password: + + See: :data:`.LRO_PASSWORD` + .. attribute:: proxy: See: :data:`.LRO_PROXY` diff --git a/librepo/python/handle-py.c b/librepo/python/handle-py.c index 32bf4e19..ccc1ef42 100644 --- a/librepo/python/handle-py.c +++ b/librepo/python/handle-py.c @@ -293,6 +293,8 @@ py_setopt(_HandleObject *self, PyObject *args) case LRO_MIRRORLISTURL: case LRO_METALINKURL: case LRO_USERPWD: + case LRO_USERNAME: + case LRO_PASSWORD: case LRO_PROXY: case LRO_PROXYUSERPWD: case LRO_DESTDIR: diff --git a/librepo/python/librepomodule.c b/librepo/python/librepomodule.c index 3908bbc2..b7b1b593 100644 --- a/librepo/python/librepomodule.c +++ b/librepo/python/librepomodule.c @@ -238,6 +238,8 @@ PyInit__librepo(void) PYMODULE_ADDINTCONSTANT(LRO_LOCAL); PYMODULE_ADDINTCONSTANT(LRO_HTTPAUTH); PYMODULE_ADDINTCONSTANT(LRO_USERPWD); + PYMODULE_ADDINTCONSTANT(LRO_USERNAME); + PYMODULE_ADDINTCONSTANT(LRO_PASSWORD); PYMODULE_ADDINTCONSTANT(LRO_PROXY); PYMODULE_ADDINTCONSTANT(LRO_PROXYPORT); PYMODULE_ADDINTCONSTANT(LRO_PROXYTYPE); diff --git a/tests/README.rst b/tests/README.rst index f7e6d032..49c8cfed 100644 --- a/tests/README.rst +++ b/tests/README.rst @@ -48,7 +48,7 @@ $ python python/tests/servermock/server.py Url examples ------------ http://127.0.0.1:5000/yum/auth_basic/static/01/repodata/repomd.xml - * This url provides basic authentification + * This url provides basic authentication http://127.0.0.1:5000/yum/badgpg/static/01/repodata/repomd.xml.asc * This url in fact returns .../repodata/repomd.xml.asc.bad file diff --git a/tests/python/tests/test_handle.py b/tests/python/tests/test_handle.py index b3c02320..36ae590d 100644 --- a/tests/python/tests/test_handle.py +++ b/tests/python/tests/test_handle.py @@ -509,6 +509,10 @@ def test_handle_setopt_none_value(self): h.httpauth = None h.setopt(librepo.LRO_USERPWD, None) h.userpwd = None + h.setopt(librepo.LRO_USERNAME, None) + h.username = None + h.setopt(librepo.LRO_PASSWORD, None) + h.password = None h.setopt(librepo.LRO_PROXY, None) h.proxy = None h.setopt(librepo.LRO_PROXYPORT, None) # None sets default value diff --git a/tests/python/tests/test_yum_repo_downloading.py b/tests/python/tests/test_yum_repo_downloading.py index 29c2c85c..9c7fdac7 100644 --- a/tests/python/tests/test_yum_repo_downloading.py +++ b/tests/python/tests/test_yum_repo_downloading.py @@ -1435,7 +1435,8 @@ def test_download_repo_01_from_base_auth_secured_web_01(self): h.checksum = True self.assertRaises(librepo.LibrepoException, h.perform, (r)) - def test_download_repo_01_from_base_auth_secured_web_02(self): + def test_download_repo_01_from_base_auth_secured_web_02_use_userpwd(self): + """ The test uses the deprecated `h.userpwd="username:password"`. """ h = librepo.Handle() r = librepo.Result() @@ -1454,6 +1455,27 @@ def test_download_repo_01_from_base_auth_secured_web_02(self): self.assertTrue(yum_repo) self.assertTrue(yum_repomd) + def test_download_repo_01_from_base_auth_secured_web_02(self): + """ The test uses `h.username="username" and `h.password="password"`. """ + h = librepo.Handle() + r = librepo.Result() + + url = "%s%s%s" % (self.MOCKURL, config.AUTHBASIC, config.REPO_YUM_01_PATH) + h.urls = [url] + h.repotype = librepo.LR_YUMREPO + h.destdir = self.tmpdir + h.checksum = True + h.httpauth = True + h.username = config.AUTH_USER + h.password = config.AUTH_PASS + h.perform(r) + + yum_repo = r.getinfo(librepo.LRR_YUM_REPO) + yum_repomd = r.getinfo(librepo.LRR_YUM_REPOMD) + + self.assertTrue(yum_repo) + self.assertTrue(yum_repomd) + # Progressbar test def test_download_repo_01_with_progressbar(self): diff --git a/tests/test_handle.c b/tests/test_handle.c index a80df4eb..180cf49a 100644 --- a/tests/test_handle.c +++ b/tests/test_handle.c @@ -38,6 +38,8 @@ START_TEST(test_handle) ck_assert(lr_handle_setopt(h, &tmp_err, LRO_MIRRORLIST, "bar")); ck_assert_ptr_null(tmp_err); ck_assert(lr_handle_setopt(h, NULL, LRO_USERPWD, "user:pwd")); + ck_assert(lr_handle_setopt(h, NULL, LRO_USERNAME, "user")); + ck_assert(lr_handle_setopt(h, NULL, LRO_PASSWORD, "pwd")); ck_assert(lr_handle_setopt(h, NULL, LRO_PROXY, "proxy")); ck_assert(lr_handle_setopt(h, NULL, LRO_PROXYUSERPWD, "proxyuser:pwd")); ck_assert(lr_handle_setopt(h, NULL, LRO_DESTDIR, "foodir"));