1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-23 00:40:46 +02:00

Add EncryptInto/DecryptInto Unit Tests

This commit is contained in:
Nick Meves
2020-06-01 16:19:27 -07:00
parent e43c65cc76
commit 014fa682be
6 changed files with 124 additions and 77 deletions

View File

@ -17,14 +17,14 @@ func timePtr(t time.Time) *time.Time {
return &t
}
func NewCipher(secret []byte) (encryption.Cipher, error) {
func newTestCipher(secret []byte) (encryption.Cipher, error) {
return encryption.NewBase64Cipher(encryption.NewCFBCipher, secret)
}
func TestSessionStateSerialization(t *testing.T) {
c, err := NewCipher([]byte(secret))
c, err := newTestCipher([]byte(secret))
assert.Equal(t, nil, err)
c2, err := NewCipher([]byte(altSecret))
c2, err := newTestCipher([]byte(altSecret))
assert.Equal(t, nil, err)
s := &sessions.SessionState{
Email: "user@domain.com",
@ -57,9 +57,9 @@ func TestSessionStateSerialization(t *testing.T) {
}
func TestSessionStateSerializationWithUser(t *testing.T) {
c, err := NewCipher([]byte(secret))
c, err := newTestCipher([]byte(secret))
assert.Equal(t, nil, err)
c2, err := NewCipher([]byte(altSecret))
c2, err := newTestCipher([]byte(altSecret))
assert.Equal(t, nil, err)
s := &sessions.SessionState{
User: "just-user",
@ -205,7 +205,7 @@ func TestDecodeSessionState(t *testing.T) {
eJSON, _ := e.MarshalJSON()
eString := string(eJSON)
c, err := NewCipher([]byte(secret))
c, err := newTestCipher([]byte(secret))
assert.NoError(t, err)
testCases := []testCase{