1# -*- coding: utf-8 -*- 2# Copyright 2013 Google Inc. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Integration tests for gsutil -D option.""" 16 17from __future__ import absolute_import 18 19import platform 20 21import gslib 22from gslib.cs_api_map import ApiSelector 23import gslib.tests.testcase as testcase 24from gslib.tests.testcase.integration_testcase import SkipForS3 25from gslib.tests.util import ObjectToURI as suri 26from gslib.tests.util import SetBotoConfigForTest 27from gslib.util import ONE_KIB 28 29 30@SkipForS3('-D output is implementation-specific.') 31class TestDOption(testcase.GsUtilIntegrationTestCase): 32 """Integration tests for gsutil -D option.""" 33 34 def test_minus_D_multipart_upload(self): 35 """Tests that debug option does not output upload media body.""" 36 # We want to ensure it works with and without a trailing newline. 37 for file_contents in ('a1b2c3d4', 'a1b2c3d4\n'): 38 fpath = self.CreateTempFile(contents=file_contents) 39 bucket_uri = self.CreateBucket() 40 with SetBotoConfigForTest( 41 [('GSUtil', 'resumable_threshold', str(ONE_KIB))]): 42 stderr = self.RunGsUtil( 43 ['-D', 'cp', fpath, suri(bucket_uri)], return_stderr=True) 44 print 'command line:' + ' '.join(['-D', 'cp', fpath, suri(bucket_uri)]) 45 if self.test_api == ApiSelector.JSON: 46 self.assertIn('media body', stderr) 47 self.assertNotIn('a1b2c3d4', stderr) 48 self.assertIn('Comparing local vs cloud md5-checksum for', stderr) 49 self.assertIn('total_bytes_transferred: %d' % len(file_contents), 50 stderr) 51 52 def test_minus_D_resumable_upload(self): 53 fpath = self.CreateTempFile(contents='a1b2c3d4') 54 bucket_uri = self.CreateBucket() 55 with SetBotoConfigForTest([('GSUtil', 'resumable_threshold', '4')]): 56 stderr = self.RunGsUtil( 57 ['-D', 'cp', fpath, suri(bucket_uri)], return_stderr=True) 58 self.assertNotIn('a1b2c3d4', stderr) 59 self.assertIn('Comparing local vs cloud md5-checksum for', stderr) 60 self.assertIn('total_bytes_transferred: 8', stderr) 61 62 def test_minus_D_cat(self): 63 """Tests cat command with debug option.""" 64 key_uri = self.CreateObject(contents='0123456789') 65 with SetBotoConfigForTest([('Boto', 'proxy_pass', 'secret')]): 66 (stdout, stderr) = self.RunGsUtil( 67 ['-D', 'cat', suri(key_uri)], return_stdout=True, return_stderr=True) 68 self.assertIn('You are running gsutil with debug output enabled.', stderr) 69 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) 70 self.assertIn('config:', stderr) 71 self.assertIn("('proxy_pass', 'REDACTED')", stderr) 72 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) 73 self.assertIn('header: Expires: ', stderr) 74 self.assertIn('header: Date: ', stderr) 75 self.assertIn('header: Content-Type: application/octet-stream', stderr) 76 self.assertIn('header: Content-Length: 10', stderr) 77 78 if self.test_api == ApiSelector.XML: 79 self.assertRegexpMatches( 80 stderr, '.*HEAD /%s/%s.*Content-Length: 0.*User-Agent: .*gsutil/%s' % 81 (key_uri.bucket_name, key_uri.object_name, gslib.VERSION)) 82 83 self.assertIn('header: Cache-Control: private, max-age=0', 84 stderr) 85 self.assertIn('header: Last-Modified: ', stderr) 86 self.assertIn('header: ETag: "781e5e245d69b566979b86e28d23f2c7"', stderr) 87 self.assertIn('header: x-goog-generation: ', stderr) 88 self.assertIn('header: x-goog-metageneration: 1', stderr) 89 self.assertIn('header: x-goog-hash: crc32c=KAwGng==', stderr) 90 self.assertIn('header: x-goog-hash: md5=eB5eJF1ptWaXm4bijSPyxw==', stderr) 91 elif self.test_api == ApiSelector.JSON: 92 self.assertRegexpMatches( 93 stderr, '.*GET.*b/%s/o/%s.*user-agent:.*gsutil/%s.Python/%s' % 94 (key_uri.bucket_name, key_uri.object_name, gslib.VERSION, 95 platform.python_version())) 96 self.assertIn(('header: Cache-Control: no-cache, no-store, max-age=0, ' 97 'must-revalidate'), stderr) 98 self.assertIn("md5Hash: u'eB5eJF1ptWaXm4bijSPyxw=='", stderr) 99 100 if gslib.IS_PACKAGE_INSTALL: 101 self.assertIn('PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS', stdout) 102 else: 103 self.assertRegexpMatches(stdout, r'.*checksum: [0-9a-f]{32}.*') 104 self.assertIn('gsutil version: %s' % gslib.VERSION, stdout) 105 self.assertIn('boto version: ', stdout) 106 self.assertIn('python version: ', stdout) 107 self.assertIn('OS: ', stdout) 108 self.assertIn('multiprocessing available: ', stdout) 109 self.assertIn('using cloud sdk: ', stdout) 110 self.assertIn('config path: ', stdout) 111 self.assertIn('gsutil path: ', stdout) 112 self.assertIn('compiled crcmod: ', stdout) 113 self.assertIn('installed via package manager: ', stdout) 114 self.assertIn('editable install: ', stdout) 115