mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
crypt: fix tests after introduction of no data encryption
This commit is contained in:
parent
4216d55a05
commit
a80287effd
@ -1049,6 +1049,10 @@ func (o *ObjectInfo) Hash(ctx context.Context, hash hash.Type) (string, error) {
|
||||
}
|
||||
// if this is wrapping a local object then we work out the hash
|
||||
if srcObj.Fs().Features().IsLocal {
|
||||
if o.f.opt.NoDataEncryption {
|
||||
// If no encryption, just return the hash of the underlying object
|
||||
return srcObj.Hash(ctx, hash)
|
||||
}
|
||||
// Read the data and encrypt it to calculate the hash
|
||||
fs.Debugf(o, "Computing %v hash of encrypted source", hash)
|
||||
return o.f.computeHashWithNonce(ctx, o.nonce, srcObj, hash)
|
||||
|
@ -77,7 +77,11 @@ func testObjectInfo(t *testing.T, f *Fs, wrap bool) {
|
||||
enc, err := f.cipher.newEncrypter(inBuf, nil)
|
||||
require.NoError(t, err)
|
||||
nonce := enc.nonce // read the nonce at the start
|
||||
_, err = io.Copy(&outBuf, enc)
|
||||
if f.opt.NoDataEncryption {
|
||||
_, err = outBuf.WriteString(contents)
|
||||
} else {
|
||||
_, err = io.Copy(&outBuf, enc)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
var oi fs.ObjectInfo = obj
|
||||
@ -96,7 +100,12 @@ func testObjectInfo(t *testing.T, f *Fs, wrap bool) {
|
||||
assert.NotEqual(t, path, src.Remote())
|
||||
|
||||
// Test ObjectInfo.Hash
|
||||
wantHash := md5.Sum(outBuf.Bytes())
|
||||
var wantHash [md5.Size]byte
|
||||
if f.opt.NoDataEncryption {
|
||||
wantHash = md5.Sum([]byte(contents))
|
||||
} else {
|
||||
wantHash = md5.Sum(outBuf.Bytes())
|
||||
}
|
||||
gotHash, err := src.Hash(ctx, hash.MD5)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fmt.Sprintf("%x", wantHash), gotHash)
|
||||
|
Loading…
Reference in New Issue
Block a user