
    &                     \   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ dd	lmZ dd
lmZ ddlmc mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddlm&Z& ddlm'Z' ddlm(Z( ddlm)Z) ddlm*Z* ddlm+Z+ ddlm,Z, ddlm-Z- ddlm.Z. ddlm/Z/ dd lm0Z0 dd!lm1Z1 dd"lm2Z2 dd#lm3Z3 dd$lm4Z4 dd%lm5Z5 dd&lm6Z6 dd'lm7Z7 dd(lm8Z8 dd)lm9Z9 dd*lm:Z: dd+lm;Z; dd,lm<Z< dd-l=m>Z? dd.l@mAZA dd/lBmCZC dd0lDmEZE dd1lFmGZG dd2lHmIZI dd3lJmKZKmLZL  eK eLd4d4d5             dd6lMmNZN d7ZOd8ZP G d9 d:ej                        ZR G d; d<ej                        ZT G d= d>ej                        ZVy)?zTests for ls command.    )absolute_import)print_function)division)unicode_literals)datetimeN)ls)ApiSelector)PopulateProjectId)	SkipForGS)SkipForJSON)	SkipForS3)
SkipForXML)CaptureStdout)ObjectToURI)RUN_S3_TESTS)SetBotoConfigForTest)SetEnvironmentForTest)SkipForP12Creds)TEST_ENCRYPTION_CONTENT1)TEST_ENCRYPTION_CONTENT1_CRC32C)TEST_ENCRYPTION_CONTENT1_MD5)TEST_ENCRYPTION_CONTENT2)TEST_ENCRYPTION_CONTENT2_CRC32C)TEST_ENCRYPTION_CONTENT2_MD5)TEST_ENCRYPTION_CONTENT3)TEST_ENCRYPTION_CONTENT3_CRC32C)TEST_ENCRYPTION_CONTENT3_MD5)TEST_ENCRYPTION_CONTENT4)TEST_ENCRYPTION_CONTENT4_CRC32C)TEST_ENCRYPTION_CONTENT4_MD5)TEST_ENCRYPTION_CONTENT5)TEST_ENCRYPTION_CONTENT5_CRC32C)TEST_ENCRYPTION_CONTENT5_MD5)TEST_ENCRYPTION_KEY1)TEST_ENCRYPTION_KEY1_SHA256_B64)TEST_ENCRYPTION_KEY2)TEST_ENCRYPTION_KEY2_SHA256_B64)TEST_ENCRYPTION_KEY3)TEST_ENCRYPTION_KEY3_SHA256_B64)TEST_ENCRYPTION_KEY4)TEST_ENCRYPTION_KEY4_SHA256_B64)unittest)storage_v1_messages)UTF8)PrintFullInfoAboutObject)Retry)
IS_WINDOWS)	shim_util)add_moveMovedModulemockzunittest.mock)r5   z\gsutil does not support KMS operations for S3 buckets, or listing KMS keys with the XML API.zggsutil does not support bucket lock operations for S3 buckets or listing retention policy with XML API.c                       e Zd ZdZd Zej                  j                  ej                  d      d        Z
ej                  j                  ej                  d      d        Zy)
TestLsUnitzUnit tests for ls command.c           
      6   | j                   t        j                  k(  rt        j                  d      S t        dddddddd	
      }t        j                  dd|||d      }t        j                         }||_
        d|_        t               5 }t        |       d	d	d	       dj                        }t        j                   dt        j"                        }t        j$                  ||      }| j'                  |       t        dddddddd	
      }t        j                  dd|||d      }t        j                         }	||	_
        d|	_        t               5 }
t        |	       d	d	d	       dj                  
      }
t        j                   dt        j"                        }t        j$                  ||
      }| j)                  |       |j+                  d      }| j-                  |t        j.                  |d             t        j                   dt        j"                        }t        j$                  ||
      }| j)                  |       |j+                  d      }| j-                  |t        j.                  |d             y	# 1 sw Y   xY w# 1 sw Y   -xY w)z/Tests the JSON storage class update time field.z3XML API has no concept of storage class update timei                    N)tzinfofoobar12345)namebuckettimeCreatedupdatedtimeStorageClassUpdatedetag
z<^\s*Storage class update time:+(?P<stor_update_time_val>.+)$   foo2bar2.^\s*Creation time:\s+(?P<time_created_val>.+)$time_created_valz%a, %d %b %Y %H:%M:%S GMTz>^\s*Storage class update time:+(?P<stor_update_time_val_2>.+)$stor_update_time_val_2)test_apir	   XMLr,   skipr   apitools_messagesObjectr5   Mockroot_object
url_stringr   r/   joinrecompile	MULTILINEsearchassertIsNoneassertIsNotNonegroupassertEqualstrftime)selfcurrent_timeobj_metadataobj_refoutputfind_stor_update_restor_update_time_matchnew_update_timeobj_metadata2obj_ref2output2find_time_created_retime_created_matchtime_createdfind_stor_update_re_2stor_update_time_match_2stor_update_times                    &platform/gsutil/gslib/tests/test_ls.py+test_one_object_with_L_storage_class_updatez6TestLsUnit.test_one_object_with_L_storage_class_update[   sT   }}']]
?A A D!Q1a4@L$++  ,L iikG&GG 
Fw' 
YYvF **G
  YY':FC,- tQ1aAdCO%,,  /M yy{H(H H 
Gx( 
ii G ::92<<I#7A+,%++,>?L,(CDF JJI
  "yy)>H12/556NO/+FGIa 
8 
s   JJJJWildcardIteratorc                    | j                  d      }t        j                  dd      }||_        d|_        t        j                         |_        |g|j                  j                  _        t        dg      5  | j                  ddt        |      gd      }d d d        | j                  d	       y # 1 sw Y   xY w)
Nr@   bucket_nameT)rC   satisfiesPZSGSUtilcheck_hashesneverr   -Lbreturn_stdoutzSatisfies PZS:			True)CreateBucketrS   BucketrV   rW   r5   rU   storage_urlreturn_valueIterBucketsr   
RunCommandsuriassertRegexrb   mock_wildcard
bucket_uribucket_metadatastdouts        rs   *test_satisfies_pzs_is_displayed_if_presentz5TestLsUnit.test_satisfies_pzs_is_displayed_if_present   s    ""u"5J'..EMO,J!J!YY[J;E,M**7	BC	DteT*-=%>-1  3f 
E 	V78 
E	Ds   9 B44B=c                 ~   | j                  d      }t        j                  d      }||_        d|_        t        j                         |_        |g|j                  j                  _        t        dg      5  | j                  ddt        |      gd      }d	d	d	       | j                  d
       y	# 1 sw Y   xY w)zANon custom dual region buckets should not display placement info.zfoo-non-cdrrw   )rC   rz   r   r~   Tr   NzPlacement locations:)r   rS   r   rV   rW   r5   rU   r   r   r   r   r   r   assertNotRegexr   s        rs   8test_placement_locations_not_displayed_for_normal_bucketzCTestLsUnit.test_placement_locations_not_displayed_for_normal_bucket   s     ""}"=J'..MBO,J)J!YY[J;E,M**7	BC	DteT*-=%>-1  3f 
