Blame SOURCES/openscap-1.2.18-gzip-compression-PR1576.patch

f02bdd
diff --git a/configure.ac b/configure.ac
f02bdd
index 91fba1390..bbc525454 100644
f02bdd
--- a/configure.ac
f02bdd
+++ b/configure.ac
f02bdd
@@ -311,6 +311,21 @@ AC_SUBST([PTHREAD_LIBS])
f02bdd
 PKG_CHECK_MODULES([curl], [libcurl >= 7.12.0],[],
f02bdd
                           AC_MSG_FAILURE([libcurl devel support is missing]))
f02bdd
 
f02bdd
+AC_MSG_CHECKING([whether libcurl supports CURLOPT_ACCEPT_ENCODING and CURLOPT_TRANSFER_ENCODING])
f02bdd
+AC_COMPILE_IFELSE(
f02bdd
+	[AC_LANG_PROGRAM(
f02bdd
+		[[#include <curl/curl.h>
f02bdd
+		#include <curl/easy.h>]],
f02bdd
+		[[CURL *curl; curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, 0);]])],
f02bdd
+	[AC_DEFINE([HAVE_CURL_WITH_COMPRESSION], 1, [libcurl is new enough to have support for data compression])
f02bdd
+	AC_MSG_RESULT([yes])]
f02bdd
+	curl_accepts_encoding=yes,
f02bdd
+	[AC_MSG_RESULT([no])
f02bdd
+	AC_MSG_NOTICE([libcurl doesnt support any compression with CURLOPT_ACCEPT_ENCODING])
f02bdd
+	curl_accepts_encoding=no]
f02bdd
+)
f02bdd
+AM_CONDITIONAL([CURLOPT_ACCEPT_ENCODING], [test "$curl_accepts_encoding" = yes])
f02bdd
+
f02bdd
 PKG_CHECK_MODULES([xml2], [libxml-2.0 >= 2.0],[],
f02bdd
 			  AC_MSG_FAILURE([libxml-2.0 devel support is missing]))
f02bdd
 
f02bdd
@@ -1576,6 +1591,7 @@ AC_CONFIG_FILES([Makefile
f02bdd
 		tests/nist/Makefile
f02bdd
 		tests/offline_mode/Makefile
f02bdd
 
f02bdd
+		tests/curl/Makefile
f02bdd
                  src/SCE/Makefile
f02bdd
                  tests/sce/Makefile])
f02bdd
 
f02bdd
diff --git a/src/common/oscap_acquire.c b/src/common/oscap_acquire.c
f02bdd
index 70dbbea7c..997e69117 100644
f02bdd
--- a/src/common/oscap_acquire.c
f02bdd
+++ b/src/common/oscap_acquire.c
f02bdd
@@ -39,6 +39,7 @@
f02bdd
 #include "common/oscap_buffer.h"
f02bdd
 #include "common/_error.h"
f02bdd
 #include "oscap_string.h"
f02bdd
+#include "debug_priv.h"
f02bdd
 
f02bdd
 #ifndef OSCAP_TEMP_DIR
f02bdd
 #define OSCAP_TEMP_DIR "/tmp"
f02bdd
@@ -142,6 +143,34 @@ oscap_acquire_url_to_filename(const char *url)
f02bdd
 	return filename;
f02bdd
 }
f02bdd
 
f02bdd
+static int _curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp)
f02bdd
+{
f02bdd
+	const char *title;
f02bdd
+
f02bdd
+	switch (type) {
f02bdd
+	case CURLINFO_TEXT:
f02bdd
+		title = "== cURL info";
f02bdd
+		break;
f02bdd
+	case CURLINFO_HEADER_OUT:
f02bdd
+		title = "=> cURL header (out)";
f02bdd
+		break;
f02bdd
+	case CURLINFO_HEADER_IN:
f02bdd
+		title = "<= cURL header (in)";
f02bdd
+		break;
f02bdd
+	case CURLINFO_DATA_OUT:
f02bdd
+	case CURLINFO_SSL_DATA_OUT:
f02bdd
+	case CURLINFO_DATA_IN:
f02bdd
+	case CURLINFO_SSL_DATA_IN:
f02bdd
+	default:
f02bdd
+		return 0;
f02bdd
+		break;
f02bdd
+	}
f02bdd
+
f02bdd
+	dD("%s: %s", title, data);
f02bdd
+
f02bdd
+	return 0;
f02bdd
+}
f02bdd
+
f02bdd
 char* oscap_acquire_url_download(const char *url, size_t* memory_size)
f02bdd
 {
f02bdd
 	CURL *curl;
f02bdd
@@ -156,7 +185,13 @@ char* oscap_acquire_url_download(const char *url, size_t* memory_size)
f02bdd
 	curl_easy_setopt(curl, CURLOPT_URL, url);
f02bdd
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory_callback);
f02bdd
 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
