public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs
@ 2020-02-26 16:35 Konrad Kleine
  2020-02-26 16:56 ` Konrad Kleine
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Kleine @ 2020-02-26 16:35 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

[-- Attachment #2: 0001-debuginfod-file-URLs-handle-curl-resp.-code.patch --]
[-- Type: text/x-patch, Size: 4299 bytes --]

From 91e942e3ac844487839653d470de2efb58255977 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine@redhat.com>
Date: Wed, 26 Feb 2020 10:00:43 -0500
Subject: [PATCH] debuginfod: file:// URLs: handle curl resp. code

When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

Signed-off-by: Konrad Kleine <kkleine@redhat.com>
---
 debuginfod/debuginfod-client.c | 36 ++++++++++++++++++++++------------
 tests/run-debuginfod-find.sh   | 18 ++++++++++++++++-
 2 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 186aa90a..4ab54593 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -716,20 +716,30 @@ debuginfod_query_server (debuginfod_client *c,
           else
             {
               /* Query completed without an error. Confirm that the
-                 response code is 200 and set verified_handle.  */
-              long resp_code = 500;
-              CURLcode curl_res;
-
-              curl_res = curl_easy_getinfo(target_handle,
-                                           CURLINFO_RESPONSE_CODE,
-                                           &resp_code);
-
-              if (curl_res == CURLE_OK
-                  && resp_code == 200
-                  && msg->easy_handle != NULL)
+                 response code is 200 when using HTTP/HTTPS and 0 when using 
+                 file:// and set verified_handle.  */
+              
+              if (msg->easy_handle != NULL)
                 {
-                  verified_handle = msg->easy_handle;
-                  break;
+                  char *effective_url = NULL;
+                  long resp_code = 500;
+                  CURLcode ok1 = curl_easy_getinfo(target_handle, CURLINFO_EFFECTIVE_URL, &effective_url);
+                  CURLcode ok2 = curl_easy_getinfo(target_handle, CURLINFO_RESPONSE_CODE, &resp_code);
+                  if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
+                    {
+                      if (strncmp(effective_url, "http", 4) == 0)
+                        if(resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                      if (strncmp(effective_url, "file", 4) == 0)
+                        if(resp_code == 0)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
                 }
             }
         }
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 2964e7c0..0facc555 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -40,7 +40,7 @@ cleanup()
   if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
   if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
 
-  rm -rf F R D L Z ${PWD}/.client_cache*
+  rm -rf F R D L Z ${PWD}/mocktree ${PWD}/.client_cache*
   exit_cleanup
 }
 
@@ -396,4 +396,20 @@ kill -int $PID3
 wait $PID3
 PID3=0
 
+########################################################################
+# Test fetching a file using file:// . No debuginfod server needs to be run for
+# this test.
+local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
+mkdir -p ${local_dir}
+echo "int main() { return 0; }" > ${local_dir}/main.c
+
+# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+DEBUGINFOD_URLS=""
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
+
+# Now test is with proper DEBUGINFOD_URLS
+DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
+cmp $filename ${local_dir}/main.c
+
 exit 0
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs
  2020-02-26 16:35 [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs Konrad Kleine
@ 2020-02-26 16:56 ` Konrad Kleine
  2020-02-26 17:09   ` Konrad Kleine
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Kleine @ 2020-02-26 16:56 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 529 bytes --]

Addec Changelog entry

On Wed, 26 Feb 2020 at 17:35, Konrad Kleine <kkleine@redhat.com> wrote:
>
> When file:// is used for DEBUGINFOD_URLS, then the response code for a
> successful server query is 0 and not 200.
>
> Using file:// can be helpful when you want to test your
> debuginfod-client integration against a mocked file tree that mimics the
> HTTP URLs from the debuginfod server. This way you don't have to run the
> debuginfod server at all.
>
> Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

[-- Attachment #2: 0001-debuginfod-file-URLs-handle-curl-resp.-code.patch --]
[-- Type: text/x-patch, Size: 4837 bytes --]

From e45a528809abfd9248d66a5e054d2e9f338b4038 Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine@redhat.com>
Date: Wed, 26 Feb 2020 10:00:43 -0500
Subject: [PATCH] debuginfod: file:// URLs: handle curl resp. code

When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

Signed-off-by: Konrad Kleine <kkleine@redhat.com>
---
 ChangeLog                      |  8 ++++++++
 debuginfod/debuginfod-client.c | 36 ++++++++++++++++++++++------------
 tests/run-debuginfod-find.sh   | 18 ++++++++++++++++-
 3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 96d61403..4260dd72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-26  Konrad Kleine <kkleine@redhat.com>
+
+	* debuginfod/debuginfod-client.c: handle curl's response code correctly when
+	DEBUGINFOD_URLS begin with file://
+
+	* tests/run-debuginfod-find.sh: added tests for DEBUGINFOD_URLS beginning
+	with "file://"
+
 2020-02-03  Frank Ch. Eigler  <fche@redhat.com>
 
 	* configure.ac: Tolerate CXX= for debuginfod configuration.
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 186aa90a..4ab54593 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -716,20 +716,30 @@ debuginfod_query_server (debuginfod_client *c,
           else
             {
               /* Query completed without an error. Confirm that the
-                 response code is 200 and set verified_handle.  */
-              long resp_code = 500;
-              CURLcode curl_res;
-
-              curl_res = curl_easy_getinfo(target_handle,
-                                           CURLINFO_RESPONSE_CODE,
-                                           &resp_code);
-
-              if (curl_res == CURLE_OK
-                  && resp_code == 200
-                  && msg->easy_handle != NULL)
+                 response code is 200 when using HTTP/HTTPS and 0 when using 
+                 file:// and set verified_handle.  */
+              
+              if (msg->easy_handle != NULL)
                 {
-                  verified_handle = msg->easy_handle;
-                  break;
+                  char *effective_url = NULL;
+                  long resp_code = 500;
+                  CURLcode ok1 = curl_easy_getinfo(target_handle, CURLINFO_EFFECTIVE_URL, &effective_url);
+                  CURLcode ok2 = curl_easy_getinfo(target_handle, CURLINFO_RESPONSE_CODE, &resp_code);
+                  if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
+                    {
+                      if (strncmp(effective_url, "http", 4) == 0)
+                        if(resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                      if (strncmp(effective_url, "file", 4) == 0)
+                        if(resp_code == 0)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
                 }
             }
         }
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 2964e7c0..0facc555 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -40,7 +40,7 @@ cleanup()
   if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
   if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
 
-  rm -rf F R D L Z ${PWD}/.client_cache*
+  rm -rf F R D L Z ${PWD}/mocktree ${PWD}/.client_cache*
   exit_cleanup
 }
 
@@ -396,4 +396,20 @@ kill -int $PID3
 wait $PID3
 PID3=0
 
+########################################################################
+# Test fetching a file using file:// . No debuginfod server needs to be run for
+# this test.
+local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
+mkdir -p ${local_dir}
+echo "int main() { return 0; }" > ${local_dir}/main.c
+
+# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+DEBUGINFOD_URLS=""
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
+
+# Now test is with proper DEBUGINFOD_URLS
+DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
+cmp $filename ${local_dir}/main.c
+
 exit 0
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs
  2020-02-26 16:56 ` Konrad Kleine