E 	 67 
E	Ds   8 B33B<N)__name__
__module____qualname____doc__rt   r5   patchobjectr   	LsCommandr   r        rs   r7   r7   X   sa    "GIR ::R\\#569 79 ::R\\#568 78r   r7   c                       e Zd ZdZd Zy)TestLsUnitWithShimz$Unit tests for ls command with shim.c           	      <   t        ddg      5  t        ddd      5  | j                  dddgd	
      }| j                  dj	                  t        j                  d            |j                  d          d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N)r{   use_gcloud_storageTrue)r{   hidden_shim_modedry_runr   fake_dir)(CLOUDSDK_CORE_PASS_CREDENTIALS_TO_GSUTILCLOUDSDK_ROOT_DIRr   z	-rRlLbeahz-p fooT)return_log_handlerzzGcloud Storage Command: {} storage ls --fetch-encrypted-object-hashes -r -r -l -L -b -e -a --readable-sizes --project  fooinfo)r   r   r   assertInformatr2   _get_gcloud_binary_pathmessages)rb   mock_log_handlers     rs   test_shim_translates_flagsz-TestLsUnitWithShim.test_shim_translates_flags   s    	GHJ 
K 6<)" 	  ??4+x1H>B + DDDJF11*=E?%%f-	/	
K 
K	 	
K 
Ks#   BAB5BB	BBN)r   r   r   r   r   r   r   rs   r   r      s
    ,/r   r   c                   F   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z ed      d        Z ed      d        Z ed       ed      d               Z ed       ed      d               Z ed       ed      d               Zd Zd Z ed       ed      d               Zd Zd Zd Zd Z d  Z! ed!      d"        Z" e#jH                  d#       ed$       ed%      d&                      Z% ed!      d'        Z& ed!      d(        Z' ed!       ed)      d*               Z(d+ Z) e#jT                  e+d,      d-        Z,d. Z-d/ Z.d0 Z/ ed1      d2        Z0d3 Z1 ed1      d4        Z2d5 Z3 ed6      d7        Z4 ed8      d9        Z5 ed8      d:        Z6d; Z7d< Z8 ee9       ee9      d=               Z: ee9       ee9      d>               Z; ee<       ee<      d?               Z= ee<       ee<      d@               Z> ee<       ee<      dA               Z? ee<       ee<      dB               Z@ edC       edD      dE               ZA edF       edG      dH               ZB edI       edJ      dK               ZC edL       edM      dN               ZDyO)PTestLsz!Integration tests for ls command.c                 6    t         s| j                  dg       y y )Nr   )r   	RunGsUtilrb   s    rs   test_blank_lszTestLs.test_blank_ls   s    
nndV r   c                 H    | j                         }| j                  |d       y )Nr   )r   AssertNObjectsInBucket)rb   r   s     rs   test_empty_bucketzTestLs.test_empty_bucket   s     ""$J
A.r   c                 l      j                         t        t        dd       fd       } |        y )Nr;   r9   triestimeout_secsc                      j                  ddt              gd      } j                  dt              z  |        y )Nr   -bTr   z%s/
r   r   r`   r   r   rb   s    rs   _Check1z0TestLs.test_empty_bucket_with_b.<locals>._Check1   sA    ~~tT4
+;<,0  2f
wj!116:r   r   r0   AssertionErrorrb   r   r   s   ` @rs   test_empty_bucket_with_bzTestLs.test_empty_bucket_with_b   s3    ""$J
>3; 4;
 Ir   c                    | j                         }| j                  ddt        |      gd      }| j                  t        |      |       | j	                  d|       | j                  dddt        |      g       | j                  ddd	t        |      g       | j                  ddt        |      gd      }t        j                  d
t
        j                        }t        j                  dt
        j                        }t        j                  dt
        j                        }t        j                  ||      }t        j                  ||      }t        j                  ||      }| j                  t        j                  k(  r4| j                  |       | j                  |       | j                  |       y| j                  t        j                  k(  r| j                  |       | j                  |       | j                  |       |j                  d      }	t!        j"                  |	d      }	|j                  d      }
t!        j"                  |
d      }
| j%                  |
|	       | j'                  d|       yy)zTests ls -Lb.r   r~   Tr   TOTAL:
versioningsetonoffz1^\s*Metageneration:\s+(?P<metageneration_val>.+)$z-^\s*Time created:\s+(?P<time_created_val>.+)$z-^\s*Time updated:\s+(?P<time_updated_val>.+)$rN   %a, %d %b %Y %H:%M:%S %Ztime_updated_valFN)r   r   r   r   assertNotInrY   rZ   r[   r\   rP   r	   rQ   r]   JSONr^   r_   timestrptimeassertGreater_AssertBucketPolicyOnly)rb   r   r   find_metageneration_rerm   find_time_updated_remetageneration_matchrn   time_updated_matchro   time_updateds              rs   test_bucket_with_LbzTestLs.test_bucket_with_Lb   s   ""$J^^T5$z*:;4^PFMM$z"F+ 	Xv& 	NNL%tJ/?@ANNL%Z0@AB^^T5$z*:;4^PFZZ<bllL::8",,H::8",,H99%;VD#7@#7@}}'
,-
*+
*+	+**	*
/0
-.
-.'--.@Al]]<1KLl'--.@Al]]<1KLl
|4
""5&1 
+r   c                     | j                   t        j                  k(  rE| j                  dd      }| j	                  ddt        |      gd      }| j                  d|       y y )NT)bucket_policy_onlyprefer_json_apir   r~   r   )rP   r	   r   r   r   r   r   rb   r   r   s      rs   &test_bucket_with_Lb_bucket_policy_onlyz-TestLs.test_bucket_with_Lb_bucket_policy_only  sg    }}((($$59 % ;j~~tUD,<=,0  2f
""40 )r   c                     t        j                  dt         j                        }t        j                  ||      }|j	                  d      }| j                  t        |      |       y )Nz2^\s*Bucket Policy Only enabled:\s+(?P<bpo_val>.+)$bpo_val)rY   rZ   r[   r\   r_   r`   str)rb   valuer   bucket_policy_only_rebucket_policy_only_matchbucket_policy_only_vals         rs   r   zTestLs._AssertBucketPolicyOnly"  sS    JJ=r||M!yy)>G5;;IFSZ!78r   c                 l      j                         t        t        dd       fd       } |        y)zTests ls -lb.r;   r9   r   c                      j                  ddt              gd      } j                  t              |        j                  d|        y )Nr   -lbTr   r   )r   r   r   r   r   s    rs   r   z+TestLs.test_bucket_with_lb.<locals>._Check1-  sJ    ~~tUD,<=,0  2f
mmD$f-
x(r   Nr   r   s   ` @rs   test_bucket_with_lbzTestLs.test_bucket_with_lb)  s3    ""$J
>3) 4) Ir   c                      j                         } j                  d|      } j                  d|      } j                  |       j                  |      t        j                  t              t              g      } j                  |j                   j                  d|d             d|z  t        t        dd	       fd
       } |        y)z/Tests listing multiple buckets with a wildcard.rD   )prefixrw   z://z%gsutil-test-test-bucket-list-wildcardz%s*r;   r9   r   c                      j                  ddgd      } t        t              dz   t              dz   g      }t        | j                               }j	                  ||       y )Nr   r   Tr   /)r   r   r   splitr`   )r   expectedactualbucket1_uribucket2_urirb   wildcards      rs   r   z1TestLs.test_bucket_list_wildcard.<locals>._Check1J  s_    ~~tT84D~Ifd;'#-tK/@3/FGHh6<<>"f
