mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 01:44:41 +01:00
6a9ae32012
This splits config.go into ui.go for the user interface functions and authorize.go for the implementation of `rclone authorize`. It also moves the tests into the correct places (including one from obscure which was in the wrong place).
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package obscure
|
|
|
|
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")
|
|
|
|
}
|
|
}
|
|
|
|
func TestReveal(t *testing.T) {
|
|
for _, test := range []struct {
|
|
in string
|
|
want string
|
|
iv string
|
|
}{
|
|
{"YWFhYWFhYWFhYWFhYWFhYQ", "", "aaaaaaaaaaaaaaaa"},
|
|
{"YWFhYWFhYWFhYWFhYWFhYXMaGgIlEQ", "potato", "aaaaaaaaaaaaaaaa"},
|
|
{"YmJiYmJiYmJiYmJiYmJiYp3gcEWbAw", "potato", "bbbbbbbbbbbbbbbb"},
|
|
} {
|
|
cryptRand = bytes.NewBufferString(test.iv)
|
|
got, err := Reveal(test.in)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.want, got)
|
|
// Now the Must variants
|
|
cryptRand = bytes.NewBufferString(test.iv)
|
|
got = MustReveal(test.in)
|
|
assert.Equal(t, test.want, got)
|
|
|
|
}
|
|
}
|
|
|
|
// Test some error cases
|
|
func TestRevealErrors(t *testing.T) {
|
|
for _, test := range []struct {
|
|
in string
|
|
wantErr string
|
|
}{
|
|
{"YmJiYmJiYmJiYmJiYmJiYp*gcEWbAw", "base64 decode failed when revealing password - is it obscured?: illegal base64 data at input byte 22"},
|
|
{"aGVsbG8", "input too short when revealing password - is it obscured?"},
|
|
{"", "input too short when revealing password - is it obscured?"},
|
|
} {
|
|
gotString, gotErr := Reveal(test.in)
|
|
assert.Equal(t, "", gotString)
|
|
assert.Equal(t, test.wantErr, gotErr.Error())
|
|
}
|
|
}
|