1 Commits

Author SHA1 Message Date
Adrian Zürcher
14968bfd4c replace static secrets with enviroment variables 2025-11-12 11:05:04 +01:00
3 changed files with 15 additions and 3 deletions

View File

@@ -1,10 +1,15 @@
package AccessHandler package AccessHandler
import ( import (
"os"
"gitea.tecamino.com/paadi/access-handler/handlers" "gitea.tecamino.com/paadi/access-handler/handlers"
"gitea.tecamino.com/paadi/tecamino-logger/logging" "gitea.tecamino.com/paadi/tecamino-logger/logging"
) )
func NewAccessHandler(path string, logger *logging.Logger) (aH *handlers.AccessHandler, err error) { func NewAccessHandler(path string, logger *logging.Logger) (aH *handlers.AccessHandler, err error) {
logger.Debug("NewAccessHandler", "get enviroment variables")
handlers.ACCESS_SECRET = []byte(os.Getenv("ACCESS_SECRET"))
handlers.REFRESH_SECRET = []byte(os.Getenv("REFRESH_SECRET"))
return handlers.NewAccessHandler(path, logger) return handlers.NewAccessHandler(path, logger)
} }

View File

@@ -16,6 +16,10 @@ import (
) )
func TestDatabase(t *testing.T) { func TestDatabase(t *testing.T) {
// set enviroment variables
os.Setenv("ACCESS_SECRET", "12345678910111213141516171819202")
os.Setenv("REFRESH_SECRET", "9998979695949392919089888786858")
dbName := "user.db" dbName := "user.db"
if _, err := os.Stat(dbName); err == nil { if _, err := os.Stat(dbName); err == nil {
t.Log("remove user.db to start test with empty database") t.Log("remove user.db to start test with empty database")
@@ -154,6 +158,9 @@ func TestDatabase(t *testing.T) {
} }
func TestLoginAndAuthorization(t *testing.T) { func TestLoginAndAuthorization(t *testing.T) {
os.Setenv("ACCESS_SECRET", "12345678910111213141516171819202")
os.Setenv("REFRESH_SECRET", "9998979695949392919089888786858")
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
// Setup your AccessHandler and router // Setup your AccessHandler and router

View File

@@ -16,9 +16,9 @@ import (
// 🔐 AUTHENTICATION CONSTANTS // 🔐 AUTHENTICATION CONSTANTS
// ----------------------------- // -----------------------------
// JWT secrets (replace "*" with strong random values in production!) // JWT secrets
var ACCESS_SECRET = []byte("ShFRprALcXjlosJ2hFCnGYGG3Ce2uRx6") var ACCESS_SECRET []byte
var REFRESH_SECRET = []byte("pQIjuX6g6Tzf0FEfdScxttT3hlL9NFaa") var REFRESH_SECRET []byte
// DOMAIN defines where cookies are valid. Change this in production. // DOMAIN defines where cookies are valid. Change this in production.
var DOMAIN = "localhost" var DOMAIN = "localhost"