2020-12-04 00:16:11 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2022-10-17 04:59:26 +05:30
|
|
|
package avatars_test
|
2020-12-04 00:16:11 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-10-17 04:59:26 +05:30
|
|
|
avatars_model "code.gitea.io/gitea/models/avatars"
|
|
|
|
system_model "code.gitea.io/gitea/models/system"
|
2020-12-04 00:16:11 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
const gravatarSource = "https://secure.gravatar.com/avatar/"
|
|
|
|
|
2022-10-17 04:59:26 +05:30
|
|
|
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 00:16:11 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func enableGravatar(t *testing.T) {
|
2022-10-17 04:59:26 +05:30
|
|
|
err := system_model.SetSettingNoVersion(system_model.KeyPictureDisableGravatar, "false")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
setting.GravatarSource = gravatarSource
|
|
|
|
err = system_model.Init()
|
2020-12-04 00:16:11 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHashEmail(t *testing.T) {
|
|
|
|
assert.Equal(t,
|
|
|
|
"d41d8cd98f00b204e9800998ecf8427e",
|
2022-10-17 04:59:26 +05:30
|
|
|
avatars_model.HashEmail(""),
|
2020-12-04 00:16:11 +05:30
|
|
|
)
|
|
|
|
assert.Equal(t,
|
|
|
|
"353cbad9b58e69c96154ad99f92bedc7",
|
2022-10-17 04:59:26 +05:30
|
|
|
avatars_model.HashEmail("gitea@example.com"),
|
2020-12-04 00:16:11 +05:30
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSizedAvatarLink(t *testing.T) {
|
2021-05-12 09:43:42 +05:30
|
|
|
setting.AppSubURL = "/testsuburl"
|
|
|
|
|
2022-10-17 04:59:26 +05:30
|
|
|
disableGravatar(t)
|
2021-05-12 09:43:42 +05:30
|
|
|
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
|
2022-10-17 04:59:26 +05:30
|
|
|
avatars_model.GenerateEmailAvatarFastLink("gitea@example.com", 100))
|
2020-12-04 00:16:11 +05:30
|
|
|
|
|
|
|
enableGravatar(t)
|
|
|
|
assert.Equal(t,
|
|
|
|
"https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
|
2022-10-17 04:59:26 +05:30
|
|
|
avatars_model.GenerateEmailAvatarFastLink("gitea@example.com", 100),
|
2020-12-04 00:16:11 +05:30
|
|
|
)
|
|
|
|
}
|