Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

1009 B
Raw Blame
package sts

import (
	"testing"
	"time"
)

func TestCalculateSessionDuration(t *testing.T) {
	svc := NewSTSService()
	if err := svc.Initialize(&STSConfig{
		TokenDuration:    FlexibleDuration{time.Hour},
		MaxSessionLength: FlexibleDuration{12 * time.Hour},
		Issuer:           "test-issuer",
		SigningKey:       []byte("test-signing-key-at-least-32-bytes-long"),
	}); err != nil {
		t.Fatalf("Initialize() error = %v", err)
	}

	seconds := func(v int64) *int64 { return &v }

	tests := []struct {
		name            string
		durationSeconds *int64
		want            time.Duration
	}{
		{"default from config", nil, time.Hour},
		{"explicit request", seconds(1800), 30 * time.Minute},
		{"capped at MaxSessionLength", seconds(86400), 12 * time.Hour},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			if got := svc.CalculateSessionDuration(tc.durationSeconds); got != tc.want {
				t.Errorf("CalculateSessionDuration(%v) = %v, want %v", tc.durationSeconds, got, tc.want)
			}
		})
	}
}