x(r   N)MakeRandomTestStringMakeTempNamer   	posixpathcommonprefixr   
assertTrue
startswithdefault_providerr0   r   )	rb   random_prefixbucket1_namebucket2_namecommon_prefixr   r   r   r   s	   `     @@@rs   test_bucket_list_wildcardz TestLs.test_bucket_list_wildcard6  s    --/M$$Xm$DL$$Xm$DL###=K###=K
 **	k	D-.0MOO  ""M3	45 }$H >3) 4) Ir   c                 H   | j                  ddd| j                  z  gdd      }| j                  d|       | j                  ddd| j                  z  gdd      }| j                  d|       | j                  dd	d| j                  z  gdd      }| j                  d|       y
)z*Tests a bucket that is known not to exist.r   r   zgs://%sTr9   return_stderrexpected_status404r~   r   N)r   nonexistent_bucket_namer   rb   stderrs     rs   test_nonexistent_bucket_with_lsz&TestLs.test_nonexistent_bucket_with_lsS  s    ^^	ui$">">>?  F 	MM% ^^	ui$">">>?  F 	MM% ^^	tY!=!==>  F 	MM% r   c                     | j                         }| j                  dt        |d      gdd      }| j                  d|       y)z$Tests listing a non-existent object.r   missingTr9   r   zmatched no objectsN)r   r   r   r   )rb   r   r  s      rs   test_list_missing_objectzTestLs.test_list_missing_objectg  sH    ""$J^^T4
I#>?*.,-  /F 	MM&/r   c                       j                          j                  d      t        t        dd       fd       } |        y )N   foor   contentsr;   r9   r   c                  l    j                  dt              gd      } j                  dz  |        y Nr   Tr   %s
r   )r   r   obj_urirb   s    rs   r   z,TestLs.test_with_one_object.<locals>._Check1s  s4    ~~tT*%56d~Kf
v'0r   r   CreateObjectr0   r   )rb   r   r   r  s   ` @@rs   test_with_one_objectzTestLs.test_with_one_objecto  sH    ""$J:GG
>31 41 Ir   c                 p    d|z  }d|z  }t        dd|fg      5   j                  |      } j                  |d      d d d        t        t        dd	       fd
       }t        dd|fg      5   |t                      |t                     d d d        y # 1 sw Y   _xY w# 1 sw Y   y xY w)Nzs3.%s.amazonaws.coms3hostlocationr
  r  r;   r9   r   c                 Z    j                  d| gd      }j                  dz  |       y r  )r   r`   )urir   r  rb   s     rs   r   z5TestLs.location_redirect_test_helper.<locals>._Check1  s.    ~~tSk~>f
v'0r   )r   r   r  r0   r   r   )rb   bucket_regionclient_regionbucket_hostclient_hostr   r   r  s   `      @rs   location_redirect_test_helperz$TestLs.location_redirect_test_helperz  s    '-7K'-7K	fk:;	<$$m$<j!!Z&!Ig 
= >31 41 
fk:;	<d:d7m	 
=	< 
=	< 
=	<s   &B 4#B, B),B5z3Only s3 V4 signatures error on location mismatches.c                 (    | j                  dd       y )Nz	ap-east-1	us-east-2r  r   s    rs   test_400_location_redirectz!TestLs.test_400_location_redirect  s     	&&{K@r   c                 (    | j                  dd       y )Nz	eu-west-1r!  r"  r   s    rs   test_301_location_redirectz!TestLs.test_301_location_redirect  s    &&{K@r   zNot relevant for S3z6Only the XML API supports changing the calling format.c                     | j                         }| j                  |d      }| j                  ddt        |      gd      }| j	                  d|       y )Nr
  r  -Dr   Tr   zHost: storage.googleapis.com)r   r  r   r   r   )rb   r   
object_urir  s       rs   -test_default_gcs_calling_format_is_path_stylez4TestLs.test_default_gcs_calling_format_is_path_style  sT     ""$J""j6"JJ^^T4j)9:$^OFMM0&9r   c                    | j                         }| j                  |d      }d}t        dd|fg      5  | j                  ddt	        |      gd	      }d d d        | j                  d
|j                  z         y # 1 sw Y   )xY w)Nr
  r  z)boto.s3.connection.SubdomainCallingFormatr  calling_formatr'  r   Tr   zHost: %s.storage.googleapis.com)r   r  r   r   r   r   rx   )rb   r   r(  custom_calling_formatr  s        rs   'test_gcs_calling_format_is_configurablez.TestLs.test_gcs_calling_format_is_configurable  s     ""$J""j6"JJG	&68MN   
