Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add LRO_USERNAME and LRO_PASSWORD options #316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SET(LIBREPO_MAJOR "1")
SET(LIBREPO_MINOR "17")
SET(LIBREPO_PATCH "2")
SET(LIBREPO_MINOR "18")
SET(LIBREPO_PATCH "0")
2 changes: 1 addition & 1 deletion librepo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions librepo/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 15 additions & 4 deletions librepo/handle.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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" */
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, this was the behavior already, but good that it's more clearly documented now.

contains, for example, a colon, it should be encoded as %3A.*/

LRO_PROGRESSCB, /*!< (LrProgressCb)
Progress callback */
Expand Down Expand Up @@ -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 */
Expand Down
21 changes: 21 additions & 0 deletions librepo/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions librepo/python/handle-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions librepo/python/librepomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/python/tests/test_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion tests/python/tests/test_yum_repo_downloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Loading