f02bdd
+#ifdef HAVE_CURL_WITH_COMPRESSION
f02bdd
+	curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
f02bdd
+	curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, true);
f02bdd
+#endif
f02bdd
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
f02bdd
+	curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
f02bdd
+	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, _curl_trace);
f02bdd
 
f02bdd
 	CURLcode res = curl_easy_perform(curl);
f02bdd
 	curl_easy_cleanup(curl);
f02bdd
diff --git a/tests/Makefile.am b/tests/Makefile.am
f02bdd
index f15c45702..1d10cc7d7 100644
f02bdd
--- a/tests/Makefile.am
f02bdd
+++ b/tests/Makefile.am
f02bdd
@@ -22,6 +22,7 @@ SUBDIRS = \
f02bdd
 	bz2 \
f02bdd
 	codestyle \
f02bdd
 	CPE \
f02bdd
+	curl \
f02bdd
 	DS \
f02bdd
 	sources \
f02bdd
 	schemas \
f02bdd
diff --git a/tests/curl/Makefile.am b/tests/curl/Makefile.am
f02bdd
new file mode 100644
f02bdd
index 000000000..118c53ea1
f02bdd
--- /dev/null
f02bdd
+++ b/tests/curl/Makefile.am
f02bdd
@@ -0,0 +1,16 @@
f02bdd
+DISTCLEANFILES = *.log *.results oscap_debug.log.*
f02bdd
+CLEANFILES = *.log *.results oscap_debug.log.*
f02bdd
+
f02bdd
+TESTS_ENVIRONMENT = \
f02bdd
+		builddir=$(top_builddir) \
f02bdd
+		OSCAP_FULL_VALIDATION=1 \
f02bdd
+		$(top_builddir)/run
f02bdd
+
f02bdd
+TESTS =
f02bdd
+
f02bdd
+if CURLOPT_ACCEPT_ENCODING
f02bdd
+TESTS += test_curl_encoding.sh
f02bdd
+endif
f02bdd
+
f02bdd
+EXTRA_DIST =	test_curl_encoding.sh \
f02bdd
+		ds.xml
f02bdd
diff --git a/tests/curl/ds.xml b/tests/curl/ds.xml
f02bdd
new file mode 100644
f02bdd
index 000000000..f33cb475d
f02bdd
--- /dev/null
f02bdd
+++ b/tests/curl/ds.xml
f02bdd
@@ -0,0 +1,99 @@
f02bdd
+
f02bdd
+<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" id="scap_org.open-scap_collection_from_xccdf_test_single_rule.xccdf.xml" schematron-version="1.3">
f02bdd
+<ds:data-stream id="scap_org.open-scap_datastream_from_xccdf_test_single_rule.xccdf.xml" scap-version="1.3" use-case="OTHER">
f02bdd
+  <ds:checklists>
f02bdd
+    <ds:component-ref id="scap_org.open-scap_cref_test_single_rule.xccdf.xml" xlink:href="#scap_org.open-scap_comp_test_single_rule.xccdf.xml">
f02bdd
+      <cat:catalog>
f02bdd
+        <cat:uri name="test_single_rule.oval.xml" uri="#scap_org.open-scap_cref_test_single_rule.oval.xml"/>
f02bdd
+        <cat:uri name="security-data-oval.xml.bz2" uri="#scap_org.open-scap_cref_security-data-oval.xml.bz2"/>
f02bdd
+      </cat:catalog>
f02bdd
+    </ds:component-ref>
f02bdd
+  </ds:checklists>
f02bdd
+  <ds:checks>
f02bdd
+    <ds:component-ref id="scap_org.open-scap_cref_test_single_rule.oval.xml" xlink:href="#scap_org.open-scap_comp_test_single_rule.oval.xml"/>
f02bdd
+
f02bdd
+    <ds:component-ref id="scap_org.open-scap_cref_security-data-oval.xml.bz2" xlink:href="https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL7.xml"/>
f02bdd
+-->
f02bdd
+    <ds:component-ref id="scap_org.open-scap_cref_security-data-oval.xml.bz2" xlink:href="https://github.com/"/>
f02bdd
+  </ds:checks>
f02bdd
+</ds:data-stream>
f02bdd
+
f02bdd
+<ds:component id="scap_org.open-scap_comp_test_single_rule.oval.xml" timestamp="2017-06-09T07:07:38">
f02bdd
+<oval_definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:win-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd    http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd   http://oval.mitre.org/XMLSchema/oval-definitions-5#windows windows-definitions-schema.xsd">
f02bdd
+  <generator>
f02bdd
+    <oval:schema_version>5.11</oval:schema_version>
f02bdd
+    <oval:timestamp>2009-01-12T10:41:00-05:00</oval:timestamp>
f02bdd
+  </generator>
f02bdd
+
f02bdd
+  <definitions>
f02bdd
+    <definition class="compliance" id="oval:test-pass:def:1" version="1">
f02bdd
+      <metadata>
f02bdd
+        <title>PASS</title>
f02bdd
+        <description>pass</description>
f02bdd
+      </metadata>
f02bdd
+      <criteria>
f02bdd
+        <criterion comment="PASS test" test_ref="oval:x:tst:1"/>
f02bdd
+      </criteria>
f02bdd
+    </definition>
f02bdd
+  </definitions>
f02bdd
+
f02bdd
+    <tests>
f02bdd
+    <variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" check="all" comment="always pass" version="1">
f02bdd
+      <object object_ref="oval:x:obj:1"/>
f02bdd
+    </variable_test>
f02bdd
+    </tests>
f02bdd
+
f02bdd
+    <objects>
f02bdd
+    <variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
f02bdd
+      <var_ref>oval:x:var:1</var_ref>
f02bdd
+    </variable_object>
f02bdd
+    </objects>
f02bdd
+
f02bdd
+    <variables>
f02bdd
+      <constant_variable id="oval:x:var:1" version="1" comment="x" datatype="int">
f02bdd
+        <value>100</value>
f02bdd
+      </constant_variable>
f02bdd
+    </variables>
f02bdd
+
f02bdd
+</oval_definitions>
f02bdd
+</ds:component>
f02bdd
+
f02bdd
+<ds:component id="scap_org.open-scap_comp_test_single_rule.xccdf.xml" timestamp="2017-06-09T09:15:45">
f02bdd
+<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="xccdf_com.example.www_benchmark_dummy" xml:lang="en-US">
f02bdd
+  <status>accepted</status>
f02bdd
+  <version>1.0</version>
f02bdd
+
f02bdd
+  <Profile id="xccdf_com.example.www_profile_test_remote_res">
f02bdd
+    <title>xccdf_test_profile</title>
f02bdd
+    <description>This profile is for testing.</description>
f02bdd
+    <select idref="xccdf_com.example.www_rule_test-pass" selected="true"/>
f02bdd
+    <select idref="xccdf_com.example.www_rule_test-remote_res" selected="true"/>
f02bdd
+  </Profile>
f02bdd
+
f02bdd
+  <Value id="xccdf_com.example.www_value_val1" type="number" operator="equals" interactive="0">
f02bdd
+    <title>test value</title>
f02bdd
+    <description>foo</description>
f02bdd
+    <value selector="bar_1">50</value>
f02bdd
+    <value selector="bar_2">100</value>
f02bdd
+  </Value>
f02bdd
+  <Rule selected="true" id="xccdf_com.example.www_rule_test-pass">
f02bdd
+    <title>This rule always pass</title>
f02bdd
+    <check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
f02bdd
+      <check-content-ref href="test_single_rule.oval.xml" name="oval:test-pass:def:1"/>
f02bdd
+    </check>
f02bdd
+  </Rule>
f02bdd
+  <Rule selected="true" id="xccdf_com.example.www_rule_test-remote_res">
f02bdd
+    <title>This rule checks remote resource</title>
f02bdd
+    <check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" multi-check="true">
f02bdd
+      <check-content-ref href="security-data-oval.xml.bz2"/>
f02bdd
+    </check>
f02bdd
+  </Rule>
f02bdd
+  <Rule selected="true" id="xccdf_com.example.www_rule_test-pass2">
f02bdd
+    <title>This rule always pass</title>
f02bdd
+    <check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
f02bdd
+      <check-content-ref href="test_single_rule.oval.xml" name="oval:test-pass:def:1"/>
f02bdd
+    </check>
f02bdd
+  </Rule>
f02bdd
+</Benchmark>
f02bdd
+</ds:component>
f02bdd
+</ds:data-stream-collection>
f02bdd
diff --git a/tests/curl/test_curl_encoding.sh b/tests/curl/test_curl_encoding.sh
f02bdd
new file mode 100755
f02bdd
index 000000000..674abf691
f02bdd
--- /dev/null
f02bdd
+++ b/tests/curl/test_curl_encoding.sh
f02bdd
@@ -0,0 +1,23 @@
f02bdd
+#!/bin/bash
f02bdd
+
f02bdd
+set -e -o pipefail
f02bdd
+
f02bdd
+. $builddir/tests/test_common.sh
f02bdd
+
f02bdd
+function curl_accept_encoding {
f02bdd
+	local DF="${srcdir}/ds.xml"
f02bdd
+	local RF="results.xml"
f02bdd
+	local LOG="verbose.log"
f02bdd
+
f02bdd
+	$OSCAP xccdf eval --verbose=DEVEL --fetch-remote-resources --results $RF $DF 2>$LOG || echo "OK"
f02bdd
+
f02bdd
+	grep -P "Accept-Encoding.*gzip" $LOG
f02bdd
+
f02bdd
+	return 0
f02bdd
+}
f02bdd
+
f02bdd
+test_init
f02bdd
+
f02bdd
+test_run "cURL: Accept-Encoding" curl_accept_encoding
f02bdd
+
f02bdd
+test_exit