@@ -58,38 +58,59 @@ module EC2
58
58
end
59
59
60
60
describe '#copy_snapshot' do
61
+ let ( :client ) do
62
+ Client . new (
63
+ region : destination_region ,
64
+ credentials : Credentials . new ( 'akid' , 'secret' ) ,
65
+ stub_responses : true
66
+ )
67
+ end
61
68
62
- it 'requires a source shapshot region' do
63
- ec2 = Client . new ( stub_responses : true )
64
- expect {
65
- ec2 . copy_snapshot
66
- } . to raise_error ( ArgumentError )
69
+ let ( :kms_key_id ) { '238f8ec9-420a-0690-8ec9-009f34fc3ef5' }
70
+ let ( :source_snapshot_id ) { 'snap-1234567890abcdef0' }
71
+ let ( :source_region ) { 'us-east-1' }
72
+ let ( :destination_region ) { 'us-west-2' }
73
+
74
+ let ( :params ) do
75
+ {
76
+ kms_key_id : kms_key_id ,
77
+ source_region : source_region ,
78
+ encrypted : true ,
79
+ source_snapshot_id : 'snap-1234567890abcdef0' ,
80
+ destination_region : 'ca-central-1' # should be ignored
81
+ }
67
82
end
68
83
69
- it 'manages :destination_region and :presigned_url' do
70
- now = Time . now
71
- allow ( Time ) . to receive ( :now ) . and_return ( now )
72
- dest_region = 'us-west-1'
73
- src_region = 'us-west-2'
74
- snap_id = 'id'
75
-
76
- ec2 = Client . new ( region : dest_region , stub_responses : true )
77
- resp = ec2 . copy_snapshot ( {
78
- source_region : src_region ,
79
- source_snapshot_id : snap_id ,
80
- } )
84
+ before do
85
+ allow ( Time ) . to receive ( :now ) . and_return ( Time . utc ( 2023 , 1 , 24 ) )
86
+ end
81
87
82
- expect ( resp . context . params [ :destination_region ] ) . to eq ( dest_region )
88
+ it 'requires a source region' do
89
+ expect { client . copy_snapshot }
90
+ . to raise_error ( ArgumentError , /Source region/ )
91
+ end
83
92
84
- presigned_query_params = CGI . parse ( resp . context . params [ :presigned_url ] )
85
- expect ( resp . context . params [ :presigned_url ] ) . to match ( /^https:\/ \/ ec2\. #{ src_region } .amazonaws.com/ )
86
- expect ( presigned_query_params [ 'DestinationRegion' ] ) . to eq ( [ dest_region ] )
87
- expect ( presigned_query_params [ 'SourceRegion' ] ) . to eq ( [ src_region ] )
88
- expect ( presigned_query_params [ 'SourceSnapshotId' ] ) . to eq ( [ snap_id ] )
93
+ it 'populates :presigned_url' do
94
+ resp = client . copy_snapshot ( params )
89
95
96
+ expect ( resp . context . params [ :destination_region ] )
97
+ . to eq ( destination_region )
90
98
91
- end
99
+ presigned_url = resp . context . params [ :presigned_url ]
100
+ presigned_url_params = CGI . parse ( presigned_url . split ( '?' ) . last )
101
+
102
+ expect ( presigned_url )
103
+ . to match ( /^https:\/ \/ ec2\. #{ source_region } .amazonaws.com/ )
92
104
105
+ expect ( presigned_url_params [ 'Action' ] ) . to eq ( [ 'CopySnapshot' ] )
106
+ expect ( presigned_url_params [ 'Version' ] ) . to eq ( [ '2016-11-15' ] )
107
+ expect ( presigned_url_params [ 'DestinationRegion' ] ) . to eq ( [ destination_region ] )
108
+ expect ( presigned_url_params [ 'SourceRegion' ] ) . to eq ( [ source_region ] )
109
+ expect ( presigned_url_params [ 'SourceSnapshotId' ] ) . to eq ( [ source_snapshot_id ] )
110
+
111
+ expect ( presigned_url_params [ 'X-Amz-Signature' ] )
112
+ . to eq ( [ 'c34b30736cc5cd6a10af02c1edb50aed3d7424577644fb912f676846a65311cf' ] )
113
+ end
93
114
end
94
115
95
116
describe '#wait_until' do
0 commit comments