@ 2020-02-26 17:09   ` Konrad Kleine
  2020-02-26 20:14     ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Kleine @ 2020-02-26 17:09 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 64 bytes --]

Modify changelog per directory and not in top-level directory.

[-- Attachment #2: 0001-debuginfod-file-URLs-handle-curl-resp.-code.patch --]
[-- Type: text/x-patch, Size: 5204 bytes --]

From ba36d7fc0aea4656ec8c2577306fec4c01c9a02d Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine@redhat.com>
Date: Wed, 26 Feb 2020 10:00:43 -0500
Subject: [PATCH] debuginfod: file:// URLs: handle curl resp. code

When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

Signed-off-by: Konrad Kleine <kkleine@redhat.com>
---
 debuginfod/ChangeLog           |  5 +++++
 debuginfod/debuginfod-client.c | 36 ++++++++++++++++++++++------------
 tests/ChangeLog                |  5 +++++
 tests/run-debuginfod-find.sh   | 18 ++++++++++++++++-
 4 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 16e14309..42f30f00 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-26  Konrad Kleine <kkleine@redhat.com>
+
+	* debuginfod-client.c: handle curl's response code correctly when
+	DEBUGINFOD_URLS begin with file://
+
 2020-02-25  Frank Ch. Eigler  <fche@redhat.com>
 
 	* debuginfod.cxx (parse_opt): Treat -R as if -Z.rpm .
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 186aa90a..4ab54593 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -716,20 +716,30 @@ debuginfod_query_server (debuginfod_client *c,
           else
             {
               /* Query completed without an error. Confirm that the
-                 response code is 200 and set verified_handle.  */
-              long resp_code = 500;
-              CURLcode curl_res;
-
-              curl_res = curl_easy_getinfo(target_handle,
-                                           CURLINFO_RESPONSE_CODE,
-                                           &resp_code);
-
-              if (curl_res == CURLE_OK
-                  && resp_code == 200
-                  && msg->easy_handle != NULL)
+                 response code is 200 when using HTTP/HTTPS and 0 when using 
+                 file:// and set verified_handle.  */
+              
+              if (msg->easy_handle != NULL)
                 {
-                  verified_handle = msg->easy_handle;
-                  break;
+                  char *effective_url = NULL;
+                  long resp_code = 500;
+                  CURLcode ok1 = curl_easy_getinfo(target_handle, CURLINFO_EFFECTIVE_URL, &effective_url);
+                  CURLcode ok2 = curl_easy_getinfo(target_handle, CURLINFO_RESPONSE_CODE, &resp_code);
+                  if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
+                    {
+                      if (strncmp(effective_url, "http", 4) == 0)
+                        if(resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                      if (strncmp(effective_url, "file", 4) == 0)
+                        if(resp_code == 0)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
                 }
             }
         }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 32ca1ce0..98e5c954 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-26  Konrad Kleine <kkleine@redhat.com>
+
+	* run-debuginfod-find.sh: added tests for DEBUGINFOD_URLS beginning
+	with "file://"
+
 2020-02-21  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (TESTS_ENVIRONMENT): Explicitly unset DEBUGINFOD_URLS.
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 2964e7c0..0facc555 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -40,7 +40,7 @@ cleanup()
   if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
   if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
 
-  rm -rf F R D L Z ${PWD}/.client_cache*
+  rm -rf F R D L Z ${PWD}/mocktree ${PWD}/.client_cache*
   exit_cleanup
 }
 
@@ -396,4 +396,20 @@ kill -int $PID3
 wait $PID3
 PID3=0
 
+########################################################################
+# Test fetching a file using file:// . No debuginfod server needs to be run for
+# this test.
+local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
+mkdir -p ${local_dir}
+echo "int main() { return 0; }" > ${local_dir}/main.c
+
+# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+DEBUGINFOD_URLS=""
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
+
+# Now test is with proper DEBUGINFOD_URLS
+DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
+cmp $filename ${local_dir}/main.c
+
 exit 0
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs
  2020-02-26 17:09   ` Konrad Kleine
@ 2020-02-26 20:14     ` Mark Wielaard
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Wielaard @ 2020-02-26 20:14 UTC (permalink / raw)
  To: Konrad Kleine; +Cc: elfutils-devel

Hi Konrad,

On Wed, Feb 26, 2020 at 06:08:39PM +0100, Konrad Kleine wrote:
> Subject: [PATCH] debuginfod: file:// URLs: handle curl resp. code
> 
> When file:// is used for DEBUGINFOD_URLS, then the response code for a
> successful server query is 0 and not 200.
> 
> Using file:// can be helpful when you want to test your
> debuginfod-client integration against a mocked file tree that mimics the
> HTTP URLs from the debuginfod server. This way you don't have to run the
> debuginfod server at all.
> 
> Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

Perfect patch, nice testcase. Thanks for the ChangeLog entries.  I did
tweak a few whitespace issues, but the file itself wasn't really
consistent to begin with.

Pushed to master.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-26 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 16:35 [PATCH] Bug 25600 - debuginfo-client should handle file:// URLs Konrad Kleine
2020-02-26 16:56 ` Konrad Kleine
2020-02-26 17:09   ` Konrad Kleine
2020-02-26 20:14     ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).