53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package middleware
|
|
|
|
import "testing"
|
|
|
|
func TestTokenConfigValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
config TokenConfig
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "secure explicit TTLs",
|
|
config: TokenConfig{
|
|
Expiration: TokenExpiration{Account: 1, Refresh: 720},
|
|
Length: 32,
|
|
},
|
|
},
|
|
{
|
|
name: "rejects legacy 24 hour access token",
|
|
config: TokenConfig{
|
|
Expiration: TokenExpiration{Account: 24, Refresh: 720},
|
|
Length: 32,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "rejects missing access TTL",
|
|
config: TokenConfig{
|
|
Expiration: TokenExpiration{Refresh: 720},
|
|
Length: 32,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "rejects weak refresh token",
|
|
config: TokenConfig{
|
|
Expiration: TokenExpiration{Account: 1, Refresh: 720},
|
|
Length: 16,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := tt.config.Validate()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("Validate() error = %v, wantErr %t", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|