!~~tT4
+;<,0  2f
! 	MM3j6L6LL	
! 
!s    A==Bz-Credstore file gets created only for json APIzEP12 credentials are not cached, as they are supported via google-authc                       j                         }t        j                  j                  |d      dj	                  |       j                          j                  d      t        t        dd       fd       } |        y )	N
credstore2zGSUtil:state_dir={}r
  r  r;   r9   r   c                     j                  ddt              gd      } j                  dz  |        t        j                  dk(  rj                  t        j                  j                               t        t        j                  t        j                        j                              }j                  t        d      |       y y )Nz-or   Tr   r  posixi  )r   r   r`   osrC   r   pathexistsoctstatS_IMODEst_mode)r   moder   filepathr  optionrb   s     rs   r   z6TestLs.test_credfile_lock_permissions.<locals>._Check1  s    ~~tJ/
0  Ff
v'0	G	x014<< 1 9 9:;UT*	 
r   )	CreateTempDirr2  r3  rX   r   r   r  r0   r   )rb   tmpdirr   r   r:  r  r;  s   `  @@@@rs   test_credfile_lock_permissionsz%TestLs.test_credfile_lock_permissions  s|     !Fww||FL1H"))&1F""$J:GG
>3+ 4+ Ir   c                 T   | j                  d      }| j                  ddt        |      gd      }|j                         }| j	                  |d   j                                t        j                  |j                         d   d	       | j                  |d
   t        |             y)z!Tests listing one object with -l.r
  r  r   -lTr   r   r9   z%Y-%m-%dT%H:%M:%SZr:   N)	r  r   r   r   r   isdigitr   r   r`   )rb   r  r   output_itemss       rs   test_one_object_with_lzTestLs.test_one_object_with_l  s    0G^^T4g7t^LF<<>LOOLO++-.MM&,,.#%9:\!_d7m4r   c                 R   | j                  d      }t        j                  d       | j                  dddt	        |      g       t        j                  dt
        j                        }t        j                  dt
        j                        }| j                  d	d
t	        |      gd      }t        j                  ||      }t        j                  ||      }|j                  d      }| j                  |       t        j                  |d      }| j                  t        j                  k(  r| j                  |       y| j                  t        j                   k(  rK|j                  d      }| j                  |       t        j                  |d      }| j#                  ||       yy)z!Tests listing one object with -L.r
  r@  r:   setmetaz-hzx-goog-meta-foo:barrM   z,^\s*Update time:\s+(?P<time_updated_val>.+)$r   -LTr   rN   r   r   N)r  r   sleepr   r   rY   rZ   r[   r\   r_   r^   r   rP   r	   rQ   r]   r   r   )	rb   r  rm   r   r   rn   r   ro   r   s	            rs   test_one_object_with_LzTestLs.test_one_object_with_L  sS   0GJJqMNNIt%:DMJK::92<<I::7G^^T4g7t^LF#7@#7@%++,>?L&==/IJL}}'
*+	+**	*'--.@Al
<(]]<1KLl
|4	 
+r   z<Integration test utils only support GCS JSON for versioning.c                    | j                  d      }| j                  |j                  d      }| j                  |j                  |j                  d      }dj                  |j                  |j                  |j
                        }dj                  |j                  |j                  |j
                        }| j                  d|gd	      }| j                  ||       | j                  ||       y
)zDTests listing one object by generation when multiple versions exist.T)versioning_enabled   1)rx   r     2)rx   object_namer  zgs://{}/{}#{}r   r   N)	CreateBucketJsonCreateObjectJsonrC   r   rD   
generationr   r   r   )rb   rD   object1object2object_url_string1object_url_string2r   s          rs   test_one_object_with_generationz&TestLs.test_one_object_with_generation  s     ""d";F##d#KG##07-1 $ 3G )//070B0BD(//070B0BD ^^T#56d^KF'0MM$f-r   c                      j                  d       j                  d       j                  d        j                  d       j                  d       t        t        dd       fd	       } |        y
)z$Tests listing a bucket subdirectory.r9   test_objectsr@   bazdir/foorA   r;   r   c                      j                  ddt              z  gd      } j                  dt              z  |        j                  dt              gd      } j                  dt              z  |        y )Nr   z%s/dirTr   r  r   )r   r   k1_urik2_urirb   s    rs   r   z#TestLs.test_subdir.<locals>._Check1  sw    ~~tXZ0@%@A,0  2f
vV,f5~~tT&\2$~Gf
vV,f5r   Nr   StorageUriCloneReplaceNameStorageUriSetContentsFromStringr0   r   )rb   r   r   r]  r^  s   ` @@@rs   test_subdirzTestLs.test_subdir  s|    """2J,,Z?F((7,,ZCF((7
>36 46 Ir   c                      j                  d       j                  d       j                  d        j                  d      } j                  |d        j                  d      } j                  |d        j                  d      } j                  |d	       t        t        d
d       fd       } |        y)zTests listing a bucket subdirectory using -d.

    Result will display subdirectory names instead of contents. Uses a wildcard
    to show multiple matching subdirectories.
    r9   rX  r@   rZ  r[  rA   zdir/foo2z	dir2/foo3rK   r;   r   c                     j                  dddt              z  gd      } j                  t              dt              d|        j                  dt              gd      } j                  dt              z  |        y )	Nr   z-dz%s/dir*Tr   z/dir/
z/dir2/
r  r   )r   r   r]  rb   s    rs   r   z.TestLs.test_subdir_nocontents.<locals>._Check1  s    ~~y4
#33
4D  Jf
#'
#3T*5E
FP~~tT&\2$~Gf
vV,f5r   Nr_  )rb   r^  k3_urik4_urir   r   r]  s   `    @@rs   test_subdir_nocontentszTestLs.test_subdir_nocontents  s     """2J,,Z?F((7,,ZCF((7,,ZDF((7,,ZEF((8
>36 46 Ir   c                      j                  d      } j                  d       j                  |dd       t        |j	                               D cg c]  } j                  ||      j                    c}d   } j                  d|t              g        j                  d|t              g       t        t        dd       fd	       } |        y
c c}w )z!Tests listing a versioned bucket.r9   rX  T	versionedr   cpr;   r   c                  .   j                  ddt              gd      } j                  | d       j                  ddt              gd      } j                  dj	                  d   j
                        z  |        j                  d	|        y )
