diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-28 16:51:56 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-28 16:51:56 -0600 |
| commit | 059a87a80227426f854256139bbbc7309bdb6fa0 (patch) | |
| tree | ebd83f6a0f57133c9a34fffaf8c20ed6d62d9250 /pkg/pls | |
| parent | 37adeb5437d0f62f5dbc137bb98addcb9d891238 (diff) | |
feat: redirect to login page when session is established
Diffstat (limited to 'pkg/pls')
| -rw-r--r-- | pkg/pls/nonce.go | 11 | ||||
| -rw-r--r-- | pkg/pls/random.go | 12 | ||||
| -rw-r--r-- | pkg/pls/random_test.go | 17 |
3 files changed, 29 insertions, 11 deletions
diff --git a/pkg/pls/nonce.go b/pkg/pls/nonce.go deleted file mode 100644 index aeab640..0000000 --- a/pkg/pls/nonce.go +++ /dev/null @@ -1,11 +0,0 @@ -package pls - -import ( - "crypto/rand" -) - -func GenerateNonce(size int) string { - nonceBytes := make([]byte, size) - rand.Read(nonceBytes) - return string(nonceBytes) -} diff --git a/pkg/pls/random.go b/pkg/pls/random.go new file mode 100644 index 0000000..f7935f1 --- /dev/null +++ b/pkg/pls/random.go @@ -0,0 +1,12 @@ +package pls + +import ( + "crypto/rand" + "encoding/hex" +) + +func GenerateRandomHex(length int) string { + nonceBytes := make([]byte, length) + rand.Read(nonceBytes) + return hex.EncodeToString(nonceBytes) +} diff --git a/pkg/pls/random_test.go b/pkg/pls/random_test.go new file mode 100644 index 0000000..56dfb2d --- /dev/null +++ b/pkg/pls/random_test.go @@ -0,0 +1,17 @@ +package pls + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGenerateRandomHex(t *testing.T) { + t.Run("returns a random nonce each time", func(t *testing.T) { + item := GenerateRandomHex(32) + + require.NotEmpty(t, item) + assert.NotEqual(t, item, GenerateRandomHex(32)) + }) +} |
