Files
GoCalGoo/internal/auth/pkce_test.go

33 lines
835 B
Go

package auth
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewPKCEChallenge(t *testing.T) {
p, err := NewPKCEChallenge()
require.NoError(t, err)
assert.NotEmpty(t, p.Verifier)
assert.NotEmpty(t, p.Challenge)
assert.Equal(t, "S256", p.Method)
assert.NotEqual(t, p.Verifier, p.Challenge)
}
func TestPKCEChallengeUniqueness(t *testing.T) {
p1, err := NewPKCEChallenge()
require.NoError(t, err)
p2, err := NewPKCEChallenge()
require.NoError(t, err)
assert.NotEqual(t, p1.Verifier, p2.Verifier)
assert.NotEqual(t, p1.Challenge, p2.Challenge)
}
func TestComputeChallenge(t *testing.T) {
verifier := "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
expected := "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"
assert.Equal(t, expected, computeChallenge(verifier))
}