Nr   z-aTr   r;   z-laz%s#r   zmetageneration=)r   r   assertNumLinesr   r`  rC   )r   r   bucket_listrb   s    rs   _Check2z'TestLs.test_versioning.<locals>._Check26  s    ~~tT4+<=,0  2f
&!$~~tUD,=>,0  2f
mm


)
)+{1~7J7J
KL
 mm%v.r   N)r   CreateVersionedBucketr   listlist_bucketStorageUriCloneReplaceKeyversionless_urir   r   r0   r   )rb   r   keyobjuriro  r   rn  s   `    @@rs   test_versioningzTestLs.test_versioning(  s    ###3K,,!,<KQ$?{..01K C 	&&{C8HH 	F 	NND&${"345NND&${"345
>3
/ 4
/ I)s   #C c                       j                          j                  d      }|j                         j                  j	                  d      t        t        dd       fd       } |         fd} |         fd	} |        y
)z*Tests that listing an object with an etag.r
  r  "'r;   r9   r   c                      j                  ddt              gd      } j                  t        j                  k(  rj                  |        y j                  d|        y )Nr   rA  Tr   etag=)r   r   rP   r	   rQ   r   r   r   rH   rb   s    rs   r   z!TestLs.test_etag.<locals>._Check1M  sW    ~~tT4
+;<,0  2f	+//	)v&&)r   c                      j                  ddt              gd      } j                  t        j                  k(  rj                  |        y j                  d|        y )Nr   z-leTr   r{  r   r   rP   r	   rQ   r   r|  s    rs   ro  z!TestLs.test_etag.<locals>._Check2X  sS    ~~tUD,<=,0  2f	+//	)dF#gv&r   c                      j                  ddt              gd      } j                  t        j                  k(  rj                  |        y j                  d|        y )Nr   z-aleTr   r{  r~  r|  s    rs   _Check3z!TestLs.test_etag.<locals>._Check3b  sS    ~~tVT*-=>,0  2f	+//	)dF#gv&r   N)r   r  get_keyrH   stripr0   r   )rb   r  r   ro  r  r   rH   s   `    @@rs   	test_etagzTestLs.test_etagE  s    ""$J:GG ??!!''.D
>3* 4* I' I' Ir   c                 R   | j                         }t        |      }| j                  dd|gd      }| j                  |d       | j                  dddd	|gd
       | j                  dd|gd      }t	        j
                  dt        j                        }| j                  ||       y)z=Tests listing on a bucket with a label/tagging configuration.r   r~   Tr   zLabels:\s+NonelabelchrA  zlabelkey:labelvalueforce_gsutilz.Labels:\s+\{\s+"labelkey":\s+"labelvalue"\s+\}N)r   r   r   r   rY   rZ   r[   )rb   r   bucket_surir   label_regexs        rs   test_labelszTestLs.test_labelsl  s    ""$Jz"K^^T5+6d^KFV./ 	NNGT4)>L $  &^^T5+6d^KF**N\\+KV[)r   z8S3 bucket configuration values are not supported via ls.c                     | j                         }t        |      }| j                  dd|gd      }| j                  d|       | j                  dd|gd      }| j	                  |d       y)	0Tests listing a bucket with location constraint.r   r   Tr   zLocation constraint:r~   zLocation constraint:\s+\SNr   r   r   r   r   rb   r   r  r   s       rs   test_location_constraintzTestLs.test_location_constraint}  sv     ""$Jz"K ^^T5+6d^KF+V4 ^^T5+6d^KF 	V9:r   zb/135700569z7Location type not available when using the GCS XML API.z)Location type not printed for S3 buckets.c                     | j                         }t        |      }| j                  dd|gd      }| j                  d|       | j                  dd|gd      }| j	                  |d       y)	r  r   r   Tr   zLocation type:r~   zLocation type:\s+\SNr  r  s       rs   test_location_typezTestLs.test_location_type  st    
 ""$Jz"K ^^T5+6d^KF%v. ^^T5+6d^KFV34r   c                 0   | j                         }t        |      }| j                  dd|gd      }| j                  d|       d}| j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
dd||g       | j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
d|g       | j                  dd|gd      }| j	                  dj                  |      |       y)z+Tests listing a bucket with logging config.r   r   Tr   zLogging configuration		r~   zLogging configuration:{}Noneloggingr   r   r   zLogging configuration:{}Presentr   Nr   r   r   r   r   r   rb   r   r  r   spacings        rs   test_loggingzTestLs.test_logging  s    ""$Jz"K ^^T5+6d^KF,f5G^^T5+6d^KFMM077@&I 	NNIudD+{KL^^T5+6d^KFMM3::7CVL 	NNIue[9:^^T5+6d^KFMM077@&Ir   c                 ,   | j                         }t        |      }| j                  dd|gd      }| j                  d|       d}| j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
dd|g       | j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
|g       | j                  dd|gd      }| j	                  dj                  |      |       y)z+Tests listing a bucket with website config.r   r   Tr   zWebsite configurationr  r~   zWebsite configuration:{}Nonewebr   z-mz
google.comzWebsite configuration:{}PresentNr  r  s        rs   test_webzTestLs.test_web  s    ""$Jz"K ^^T5+6d^KF,f5G^^T5+6d^KFMM077@&I 	NNE5$kBC^^T5+6d^KFMM3::7CVL 	NNE5+./^^T5+6d^KFMM077@&Ir   z0Requester Pays is not supported for the XML API.c                 ,   | j                         }t        |      }d}| j                  dd|gd      }| j                  d|       | j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
d|g       | j                  dd|gd      }| j	                  dj                  |      |       | j                  d	d
d|g       | j                  dd|gd      }| j	                  dj                  |      |       y)z<Tests listing a bucket with requester pays (billing) config.r  r   r   Tr   zRequester Pays enabledr~   zRequester Pays enabled:{}Nonerequesterpaysr   r   zRequester Pays enabled:{}Truer   zRequester Pays enabled:{}FalseNr  )rb   r   r  r  r   s        rs   test_requesterpayszTestLs.test_requesterpays  s    ""$Jz"KG^^T5+6d^KF-v6 ^^T5+6d^KFMM188A6J 	NNOUD+>?^^T5+6d^KFMM188A6J 	NNOUE;?@^^T5+6d^KFMM299'BFKr   c                      j                          j                  d       t        t        dd       fd       } |        t        t        dd       fd       } |        t        t        dd       fd       } |        t        t        dd       fd	       } |        t        t        dd       fd
       } |        y)z#Tests various size listing options.s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr  r;   r9   r   c                  h    j                  ddt              gd      } j                  d|        y )Nr   rA  Tr   2048r   r   r   r   s    rs   r   z'TestLs.test_list_sizes.<locals>._Check1  5    ~~tT4
