
                            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Zddl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Z ej*                  ej,                   d       G d dej.                               Zy)zaIntegration tests for cp STET binary integration.

Could go with cp tests but that file is bulky.    )absolute_import)division)print_function)unicode_literalsN)storage_url)testcase)util)ObjectToURI)unittest)system_util)temporary_file_utilz#!/bin/sh
if [ "$#" -ne 5 ]; then
  echo "Expected 5 arguments. Got $#."
  exit 1
fi

echo "subcommand: $1
config file: $2
blob id: $3
in file: $4
out file: $5" > $5
z STET binary supports only Linux.c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )
TestStetCpz6Integration tests for cp integration with STET binary.c                 >   t         t        |           | j                  t              | _        t        j                  | j
                        }t        j                  | j
                  |j                  t        j                  z         | j                         | _        y )Ncontents)superr   setUpCreateTempFileFAKE_STET_BINARYstet_binary_pathosstatchmodst_modeS_IEXECstet_config_path)selfcurrent_stat	__class__s     +platform/gsutil/gslib/tests/test_stet_cp.pyr   zTestStetCp.setUp6   so    	*d!# //9I/JD774001LHHT""L$8$84<<$GH //1D    c                 N   | j                         }| j                  d      }| j                  ddj                  | j                        ddj                  | j
                        dd|t        |      gd	      }| j                  d
|       | j                  dt        |      gd      }| j                  d|       | j                  dj                  | j
                        |       | j                  dj                  t        |            |       | j                  dj                  |      |       | j                  dj                  |      |       | j                  t        j                  j                  t        j                  t        j                   |                         y )Nzwill be rewrittenr   -oGSUtil:stet_binary_path={}GSUtil:stet_config_path={}cp--stetTreturn_stderr/4.0 B]cat)return_stdoutzsubcommand: encryptconfig file: --config-file={}blob id: --blob-id={}in file: {}out file: {}_.stet_tmp)CreateObjectr   	RunGsUtilformatr   r   suriassertNotInassertInassertFalser   pathexistsr   GetStetTempFileNamer   StorageUrlFromString)r   
object_uri	test_filestderrstdouts        r!   'test_encrypts_upload_if_stet_is_enabledz2TestStetCp.test_encrypts_upload_if_stet_is_enabled@   sl   ""$J##-@#AI^^*11$2G2GH$$++!!	#$((IZ	 +/  0F 	Y'^^UD$45T^JFMM'0MM1889N9NOMM)00j1ABFKMM-&&y16:MM*11)<fE
3300;=	>?r"   c                 t   | j                  d      }| j                         }| j                  ddj                  | j                        ddj                  | j
                        ddt        |      |gd	      }| j                  d
|       t        |      5 }|j                         }d d d        | j                  d       | j                  dj                  | j
                        |       | j                  dj                  t        |            |       | j                  dj                  |      |       | j                  dj                  |      |       | j                  t        j                  j                  t        j                   t#        j$                  |                         y # 1 sw Y   xY w)Nabcr   r$   r%   r&   r'   r(   Tr)   r+   zsubcommand: decryptr.   r/   r0   r1   )r2   r   r3   r4   r   r   r5   r6   openreadr7   r8   r   r9   r:   r   r;   r   r<   )r   r=   r>   r?   file_readerdownloaded_texts         r!   )test_decrypts_download_if_stet_is_enabledz4TestStetCp.test_decrypts_download_if_stet_is_enabled]   sv   ""E"2J##%I^^*11$2G2GH$$++!!	#$((Z)	 +/  0F 	Y'	iK#((*o 
MM'9MM1889N9NO!#MM)00j1AB!#MM-&&y1?CMM*11)<oN
3300;=	>? 
s   F--F7c                    | j                         }t        d      D ]  }| j                  |d        | j                         }t	        j
                  ddg      5  | j                  dddj                  | j                        dd	j                  | j                        d
dd|t        |      g
d      }| j                  d|       | j                  |d       ddd       y# 1 sw Y   yxY w)zETests that cp does not seek-ahead for bytes if file size will change.   s   123456)tmpdirr   )GSUtiltask_estimation_threshold1)rL   task_estimation_forceTruez-mr$   r%   r&   r'   z-rr(   Tr)   z18.0 B]z
2\.\d KiB]N)CreateTempDirranger   CreateBucketr	   SetBotoConfigForTestr3   r4   r   r   r5   r6   assertRegex)r   rK   _
bucket_urir?   s        r!   4test_does_not_seek_ahead_for_bytes_if_stet_transformz?TestStetCp.test_does_not_seek_ahead_for_bytes_if_stet_transform|   s    !F1X
)<  ""$J		"	"43$ 
 ~~
299##%&*,H,O,O''-)*.h
z
	 -1  2f y&) v}-+
 
 
s   A=C!!C*)	__name__
__module____qualname____doc__r   rA   rH   rX   __classcell__)r    s   @r!   r   r   2   s    >2?:?>.r"   r   )r\   
__future__r   r   r   r   r   r   gslibr   gslib.testsr   r	   gslib.tests.utilr
   r5   r   gslib.utilsr   r   r   skipIfIS_LINUXGsUtilIntegrationTestCaser    r"   r!   <module>rg      sw   2 '  % ' 	      0 % # +  [)))+MNf.33 f. Of.r"   