2020-12-04 03:46:11 +09:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-28 03:20:29 +09:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-04 03:46:11 +09:00
|
|
|
|
2022-10-17 08:29:26 +09:00
|
|
|
package avatars_test
|
2020-12-04 03:46:11 +09:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-10-17 08:29:26 +09:00
|
|
|
avatars_model "code.gitea.io/gitea/models/avatars"
|
|
|
|
system_model "code.gitea.io/gitea/models/system"
|
2020-12-04 03:46:11 +09:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
const gravatarSource = "https://secure.gravatar.com/avatar/"
|
|
|
|
|
2022-10-17 08:29:26 +09:00
|
|
|
func disableGravatar(t *testing.T) {
|
|
|
|
err := system_model.SetSettingNoVersion(system_model.KeyPictureEnableFederatedAvatar, "false")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = system_model.SetSettingNoVersion(system_model.KeyPictureDisableGravatar, "true")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
system_model.LibravatarService = nil
|
2020-12-04 03:46:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func enableGravatar(t *testing.T) {
|
2022-10-17 08:29:26 +09:00
|
|
|
err := system_model.SetSettingNoVersion(system_model.KeyPictureDisableGravatar, "false")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
setting.GravatarSource = gravatarSource
|
|
|
|
err = system_model.Init()
|
2020-12-04 03:46:11 +09:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHashEmail(t *testing.T) {
|
|
|
|
assert.Equal(t,
|
|
|
|
"d41d8cd98f00b204e9800998ecf8427e",
|
2022-10-17 08:29:26 +09:00
|
|
|
avatars_model.HashEmail(""),
|
2020-12-04 03:46:11 +09:00
|
|
|
)
|
|
|
|
assert.Equal(t,
|
|
|
|
"353cbad9b58e69c96154ad99f92bedc7",
|
2022-10-17 08:29:26 +09:00
|
|
|
avatars_model.HashEmail("gitea@example.com"),
|
2020-12-04 03:46:11 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSizedAvatarLink(t *testing.T) {
|
2021-05-12 13:13:42 +09:00
|
|
|
setting.AppSubURL = "/testsuburl"
|
|
|
|
|
2022-10-17 08:29:26 +09:00
|
|
|
disableGravatar(t)
|
2021-05-12 13:13:42 +09:00
|
|
|
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
|
2022-10-17 08:29:26 +09:00
|
|
|
avatars_model.GenerateEmailAvatarFastLink("gitea@example.com", 100))
|
2020-12-04 03:46:11 +09:00
|
|
|
|
|
|
|
enableGravatar(t)
|
|
|
|
assert.Equal(t,
|
|
|
|
"https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
|
2022-10-17 08:29:26 +09:00
|
|
|
avatars_model.GenerateEmailAvatarFastLink("gitea@example.com", 100),
|
2020-12-04 03:46:11 +09:00
|
|
|
)
|
|
|
|
}
|