+;<,0  2f
mmFF#r   c                  h    j                  ddt              gd      } j                  d|        y )Nr   rG  Tr   r  r  r   s    rs   ro  z'TestLs.test_list_sizes.<locals>._Check2  r  r   c                  h    j                  ddt              gd      } j                  d|        y )Nr   z-alTr   r  r  r   s    rs   r  z'TestLs.test_list_sizes.<locals>._Check3  s5    ~~tUD,<=,0  2f
mmFF#r   c                  h    j                  ddt              gd      } j                  d|        y )Nr   z-lhTr   2 KiBr  r   s    rs   _Check4z'TestLs.test_list_sizes.<locals>._Check4  s5    ~~tUD,<=,0  2f
mmGV$r   c                  h    j                  ddt              gd      } j                  d|        y )Nr   z-alhTr   r  r  r   s    rs   _Check5z'TestLs.test_list_sizes.<locals>._Check5  s5    ~~tVT*-=>,0  2f
mmGV$r   Nr  )rb   r   ro  r  r  r  r   s   `     @rs   test_list_sizeszTestLs.test_list_sizes  s    ""$JkB >3$ 4$
 I >3$ 4$
 I >3$ 4$
 I >3% 4%
 I >3% 4%
 Ir   z:Unicode handling on Windows requires mods to site-packagesc                 :   d}| j                         }| j                  |d|      }| j                  |dd       | j                  ddt	        |      gd	      }| j                  ||       | j                  d
k(  r| j                  t        |j                        |       | j                  d|j                         j                  z  |       | j                  t        j                  k(  r:| j                  |j                         j                  j                  d      |       y| j                  d|       y| j                  dk(  rV| j                  |j                   |       | j                  |j                         j                  j                  d      |       yy)z0Tests listing an object with a unicode filename.u   Аудиоархивr
  )r   r  rN  r9   Tri  r   z-aelr   gszmetageneration=%sry  r{  r  N)rp  r  r   r   r   r   r   r   rQ  r  metagenerationrP   r	   rQ   rH   r  
version_id)rb   rN  r   key_urir   s        rs   test_list_unicode_filenamez!TestLs.test_list_unicode_filename  sT    *K++-J:)/,7   9G 	
A>^^T64=9^NFMM+v&$
mmC**+V4
mm''//*;*J*JJ	+//	)goo',,22596B 	gv&			$	&
mmG&&/
mmGOO%**007@ 
'r   c                     | j                  d      }| j                  ddt        |      gd      }| j                  d|       | j	                  d|       y	)
z(Tests that long listing includes an ACL.r
  r@  r   rG  Tr   zACL:zACCESS DENIEDN)r  r   r   r   r   )rb   r  r   s      rs   test_list_aclzTestLs.test_list_aclA  sP    0G^^T4g7t^LFMM&&!_f-r   c           	           ddz  } j                  |d      } j                          j                  dddt        |      t              g       t	        t
        dd	
       fd       } |        y)zTests listing a gzipped object.i'     xzfoo.txt)r  	file_namerk  z-ztxtr;   r9   r   c                  8   j                  ddt              gd      } j                  | d       d}j                  | |       t        j                  ||       }t        |j                  d            }j                  |d       j                  |       y )	Nr   rG  Tr   zContent-Encoding:\s+gzipzContent-Length:\s+(?P<num>\d)numr   )	r   r   r   rY   r\   intr_   r   
assertLess)r   find_content_length_remcontent_length	file_sizer  rb   s       rs   r   z5TestLs.test_list_gzip_content_length.<locals>._Check1Q  s    ~~tT4=9~Nf
v:;?
v56
))*F
3a1775>*n
+
ooni0r   N)CreateTempFiler  r   r   r0   r   )rb   file_contentsfpathr   r  r  s   `   @@rs   test_list_gzip_content_lengthz$TestLs.test_list_gzip_content_lengthH  sx    I9$M)LE!GNND$tE{DMBC >31 41 Ir   c                 X   | j                  d      }t        j                  dt        j                  dt        |      g}t        j                  |t        j                  d      }|j                  j                          |j                          | j                  |j                  d       y)z9Tests that gsutil still succeeds with a truncated stdout.r:   rX  z-ur   r   )r   bufsizeN)r   sys
executablegslibGSUTIL_PATHr   
subprocessPopenPIPEr   closewaitr`   
returncode)rb   r   
gsutil_cmdps       rs   test_output_choppedzTestLs.test_output_chopped^  s~    """2J 	e//ZJ
 	JOOQGAHHNNFFHQ\\1%r   zCBoto lib required for S3 does not handle paths starting with slash.c                     | j                         }| j                  |dd       | j                  |d       | j                  ddt	        |      gd      }| j                  t	        |      dz   |       y	)
.Tests listing an object with a trailing slash.r   r
  r   rN  r  r9   r   -RTr   Nr   r  r   r   r   r   r   s      rs   test_recursive_list_slash_onlyz%TestLs.test_recursive_list_slash_onlyo  so     ""$JvN
A.^^T4j)9:$^OF 	MM$z"S(&1r   c                     | j                         }| j                  |dd       | j                  |d       | j                  ddt	        |      gd      }| j                  t	        |      d	z   |       y
)r  zfoo/r
  r  r9   r   r  Tr   z/foo/Nr  r   s      rs   "test_recursive_list_trailing_slashz)TestLs.test_recursive_list_trailing_slash{  su    ""$J"(%  ' 	
A.^^T4j)9:$^OF 	MM$z"W,f5r   c                     | j                         }| j                  |dd       | j                  |d       | j                  ddt	        |      gd      }| j                  t	        |      dz   |       y	)
z2Tests listing an object with two trailing slashes.z//r
  r  r9   r   r  Tr   Nr  r   s      rs   &test_recursive_list_trailing_two_slashz-TestLs.test_recursive_list_trailing_two_slash  so     ""$JO
A.^^T4j)9:$^OF 	MM$z"T)62r   c                      j                         d}d} j                  |d        j                  |d        j                  d        j                  dt	        d      gdd	
      } j
                  rd}nd} j                  |j                  t	                    |       t        t        dd	       fd       } |        y)zATests that an object name with a wildcard does not infinite loop.z
wildcard*/zwildcard10/foor
  r  r:   r   z	wildcard*Tr9   r   zPCloud folders named with wildcards are not supported. API returned {}/wildcard*/z.Cloud folder {}/wildcard*/ contains a wildcardr;   r   c                  j    j                  ddt        d      gd      } j                  | d       y )Nr   rA  z**Tr   r;   )r   r   rm  r   s    rs   _Checkz+TestLs.test_wildcard_prefix.<locals>._Check  s9    ~~tT4
D+AB,0  2f
&!$r   N)
r   r  r   r   r   _use_gcloud_storager   r   r0   r   )rb   wildcard_folder_objectobject_matching_folderr  warning_messager  r   s   `     @rs   test_wildcard_prefixzTestLs.test_wildcard_prefix  s    ""$J)-"8%  ' 	"8%  ' 	
A.^^T4
K#@A*.,-  /F 7o IoMM/((j)9:FC >3% 4%
 Hr   z%S3 anonymous access is not supported.c                 J   | j                         }| j                  |dd      }| j                  dddt        |      gd       | j	                         5  | j                  d	d
