Change config JWT duration fields to time.Duration
- fix: The AccessTTL and RefreshTTL fields in JWTConfig now use time.Duration type directly instead of string with ParseDuration methods. The config validation now checks for positive durations rather than parsing strings.
This commit is contained in:
@@ -25,8 +25,8 @@ func TestDefaults(t *testing.T) {
|
||||
{"database.sqlite.path", cfg.Database.SQLite.Path, "data/mygo.db"},
|
||||
{"storage.driver", cfg.Storage.Driver, "local"},
|
||||
{"storage.local.path", cfg.Storage.Local.Path, "data/files"},
|
||||
{"jwt.access_ttl", cfg.JWT.AccessTTL, "15m"},
|
||||
{"jwt.refresh_ttl", cfg.JWT.RefreshTTL, "168h"},
|
||||
{"jwt.access_ttl", cfg.JWT.AccessTTL, 15 * time.Minute},
|
||||
{"jwt.refresh_ttl", cfg.JWT.RefreshTTL, 168 * time.Hour},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -87,11 +87,11 @@ jwt:
|
||||
if cfg.JWT.Secret != "test-secret" {
|
||||
t.Errorf("jwt.secret = %q, want %q", cfg.JWT.Secret, "test-secret")
|
||||
}
|
||||
if cfg.JWT.AccessTTL != "30m" {
|
||||
t.Errorf("jwt.access_ttl = %q, want %q", cfg.JWT.AccessTTL, "30m")
|
||||
if cfg.JWT.AccessTTL != 30*time.Minute {
|
||||
t.Errorf("jwt.access_ttl = %v, want %v", cfg.JWT.AccessTTL, 30*time.Minute)
|
||||
}
|
||||
if cfg.JWT.RefreshTTL != "72h" {
|
||||
t.Errorf("jwt.refresh_ttl = %q, want %q", cfg.JWT.RefreshTTL, "72h")
|
||||
if cfg.JWT.RefreshTTL != 72*time.Hour {
|
||||
t.Errorf("jwt.refresh_ttl = %v, want %v", cfg.JWT.RefreshTTL, 72*time.Hour)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,15 +198,15 @@ func TestExplicitConfigFileNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJWTConfigAccessDuration(t *testing.T) {
|
||||
j := JWTConfig{AccessTTL: "15m"}
|
||||
if got := j.AccessDuration(); got != 15*time.Minute {
|
||||
t.Errorf("AccessDuration() = %v, want %v", got, 15*time.Minute)
|
||||
j := JWTConfig{AccessTTL: 15 * time.Minute}
|
||||
if j.AccessTTL != 15*time.Minute {
|
||||
t.Errorf("AccessTTL = %v, want %v", j.AccessTTL, 15*time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJWTConfigRefreshDuration(t *testing.T) {
|
||||
j := JWTConfig{RefreshTTL: "168h"}
|
||||
if got := j.RefreshDuration(); got != 168*time.Hour {
|
||||
t.Errorf("RefreshDuration() = %v, want %v", got, 168*time.Hour)
|
||||
j := JWTConfig{RefreshTTL: 168 * time.Hour}
|
||||
if j.RefreshTTL != 168*time.Hour {
|
||||
t.Errorf("RefreshTTL = %v, want %v", j.RefreshTTL, 168*time.Hour)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user