mirror of
https://github.com/rclone/rclone.git
synced 2024-12-03 14:03:41 +08:00
11da2a6c9b
The purpose of this is to make it easier to maintain and eventually to allow the rclone backends to be re-used in other projects without having to use the rclone configuration system. The new code layout is documented in CONTRIBUTING.
39 lines
950 B
Go
39 lines
950 B
Go
package config
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestObscure(t *testing.T) {
|
|
for _, test := range []struct {
|
|
in string
|
|
want string
|
|
iv string
|
|
}{
|
|
{"", "YWFhYWFhYWFhYWFhYWFhYQ", "aaaaaaaaaaaaaaaa"},
|
|
{"potato", "YWFhYWFhYWFhYWFhYWFhYXMaGgIlEQ", "aaaaaaaaaaaaaaaa"},
|
|
{"potato", "YmJiYmJiYmJiYmJiYmJiYp3gcEWbAw", "bbbbbbbbbbbbbbbb"},
|
|
} {
|
|
cryptRand = bytes.NewBufferString(test.iv)
|
|
got, err := Obscure(test.in)
|
|
cryptRand = rand.Reader
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.want, got)
|
|
recoveredIn, err := Reveal(got)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.in, recoveredIn, "not bidirectional")
|
|
// Now the Must variants
|
|
cryptRand = bytes.NewBufferString(test.iv)
|
|
got = MustObscure(test.in)
|
|
cryptRand = rand.Reader
|
|
assert.Equal(t, test.want, got)
|
|
recoveredIn = MustReveal(got)
|
|
assert.Equal(t, test.in, recoveredIn, "not bidirectional")
|
|
|
|
}
|
|
}
|