Fix PKCE code verifier generation to never use UTF-8 characters

- This could result in intermittent/random failures of PKCE enabled IdP's
This commit is contained in:
Braunson M
2022-11-18 20:37:14 -05:00
parent fd2807c091
commit f4f5b7756c
4 changed files with 42 additions and 5 deletions
+19
View File
@@ -7,7 +7,9 @@ import (
"encoding/base64"
"fmt"
"io"
"strings"
"testing"
"unicode"
"github.com/stretchr/testify/assert"
)
@@ -100,3 +102,20 @@ func TestSignAndValidate(t *testing.T) {
assert.False(t, checkSignature(sha256sig, seed, key, "tampered", epoch))
assert.False(t, checkSignature(sha1sig, seed, key, "tampered", epoch))
}
func TestGenerateRandomASCIIString(t *testing.T) {
randomString, err := GenerateRandomASCIIString(96)
assert.NoError(t, err)
// Only 8-bit characters
assert.Equal(t, 96, len([]byte(randomString)))
// All non-ascii characters removed should still be the original string
removedChars := strings.Map(func(r rune) rune {
if r > unicode.MaxASCII {
return -1
}
return r
}, randomString)
assert.Equal(t, removedChars, randomString)
}