t        |      gd      }| j                  t        |      |       d d d        y # 1 sw Y   y xY w)N	permittedr
  r  aclr   zpublic-readTr  r   rG  r   )r   r  r   r   SetAnonymousBotoCredsr   )rb   r   r(  r   s       rs   .test_get_object_without_list_bucket_permissionz5TestLs.test_get_object_without_list_bucket_permission  s     ""$J""j/:,2 # 4J 	NNE5-$& $  & 
	#	#	%~~tT4
+;<,0  2f
mmD$f- 
&	%	%s   ;BB"z7S3 customer-supplied encryption keys are not supported.c                      j                   t        j                  k(  rt        j                  d      S  j                  dt        t              t        ddt        fg      5  t        t        dd       fd	       } |        d d d        t        t        dd       fd
       } |        t        ddt        fg      5   |        d d d        y # 1 sw Y   OxY w# 1 sw Y   y xY w)Nz3gsutil does not support encryption with the XML APIr@   )rN  r  encryption_keyr{   r  r;   r9   r   c                      j                  ddt              gd      } j                  t        |        j                  t        |        j                  t        j                  d      |        y )Nr   rG  Tr   ascii)r   r   r   r   r   r%   decoder   r(  rb   s    rs   _ListExpectDecryptedz?TestLs.test_list_encrypted_object.<locals>._ListExpectDecrypted  s_    tT*-= >.2   42F;5v>5<<WEvNr   c                  
   j                  ddt              gd      } j                  t        |        j                  t        |        j                  d|        j                  t        j                  d      |        y )Nr   rG  Tr   	encryptedr  )r   r   r   r   r   r   r%   r  r  s    rs   _ListExpectEncryptedz?TestLs.test_list_encrypted_object.<locals>._ListExpectEncrypted  sq    ~~tT4
+;<,0  2f
3V<
6?
mmK(
mm3::7CVLr   )rP   r	   rQ   r,   rR   r  r   r$   r   r0   r   r&   )rb   r  r  r(  s   `  @rs   test_list_encrypted_objectz!TestLs.test_list_encrypted_object  s    }}']]
?A A""u,D2F # HJ
 
*: 4 6 7 
8 ^115O 6O 
8 >3M 4M  
*: 4 6 7 
8
8 
87
8 
86
8 
8s   $#CC!C!C*c                      j                          j                  dt        t                j                  dt        t
                j                  dt        t                j                  dt        t                j                  dt               t        dd	t        fdd
t        fddt        fg      5  t        t        dd       fd       } |        ddd       y# 1 sw Y   yxY w)z;Tests listing objects with various encryption interactions.r@   )r   rN  r  r  rK   foo3foo4foo5r  r{   r  decryption_key1decryption_key2r;   r9   r   c                  H   j                  ddt              gd      } j                  t        |        j                  t        |        j                  t        j                  d      |        j                  t        |        j                  t        |        j                  d|        j                  t        j                  d      |        j                  t        |        j                  t        |        j                  t        j                  d      |        j                  t        |        j                  t        |        j                  t!        j                  d      |        j                  t"        |        j                  t$        |        y)zValidates object listing.r   rG  Tr   r  r  N)r   r   r   r   r   r%   r  r   r   r   r'   r   r   r)   r    r   r+   r#   r"   r   s    rs   _ListExpectMixedz;TestLs.test_list_mixed_encryption.<locals>._ListExpectMixed  s9    tT*-= >.2   42F;5v>5<<WEvN5v>8&Ak6*5<<WEvN2F;5v>5<<WEvN2F;5v>5<<WEvN2F;5v>r   N)r   r  r   r$   r   r&   r   r(   r   r*   r!   r   r0   r   )rb   r  r   s   ` @rs   test_list_mixed_encryptionz!TestLs.test_list_mixed_encryption  s    ""$J"'7%9  ; 	"(7%9  ; 	"(7%9  ; 	"(7%9  ; 	"(7  9 
	#%9:	$&:;	$&:; 
 ^115? 6?( 7
 
 
s   #C..C7c                 T    | j                  g ddd      }| j                  d|       y )N)r   z-p   ãzgs://fobarbazr9   T)r   r   zInvalid non-ASCII)r   r   r  s     rs   test_non_ascii_project_failsz#TestLs.test_non_ascii_project_fails'  s/    ^^?,-*.  0F 	MM%v.r   c           	      Z   | j                   j                  t        d       t        j                  j
                  t        j                  j                        }| j                   j                  |t        j                  j                        }| j                  ddd|t        |      g       |S )Nr  kms
encryptionz-k)kms_apiCreateKeyRingr
   testcaseKmsTestingResourcesKEYRING_NAMEKEYRING_LOCATIONCreateCryptoKeyCONSTANT_KEY_NAMEr   r   )rb   r   keyring_fqnkey_fqns       rs   set_default_kms_key_on_bucketz$TestLs.set_default_kms_key_on_bucket-  s    ,,,,$$$11-->> - @K ll**X11CCEG 	NNE<wZ8HIJNr   c                    | j                         }| j                  ddt        |      gd      }| j                  |d       | j	                  |      }| j                  ddt        |      gd      }| j                  |d|z         y )Nr   r~   Tr   zDefault KMS key:\s+NonezDefault KMS key:\s+%s)r   r   r   r   r  )rb   r   r   r  s       rs   &test_default_kms_key_listed_for_bucketz-TestLs.test_default_kms_key_listed_for_bucket:  s     ""$J ^^T5$z*:;4^PFV78 00<G^^T5$z*:;4^PFV5?@r   c                     | j                         }| j                  |      }| j                  |dd|      }| j                  ddt	        |      gd      }| j                  |d|z         y )	Nr@   r
  )r   rN  r  kms_key_namer   rG  Tr   zKMS key:\s+%s)r   r  r  r   r   r   )rb   r   r  r  r   s        rs   ,test_kms_key_listed_for_kms_encrypted_objectz3TestLs.test_kms_key_listed_for_kms_encrypted_objectH  sw     ""$J00<G:,1)/-4   6G
 ^^T4g7t^LFV-78r   c                 &   | j                  d      }| j                  ddt        |      gd      }| j                  |d       | j                  dd	t        |      g       | j                  ddt        |      gd      }| j	                  |d
       y )Nr9   )retention_period_in_secondsr   r~   Tr   zRetention Policy\:\s*Present	retentionclearzRetention Policy:)CreateBucketWithRetentionPolicyr   r   r   r   r   s      rs   test_list_retention_policyz!TestLs.test_list_retention_policyW  s     55$% 6 'J^^T5$z*:;4^PFV<=NNK$z*:;<^^T5$z*:;4^PF 45r   c                 `   | j                         }| j                  dddt        |      g       | j                  ddt        |      gd      }| j                  |d       | j                  ddd	t        |      g       | j                  ddt        |      gd      }| j	                  |d
       y )Nr  zevent-defaultr   r   r~   Tr   z"Default Event-Based Hold:\t* *TruereleasezDefault Event-Based Hold)r   r   r   r   r   r   s      rs   "test_list_default_event_based_holdz)TestLs.test_list_default_event_based_holdc  s     ""$JNNK%j9IJK^^T5$z*:;4^PFVBCNNK)T*=MNO^^T5$z*:;4^PF ;<r   c                 d   | j                  d      }| j                  dddt        |      g       | j                  ddt        |      gd	      }| j                  |d
       | j                  dddt        |      g       | j                  ddt        |      gd	      }| j	                  |d
       y )N   contentr@  r  tempr   r   rG  Tr   zTemporary Holdr  r  r   r   r   r   rb   r(  r   s      rs   test_list_temporary_holdzTestLs.test_list_temporary_holdo  s     ""J"7JNNKZ0@AB^^T4j)9:$^OFV./NNKD4DEF^^T4j)9:$^OF 12r   c                 d   | j                  d      }| j                  dddt        |      g       | j                  ddt        |      gd	      }| j                  |d
       | j                  dddt        |      g       | j                  ddt        |      gd	      }| j	                  |d
       y )Nr  r@  r  eventr   r   rG  Tr   zEvent-Based Holdr  r!  r"  s      rs   test_list_event_based_holdz!TestLs.test_list_event_based_hold{  s     ""J"7JNNK%j1ABC^^T4j)9:$^OFV01NNK)T*5EFG^^T4j)9:$^OF 34r   z:public access prevention is not supported for the XML API.z9public access prevention is not supported for S3 buckets.c                 $   | j                         }| j                  ddt        |      gd      }| j                  |d       | j                  dddt        |      g       | j                  ddt        |      gd      }| j                  |d	       y )
