-
Notifications
You must be signed in to change notification settings - Fork 219
add support for using customized HTTP headers in download_file #3472
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
Changes from 11 commits
cec696c
6dc4d86
98d8d04
5e4427d
fd9b7e3
b939fc4
bd9ccaa
c6853f4
867aa48
43a3ddd
3dcce95
1d7ade4
3c21a16
5e80716
4410e04
3b7cfc4
3a4f487
a9476de
a5aa485
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2563,6 +2563,148 @@ def test_hide_toolchains(self): | |
| self.assertTrue(re.search(r'module: GCC/\.4\.9\.2', outtxt)) | ||
| self.assertTrue(re.search(r'module: gzip/1\.6-GCC-4\.9\.2', outtxt)) | ||
|
|
||
| def test_http_header_fields_urlpat(self): | ||
| """Test use of --http-header-fields-urlpat.""" | ||
| test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs') | ||
| ec_file = os.path.join(test_ecs_dir, 'g', 'gzip', 'gzip-1.6-GCC-4.9.2.eb') | ||
| common_args = [ | ||
| ec_file, | ||
| '--stop=fetch', | ||
| '--debug', | ||
| '--force', | ||
| '--force-download', | ||
| '--logtostdout', | ||
| ] | ||
|
|
||
| # define header fields:values that should (not) show up in the logs, either | ||
| # because they are secret or because they are not matched for the url | ||
| testdohdr = 'HeaderAPPLIED' | ||
| testdoval = 'SECRETvalue' | ||
| testdonthdr = 'HeaderIGNORED' | ||
| testdontval = 'BOGUSvalue' | ||
|
|
||
| # header fields (or its values) could be files to be read instead of literals | ||
| testcmdfile = os.path.join(self.test_prefix, 'testhttpheaderscmdline.txt') | ||
| testincfile = os.path.join(self.test_prefix, 'testhttpheadersvalinc.txt') | ||
| testexcfile = os.path.join(self.test_prefix, 'testhttpheadersvalexc.txt') | ||
| testinchdrfile = os.path.join(self.test_prefix, 'testhttpheadershdrinc.txt') | ||
| testexchdrfile = os.path.join(self.test_prefix, 'testhttpheadershdrexc.txt') | ||
| testurlpatfile = os.path.join(self.test_prefix, 'testhttpheadersurlpat.txt') | ||
|
|
||
| # log mention format upon header or file inclusion | ||
| mentionhdr = 'Custom HTTP header field set: %s' | ||
| mentionfile = 'File included in parse_http_header_fields_urlpat: %s' | ||
|
|
||
| def run_and_assert(args, msg, words_expected=None, words_unexpected=None): | ||
| stdout, stderr = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False) | ||
| if words_expected is not None: | ||
| for thestring in words_expected: | ||
| self.assertTrue(re.compile(thestring).search(stdout), "Pattern '%s' missing from log (%s)" % | ||
| (thestring, msg)) | ||
| if words_unexpected is not None: | ||
| for thestring in words_unexpected: | ||
| self.assertFalse(re.compile(thestring).search(stdout), "Pattern '%s' leaked into log (%s)" % | ||
| (thestring, msg)) | ||
|
|
||
| # A: simple direct case (all is logged) | ||
Louwrensth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| args = list(common_args) | ||
| args.extend([ | ||
| '--http-header-fields-urlpat=gnu.org::%s:%s' % (testdohdr, testdoval), | ||
| '--http-header-fields-urlpat=nomatch.com::%s:%s' % (testdonthdr, testdontval), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also check with single
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that, but decided not to use the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a good technical reason not to support it, so fine by me :) |
||
| ]) | ||
| # expect to find everything passed on cmdline | ||
| run_and_assert( | ||
| args, | ||
| 'case A', | ||
| [mentionhdr % (testdohdr), testdoval, testdonthdr, testdontval] | ||
| ) | ||
|
|
||
| # all subsequent tests share this argument list | ||
| args = common_args | ||
| args.append('--http-header-fields-urlpat=%s' % (testcmdfile)) | ||
|
|
||
| # B: simple file case (secrets in file are not logged) | ||
| write_file( | ||
| testcmdfile, | ||
| '\n'.join( | ||
| [ | ||
| 'gnu.org::%s: %s' % (testdohdr, testdoval), | ||
| 'nomatch.com::%s: %s' % (testdonthdr, testdontval), | ||
| '', | ||
| ] | ||
| ), | ||
| ) | ||
Louwrensth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # expect to find only the header key (not its value) and only for the appropriate url | ||
| run_and_assert( | ||
| args, | ||
| 'case B', | ||
| [mentionhdr % (testdohdr), mentionfile % (testcmdfile)], | ||
| [testdoval, testdonthdr, testdontval], | ||
| ) | ||
Louwrensth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # C: recursion one: header value is another file | ||
| write_file( | ||
| testcmdfile, | ||
| '\n'.join( | ||
| [ | ||
| 'gnu.org::%s: %s' % (testdohdr, testincfile), | ||
| 'nomatch.com::%s: %s' % (testdonthdr, testexcfile), | ||
| '', | ||
| ] | ||
| ), | ||
| ) | ||
| write_file(testincfile, '%s\n' % (testdoval)) | ||
| write_file(testexcfile, '%s\n' % (testdontval)) | ||
| # expect to find only the header key (not its value and not the filename) and only for the appropriate url | ||
| run_and_assert( | ||
| args, | ||
| 'case C', | ||
| [ | ||
| mentionhdr % (testdohdr), | ||
| mentionfile % (testcmdfile), | ||
| mentionfile % (testincfile), | ||
| mentionfile % (testexcfile), | ||
| ], | ||
| [testdoval, testdonthdr, testdontval], | ||
| ) | ||
|
|
||
| # D: recursion two: header field+value is another file, | ||
| write_file(testcmdfile, '\n'.join(['gnu.org::%s' % (testinchdrfile), 'nomatch.com::%s' % (testexchdrfile), ''])) | ||
| write_file(testinchdrfile, '%s: %s\n' % (testdohdr, testdoval)) | ||
| write_file(testexchdrfile, '%s: %s\n' % (testdonthdr, testdontval)) | ||
| # expect to find only the header key (and the literal filename) and only for the appropriate url | ||
| run_and_assert( | ||
| args, | ||
| 'case D', | ||
| [ | ||
| mentionhdr % (testdohdr), | ||
| mentionfile % (testcmdfile), | ||
| mentionfile % (testinchdrfile), | ||
| mentionfile % (testexchdrfile), | ||
| ], | ||
| [testdoval, testdonthdr, testdontval], | ||
| ) | ||
|
|
||
| # E: recursion three: url pattern + header field + value in another file | ||
| write_file(testcmdfile, '%s\n' % (testurlpatfile)) | ||
| write_file( | ||
| testurlpatfile, | ||
| '\n'.join( | ||
| [ | ||
| 'gnu.org::%s: %s' % (testdohdr, testdoval), | ||
| 'nomatch.com::%s: %s' % (testdonthdr, testdontval), | ||
| '', | ||
| ] | ||
| ), | ||
| ) | ||
| # expect to find only the header key (but not the literal filename) and only for the appropriate url | ||
| run_and_assert( | ||
| args, | ||
| 'case E', | ||
| [mentionhdr % (testdohdr), mentionfile % (testcmdfile), mentionfile % (testurlpatfile)], | ||
| [testdoval, testdonthdr, testdontval], | ||
| ) | ||
|
|
||
| def test_test_report_env_filter(self): | ||
| """Test use of --test-report-env-filter.""" | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.