
    |                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr   " S S\5      rg)z!Unit tests for encryption_helper.    )absolute_import)print_function)division)unicode_literalsN)CommandException)GsUtilUnitTestCase)SetBotoConfigForTest)#Base64Sha256FromBase64EncryptionKey)CryptoKeyWrapperFromKey)FindMatchingCSEKInBotoConfigc                   0    \ rS rSrSrS rS rS rS rSr	g)	TestEncryptionHelper#   z+Unit tests for encryption helper functions.c           	         / n/ n[        SS5       Hh  n UR                  [        R                  " [        R
                  " S5      5      R                  S5      5        UR                  SSU-  XS-
     45        Mj     [        U5         U R                  [        [        US   5      [        R                  5      5        U R                  [        [        US   5      [        R                  5      5        U R                  [        [        US	   5      [        R                  5      5        S
S
S
5        [!        U5      nUR#                  5         [        U5         U R                  [        [        US   5      [        R                  5      5        U R                  [        [        US   5      [        R                  5      5        S
S
S
5        g
! [         aL    UR                  [        R                  " [        R
                  " S5      5      R                  S5      5         GNf = f! , (       d  f       GN= f! , (       d  f       g
= f)z?Tests a config file with the maximum number of decryption keys.   f          
GSUtilzdecryption_key%sr   c   d   N)rangeappendbase64encodebytesosurandomrstripAttributeErrorencodestringr	   assertIsNotNoner   r
   botoconfigassertIsNonelistpop)selfkeysboto_101_key_configiboto_100_key_configs        5platform/gsutil/gslib/tests/test_encryption_helper.pytestMaxDecryptionKeys*TestEncryptionHelper.testMaxDecryptionKeys&   s   D1c]GF&&rzz"~6==eDE   '!+Ta%[
9;  
1	2

&1$q':DKKIJ 
&1$r(;T[[JK 
&1$s)<dkkKL 
3 23	1	2

&1$q':DKKIJ 
&1$r(;T[[JK	 
3	2'  GF''

27>>uEFG
 
3	2 
3	2s-   AG
B H#A+H5
AH H #
H25
Ic           	      (   / n[        S5       HL  n UR                  [        R                  " [        R
                  " S5      5      R                  S5      5        MN     SSUS   4SSUS   4SS	US
   4/n[        U5         U R                  [        [        US   5      [        R                  5      5        U R                  [        [        US   5      [        R                  5      5        U R                  [        [        US
   5      [        R                  5      5        SSS5        g! [         aM    UR                  [        R                  " [        R
                  " S5      5      R                  S5      5         GMq  f = f! , (       d  f       g= f)zATests a config file with non-sequential decryption key numbering.   r   r   r   decryption_key4   decryption_key1r   decryption_key2r   N)r   r   r   r   r   r   r   r   r    r	   r$   r   r
   r"   r#   r!   )r'   r(   _boto_configs       r,   testNonSequentialDecryptionKeys4TestEncryptionHelper.testNonSequentialDecryptionKeysI   sZ   D1XGF&&rzz"~6==eDE  /a9/a9/a9;K 
k	* 
&1$q':DKKIJ 
&1$q':DKKIJ 
&1$q':DKKIJ 
+	*  GF''

27>>uEFFG 
+	*s    AD) B F)AF ?F 
Fc                     SnU R                  [        5       n[        U5        S S S 5        U R                  SWR                  R
                  5        g ! , (       d  f       N5= f)Nz,aP7KbmxLqDw1SWHeKvlfKOVgNRNNZc8L2sFz8ybLN===z>Configured encryption_key or decryption_key looked like a CSEKassertRaisesr   r   assertIn	exceptionreasonr'   invalid_keycms      r,   "testInvalidCSEKConfigurationRaises7TestEncryptionHelper.testInvalidCSEKConfigurationRaisesc   sJ    @K			+	,k* 
-MMH
 
-	,   A
A!c                     SnU R                  [        5       n[        U5        S S S 5        U R                  SWR                  R
                  5        g ! , (       d  f       N5= f)Nzmprojects/my-project/locations/some-location/keyRings/keyring/cryptoKeyWHOOPS-INVALID-RESOURCE-PORTION/somekeyz>Configured encryption_key or decryption_key looked like a CMEKr:   r?   s      r,   "testInvalidCMEKConfigurationRaises7TestEncryptionHelper.testInvalidCMEKConfigurationRaisesk   sQ    	;  
		+	,k* 
-MMH
 
-	,rD    N)
__name__
__module____qualname____firstlineno____doc__r-   r7   rB   rF   __static_attributes__rH       r,   r   r   #   s    3!KFJ4rO   r   )rM   
__future__r   r   r   r   r   r   sixr"   gslib.exceptionr   "gslib.tests.testcase.unit_testcaser   gslib.tests.utilr	   gslib.utils.encryption_helperr
   r   r   r   rH   rO   r,   <module>rV      sC    ( & %  '  	 
  , A 1 M A FP- PrO   