Files
iam/pkg/schema/proves_test.go
zeekay 4761ee04ee A signed-in person without an image is drawn from Gravatar
picture was the uploaded avatar or nothing, so most people signed in as
a blank, and a client's own Gravatar guess 404ed into a generated face.
User.Picture answers the image they set, else their Gravatar keyed by
the SHA-256 of the normalized address, identicon when Gravatar has none.
userinfo publishes it only alongside the email scope, since the URL is
a hash of the address; the account switcher shows it to its owner.

Claude-Session: https://claude.ai/code/session_016hTDbBTaq6r3xTQ5RAVVtF
2026-09-23 17:53:32 -07:00

44 lines
1.4 KiB
Go

package schema
import "testing"
// Proves is the one rule every client-authenticating endpoint applies: a
// registration with no secret has nothing to prove, and one with a secret is
// proved by that secret alone.
func TestApplicationProves(t *testing.T) {
public := &Application{}
confidential := &Application{ClientSecret: "s3cr3t"}
for _, c := range []struct {
app *Application
secret string
want bool
}{
{public, "", true},
{public, "anything", true},
{confidential, "s3cr3t", true},
{confidential, "", false},
{confidential, "s3cr3", false},
{confidential, "s3cr3t ", false},
} {
if got := c.app.Proves(c.secret); got != c.want {
t.Errorf("secret %q against %q: Proves = %v, want %v", c.secret, c.app.ClientSecret, got, c.want)
}
}
}
// A person with no image is drawn from Gravatar, keyed by the normalized
// address; one with an image keeps it.
func TestUserPicture(t *testing.T) {
a := (&User{Email: " [email protected] "}).Picture()
b := (&User{Email: "[email protected]"}).Picture()
if a != b || len(a) != len("https://gravatar.com/avatar/")+64+len("?d=identicon&s=256") {
t.Fatalf("gravatar not normalized or malformed: %q vs %q", a, b)
}
if got := (&User{Email: "[email protected]", Avatar: "https://x/y.png"}).Picture(); got != "https://x/y.png" {
t.Fatalf("an image set by the person must win, got %q", got)
}
if got := (&User{}).Picture(); got != "" {
t.Fatalf("no image and no address draws nothing, got %q", got)
}
}