32 lines
833 B
Go
32 lines
833 B
Go
package usecase
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateGoogleIDTokenInfo(t *testing.T) {
|
|
now := time.Unix(1_700_000_000, 0)
|
|
valid := &googleIDTokenInfoResp{
|
|
Audience: "client-123",
|
|
Issuer: "https://accounts.google.com",
|
|
Subject: "google-user",
|
|
Expires: "1700000060",
|
|
}
|
|
require.NoError(t, validateGoogleIDTokenInfo(valid, "client-123", now))
|
|
|
|
wrongAudience := *valid
|
|
wrongAudience.Audience = "other-client"
|
|
require.Error(t, validateGoogleIDTokenInfo(&wrongAudience, "client-123", now))
|
|
|
|
wrongIssuer := *valid
|
|
wrongIssuer.Issuer = "https://attacker.example"
|
|
require.Error(t, validateGoogleIDTokenInfo(&wrongIssuer, "client-123", now))
|
|
|
|
expired := *valid
|
|
expired.Expires = "1699999999"
|
|
require.Error(t, validateGoogleIDTokenInfo(&expired, "client-123", now))
|
|
}
|