Skip to content

Commit

Permalink
Allow accessing public data with anonymous user when shim is turned ON (
Browse files Browse the repository at this point in the history
#1755)

* Allow anonymous credentials to work with shim

* Fix typo

* Add tests

* Fix tests that were breaking because of call to gcloud config get account in the translation step

* Update tests

* Add shim test base class

* Fix signurl test

* Update test to work for Windows

* Fix test failures for windows

* Add period just to trigger kokoro

* Fix teardown method for shim
  • Loading branch information
dilipped authored Nov 8, 2023
1 parent 423c588 commit a872f98
Show file tree
Hide file tree
Showing 29 changed files with 331 additions and 144 deletions.
2 changes: 1 addition & 1 deletion gslib/tests/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ class TestAclOldAlias(TestAcl):
_ch_acl_prefix = ['chacl']


class TestAclShim(testcase.GsUtilUnitTestCase):
class TestAclShim(testcase.ShimUnitTestBase):

@mock.patch.object(acl.AclCommand, 'RunCommand', new=mock.Mock())
def test_shim_translates_acl_get_object(self):
Expand Down
8 changes: 4 additions & 4 deletions gslib/tests/test_autoclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ class TestAutoclassUnit(testcase.GsUtilUnitTestCase):

def test_set_too_few_arguments_fails(self):
with self.assertRaisesRegex(exception.CommandException,
'command requires at least'):
'command requires at least'):
self.RunCommand('autoclass', ['set'])

def test_get_too_few_arguments_fails(self):
with self.assertRaisesRegex(exception.CommandException,
'command requires at least'):
'command requires at least'):
self.RunCommand('autoclass', ['get'])

def test_no_subcommand_fails(self):
with self.assertRaisesRegex(exception.CommandException,
'command requires at least'):
'command requires at least'):
self.RunCommand('autoclass', [])

def test_invalid_subcommand_fails(self):
with self.assertRaisesRegex(exception.CommandException,
'Invalid subcommand'):
'Invalid subcommand'):
self.RunCommand('autoclass', ['fakecommand', 'test'])

def test_gets_multiple_buckets_with_wildcard(self):
Expand Down
2 changes: 1 addition & 1 deletion gslib/tests/test_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_cat_encrypted_object(self):
self.assertEqual(stdout, '123')


class TestShimCatFlags(testcase.GsUtilUnitTestCase):
class TestShimCatFlags(testcase.ShimUnitTestBase):
"""Unit tests for shimming cat flags"""

def test_shim_translates_flags(self):
Expand Down
2 changes: 1 addition & 1 deletion gslib/tests/test_copy_objects_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_iterator(self):
for (src_string, dst_string) in src_dst_strings:
copy_object_info = next(copy_objects_iterator)
self.assertEqual(src_string,
copy_object_info.source_storage_url.object_name)
copy_object_info.source_storage_url.object_name)
self.assertEqual(dst_string, copy_object_info.exp_dst_url.object_name)

iterator_ended = False
Expand Down
8 changes: 6 additions & 2 deletions gslib/tests/test_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2137,8 +2137,8 @@ def _Check1():

_Check1()

@unittest.skipIf(
IS_WINDOWS, 'Unicode handling on Windows requires mods to site-packages')
@unittest.skipIf(IS_WINDOWS,
'Unicode handling on Windows requires mods to site-packages')
@SequentialAndParallelTransfer
def test_cp_manifest_upload_unicode(self):
return self._ManifestUpload('foo-unicöde'.encode(UTF8),
Expand Down Expand Up @@ -5009,6 +5009,10 @@ def test_translates_predefined_acl_sub_opts(self):
self.assertEqual(sub_opts, [('--flag-key', 'flag-value'),
('-a', 'publicRead'), ('-a', 'does-not-exist')])


class TestCpShimUnitTests(testcase.ShimUnitTestBase):
"""Unit tests for shimming cp flags"""

def test_shim_translates_flags(self):
bucket_uri = self.CreateBucket()
fpath = self.CreateTempFile(contents=b'abcd')
Expand Down
2 changes: 1 addition & 1 deletion gslib/tests/test_defacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def testTooFewArgumentsFails(self):
self.assertIn('command requires at least', stderr)


class TestDefaclShim(case.GsUtilUnitTestCase):
class TestDefaclShim(case.ShimUnitTestBase):

@mock.patch.object(defacl.DefAclCommand, 'RunCommand', new=mock.Mock())
def test_shim_translates_defacl_get(self):
Expand Down
2 changes: 1 addition & 1 deletion gslib/tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def testHashCompositeObject(self):
self.assertIn(('\tHash (crc32c):\t\t%s' % _TEST_COMPOSITE_B64_CRC), stdout)


class TestHashShim(testcase.GsUtilUnitTestCase):
class TestHashShim(testcase.ShimUnitTestBase):

@mock.patch.object(hash.HashCommand, 'RunCommand', new=mock.Mock())
def test_shim_translates_basic_hash_command(self):
Expand Down
4 changes: 2 additions & 2 deletions gslib/tests/test_hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def AssertKeyMetadataMatches(self,
self.assertRegex(output_string, r'Access ID %s:' % access_id)
self.assertRegex(output_string, r'\sState:\s+%s' % state)
self.assertRegex(output_string,
r'\s+Service Account:\s+%s\n' % service_account)
r'\s+Service Account:\s+%s\n' % service_account)
self.assertRegex(output_string, r'\s+Project:\s+%s' % project)
self.assertRegex(output_string, r'\s+Time Created:\s+.*')
self.assertRegex(output_string, r'\s+Time Last Updated:\s+.*')
Expand Down Expand Up @@ -412,7 +412,7 @@ def test_hmac_fails_for_xml(self):
'The "hmac" command can only be used with the GCS JSON API', stderr)


class TestHmacUnit(testcase.GsUtilUnitTestCase):
class TestHmacUnitShim(testcase.ShimUnitTestBase):

@mock.patch.object(hmac.HmacCommand, 'RunCommand', new=mock.Mock())
def test_shim_translates_hmac_create_command(self):
Expand Down
Loading

0 comments on commit a872f98

Please sign in to comment.