Nr   r~   Tr   z3Public access prevention:\s*(unspecified|inherited)papr   enforcedz$Public access prevention:\s*enforcedr   r   r   r   r   s      rs   "test_list_public_access_preventionz)TestLs.test_list_public_access_prevention  s     ""$J^^T5$z*:;4^PFVKM 	NNE5*d:.>?@^^T5$z*:;4^PFVDEr   z%RPO is not supported for the XML API.z$RPO is not supported for S3 buckets.c                    | j                  d      }| j                  ddt        |      gd      }| j                  ddd	t        |      g       | j                  ddt        |      gd      }| j                  |d
       y )Nnam4r  r   r~   Tr   rpor   ASYNC_TURBOzRPO:\t\t\t\tASYNC_TURBOr*  r   s      rs   test_list_Lb_displays_rpoz TestLs.test_list_Lb_displays_rpo  s     ""F"3J^^T5$z*:;4^PF 	NNE5-j1ABC^^T5$z*:;4^PFV78r   z4Custom Dual Region is not supported for the XML API.z3Custom Dual Region is not supported for S3 buckets.c                     d| j                  d      z   }| j                  ddd|gd       | j                  dd	|gd
      }| j                  |d       y )Nzgs://rD   mbz--placementzus-central1,us-west1r   )r   r   r~   Tr   z5Placement locations:\t\t\['US-CENTRAL1', 'US-WEST1'\])r   r   r   )rb   rx   r   s      rs   7test_list_Lb_displays_custom_dual_region_placement_infoz>TestLs.test_list_Lb_displays_custom_dual_region_placement_info  sf     D--h77KNND-)?M#$  &^^T5+6d^KFVMOr   z+Autoclass is not supported for the XML API.z*Autoclass is not supported for S3 buckets.c                 $   | j                         }| j                  ddt        |      gd      }| j                  d|       | j                  dddt        |      g       | j                  ddt        |      gd      }| j	                  |d	       y )
Nr   r~   Tr   	Autoclass	autoclassr   r   zAutoclass:\t*Enabled on .+)r   r   r   r   r   r   s      rs   test_list_autoclasszTestLs.test_list_autoclass  s     ""$J^^T5$z*:;4^PF[&)NNKd:.>?@^^T5$z*:;4^PFV:;r   N)Er   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r#  r%  r   r   r)  r-  r   r   r>  rD  rI  rV  rb  rg  rw  r  r  r  r,   rR   r  r  r  r  r  skipIfr1   r  r  r  r  r  r  r  r  r  r  r  r  r  KMS_XML_SKIP_MSGr  r  BUCKET_LOCK_SKIP_MSGr  r  r#  r&  r+  r0  r3  r7  r   r   rs   r   r      s}   )/	)2V19:!(0	$ BCA DA
 BCA DA "#GH: I $: "#GH
 I $
 =>Z[ \ ?(556 KLLM. N M."$6:%N*" GH; I;" 8==GH895 : I  5 GHJ IJ0 GHJ IJ0 GH@AL B IL00d 8??:OQAQAB.,&"  $ %2%2
6  $ %3%3B 45. 6.  FG& H&P FG6 H6p/ 
A   
A 9   9 "#!"6 # $6 "#!"= # $= "#!"3 # $3 "#!"5 # $5 JKHIF J LF 5634
9 5 7
9 DEBCO D FO ;<9:< ; =<r   r   )Wr   
__future__r   r   r   r   r   r2  r   rY   r6  r  r  r   r  gslib.commandsr   gslib.cs_api_mapr	   gslib.project_idr
   gslib.tests.testcasetestsr  )gslib.tests.testcase.integration_testcaser   r   r   r   gslib.tests.utilr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   "gslib.third_party.storage_apitoolsr-   rS   gslib.utils.constantsr.   gslib.utils.ls_helperr/   gslib.utils.retry_utilr0   gslib.utils.system_utilr1   gslib.utilsr2   sixr3   r4   	six.movesr5   r9  r:  GsUtilUnitTestCaser7   ShimUnitTestBaser   GsUtilIntegrationTestCaser   r   r   rs   <module>rN     s    & %  '  	  	   
    ( . ' ' ? A ? @ * 0 ) 1 2 , 5 < 9 5 < 9 5 < 9 5 < 9 5 < 9 1 < 1 < 1 < 1 < % W & : ( . ! % VV_	5 6 < O j8,, j8Z/22 /([<X// [<r   