You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-08-10 22:51:31 +02:00
Session-Cookie Support (#1713)
* Create session cookie when cookie-expire set 0 * Fix format * add test * fix lint error * fix test code * fix conflicted test case * update test case of cookie expiration * update tests of csrf cookies * update docs * Update docs/docs/configuration/overview.md Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> --------- Co-authored-by: tanuki884 <morkazuk@fsi.co.jp> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
@@ -7,8 +7,11 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -103,6 +106,30 @@ func TestSignAndValidate(t *testing.T) {
|
||||
assert.False(t, checkSignature(sha1sig, seed, key, "tampered", epoch))
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
seed := "0123456789abcdef"
|
||||
key := "cookie-name"
|
||||
value := base64.URLEncoding.EncodeToString([]byte("I am soooo encoded"))
|
||||
epoch := int64(123456789)
|
||||
epochStr := strconv.FormatInt(epoch, 10)
|
||||
|
||||
sha256sig, err := cookieSignature(sha256.New, seed, key, value, epochStr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
cookie := &http.Cookie{
|
||||
Name: key,
|
||||
Value: value + "|" + epochStr + "|" + sha256sig,
|
||||
}
|
||||
|
||||
validValue, timestamp, ok := Validate(cookie, seed, 0)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, timestamp, time.Unix(epoch, 0))
|
||||
|
||||
expectedValue, err := base64.URLEncoding.DecodeString(value)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, validValue, expectedValue)
|
||||
}
|
||||
|
||||
func TestGenerateRandomASCIIString(t *testing.T) {
|
||||
randomString, err := GenerateRandomASCIIString(96)
|
||||
assert.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user