2015-01-02 12:34:40 -05:00
|
|
|
Shindo.tests('AWS::Glacier | glacier tree hash calcuation', ['aws']) do
|
2014-12-30 17:25:09 -05:00
|
|
|
|
|
|
|
tests('tree_hash(single part < 1MB)') do
|
2016-06-23 01:23:19 -04:00
|
|
|
returns(OpenSSL::Digest::SHA256.hexdigest('')) { Fog::AWS::Glacier::TreeHash.digest('')}
|
2014-12-30 17:25:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('tree_hash(multibyte characters)') do
|
|
|
|
body = ("\xC2\xA1" * 1024*1024)
|
|
|
|
body.force_encoding('UTF-8') if body.respond_to? :encoding
|
|
|
|
|
2016-06-23 01:23:19 -04:00
|
|
|
expected = OpenSSL::Digest::SHA256.hexdigest(
|
|
|
|
OpenSSL::Digest::SHA256.digest("\xC2\xA1" * 1024*512) + OpenSSL::Digest::SHA256.digest("\xC2\xA1" * 1024*512)
|
2014-12-30 17:25:09 -05:00
|
|
|
)
|
|
|
|
returns(expected) { Fog::AWS::Glacier::TreeHash.digest(body)}
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('tree_hash(power of 2 number of parts)') do
|
|
|
|
body = ('x' * 1024*1024) + ('y'*1024*1024) + ('z'*1024*1024) + ('t'*1024*1024)
|
2016-06-23 01:23:19 -04:00
|
|
|
expected = OpenSSL::Digest::SHA256.hexdigest(
|
|
|
|
OpenSSL::Digest::SHA256.digest(
|
|
|
|
OpenSSL::Digest::SHA256.digest('x' * 1024*1024) + OpenSSL::Digest::SHA256.digest('y' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
) +
|
2016-06-23 01:23:19 -04:00
|
|
|
OpenSSL::Digest::SHA256.digest(
|
|
|
|
OpenSSL::Digest::SHA256.digest('z' * 1024*1024) + OpenSSL::Digest::SHA256.digest('t' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
returns(expected) { Fog::AWS::Glacier::TreeHash.digest(body)}
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('tree_hash(non power of 2 number of parts)') do
|
|
|
|
body = ('x' * 1024*1024) + ('y'*1024*1024) + ('z'*1024*1024)
|
2016-06-23 01:23:19 -04:00
|
|
|
expected = OpenSSL::Digest::SHA256.hexdigest(
|
|
|
|
OpenSSL::Digest::SHA256.digest(
|
|
|
|
OpenSSL::Digest::SHA256.digest('x' * 1024*1024) + OpenSSL::Digest::SHA256.digest('y' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
) +
|
2016-06-23 01:23:19 -04:00
|
|
|
OpenSSL::Digest::SHA256.digest('z' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
returns(expected) { Fog::AWS::Glacier::TreeHash.digest(body)}
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('multipart') do
|
|
|
|
tree_hash = Fog::AWS::Glacier::TreeHash.new
|
|
|
|
part = ('x' * 1024*1024) + ('y'*1024*1024)
|
|
|
|
returns(Fog::AWS::Glacier::TreeHash.digest(part)) { tree_hash.add_part part }
|
|
|
|
|
|
|
|
tree_hash.add_part('z'* 1024*1024 + 't'*1024*1024)
|
|
|
|
|
2016-06-23 01:23:19 -04:00
|
|
|
expected = OpenSSL::Digest::SHA256.hexdigest(
|
|
|
|
OpenSSL::Digest::SHA256.digest(
|
|
|
|
OpenSSL::Digest::SHA256.digest('x' * 1024*1024) + OpenSSL::Digest::SHA256.digest('y' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
) +
|
2016-06-23 01:23:19 -04:00
|
|
|
OpenSSL::Digest::SHA256.digest(
|
|
|
|
OpenSSL::Digest::SHA256.digest('z' * 1024*1024) + OpenSSL::Digest::SHA256.digest('t' * 1024*1024)
|
2014-12-30 17:25:09 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
returns(expected) { tree_hash.hexdigest}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|