Files
opencloud/services/auth-guest/pkg/config/config_test.go
T
André Duffeck 10b93edded Derive the guest session key from OC_JWT_SECRET
Replace AUTH_GUEST_SESSION_JWT_SECRET with a key derived via
HMAC-SHA256 from the reva JWT secret. Guest session tokens and reva
access tokens remain unforgeable across each other without a second
secret to configure.
2026-10-07 08:46:53 +02:00

26 lines
846 B
Go

// Copyright 2026 OpenCloud GmbH <mail@opencloud.eu>
// SPDX-License-Identifier: Apache-2.0
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSessionSecret(t *testing.T) {
cfg := &Config{TokenManager: &TokenManager{JWTSecret: "reva-secret"}}
other := &Config{TokenManager: &TokenManager{JWTSecret: "other-secret"}}
assert.Len(t, cfg.SessionSecret(), 64)
assert.Equal(t, cfg.SessionSecret(), cfg.SessionSecret(), "derivation must be deterministic")
assert.NotEqual(t, cfg.TokenManager.JWTSecret, cfg.SessionSecret())
assert.NotEqual(t, cfg.SessionSecret(), other.SessionSecret())
}
func TestSessionSecretMissingJWTSecret(t *testing.T) {
assert.Empty(t, (&Config{}).SessionSecret(), "nil token manager")
assert.Empty(t, (&Config{TokenManager: &TokenManager{}}).SessionSecret(), "empty jwt secret")
}