Initial commit
This commit is contained in:
31
pkg/auth/validator_test.go
Normal file
31
pkg/auth/validator_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"encoding/base64"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLoadValidator_RSAFromEnv(t *testing.T) {
|
||||
key, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
require.NoError(t, err)
|
||||
|
||||
store := KeyStore{PublicKey: &key.PublicKey}
|
||||
path := t.TempDir() + "/pub.pem"
|
||||
require.NoError(t, store.SavePublicKey(path))
|
||||
|
||||
pemBytes, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Setenv("JWT_PUBLIC_KEY", base64.StdEncoding.EncodeToString(pemBytes))
|
||||
|
||||
validator, err := LoadValidator("config/ed25519-key.pub")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ValidatorRSA, validator.Mode)
|
||||
assert.NotNil(t, validator.RSA)
|
||||
}
|
||||
Reference in New Issue
Block a user