Open platform to collect and prioritize feedback
fix: Temporary fix for #226 (#227)
Guilherme Oenning076965b24078
diff --git a/app/handlers/avatar.go b/app/handlers/avatar.goindex 7e40941f5..85c5c7f3b 100644--- a/app/handlers/avatar.go+++ b/app/handlers/avatar.go@@ -2,7 +2,10 @@ package handlersimport ("bytes"+ "crypto/md5"+ "fmt""image/png"+ "io/ioutil""net/http""strings"@@ -10,11 +13,35 @@ import ("github.com/goenning/letteravatar")-//LetterAvatar returns a letter avatar based on name-func LetterAvatar() web.HandlerFunc {+//Avatar returns a gravatar picture of fallsback to letter avatar based on name+func Avatar() web.HandlerFunc {return func(c web.Context) error {name := c.Param("name")size, _ := c.ParamAsInt("size")+ email := c.QueryParam("e")++ id, err := c.ParamAsInt("id")+ if err == nil && id > 0 && email == "" {+ user, err := c.Services().Users.GetByID(id)+ if err == nil && user.Tenant.ID == c.Tenant().ID {+ email = user.Email+ println(user.Email)+ }+ }++ if email != "" {+ hash := md5.Sum([]byte(email))+ url := fmt.Sprintf("https://www.gravatar.com/avatar/%x?s=%d&d=404", hash, size)+ c.Logger().Debugf("Requesting gravatar: %s", url)+ resp, err := http.Get(url)+ if err == nil && resp != nil && resp.StatusCode == http.StatusOK {+ bytes, err := ioutil.ReadAll(resp.Body)+ if err == nil {+ return c.Blob(http.StatusOK, "image/png", bytes)+ }+ }+ }+img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{PaletteKey: name})if err != nil {return c.Failure(err)diff --git a/app/handlers/avatar_test.go b/app/handlers/avatar_test.goindex 53e95ae28..b36e1b939 100644--- a/app/handlers/avatar_test.go+++ b/app/handlers/avatar_test.go@@ -5,56 +5,93 @@ import ("net/http""testing"+ "github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/mock""github.com/getfider/fider/app/handlers". "github.com/onsi/gomega")-func TestAvatarHandler(t *testing.T) {+func TestGravatarHandler(t *testing.T) {+ RegisterTestingT(t)++ server, services := mock.NewServer()+ user := &models.User{+ Name: "Darth Vader",+ Email: "[email protected]",+ Tenant: mock.DemoTenant,+ }+ services.Users.Register(user)+ code, response := server.+ OnTenant(mock.DemoTenant).+ AddParam("id", user.ID).+ AddParam("size", 50).+ AddParam("name", user.Name).+ Execute(handlers.Avatar())++ expectedAvatar := []byte{255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 254, 0, 59, 67, 82, 69, 65, 84, 79, 82, 58, 32, 103, 100, 45, 106, 112, 101, 103, 32, 118, 49, 46, 48, 32, 40, 117, 115, 105, 110, 103, 32, 73, 74, 71, 32, 74, 80, 69, 71, 32, 118, 54, 50, 41, 44, 32, 113, 117, 97, 108, 105, 116, 121, 32, 61, 32, 57, 48, 10, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, 9, 5, 5, 9, 20, 13, 11, 13, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 255, 192, 0, 17, 8, 0, 50, 0, 50, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 252, 207, 109, 22, 21, 199, 12, 61, 112, 213, 57, 209, 237, 33, 182, 105, 165, 46, 168, 163, 183, 57, 62, 149, 245, 7, 236, 5, 225, 255, 0, 3, 235, 159, 181, 46, 155, 99, 227, 221, 31, 79, 214, 244, 137, 244, 107, 150, 182, 179, 213, 33, 89, 160, 123, 133, 101, 32, 148, 111, 148, 144, 130, 67, 200, 237, 94, 239, 255, 0, 5, 55, 248, 123, 240, 166, 203, 194, 254, 23, 210, 126, 29, 120, 111, 194, 158, 24, 214, 165, 214, 86, 43, 171, 171, 8, 161, 179, 45, 7, 145, 35, 54, 66, 224, 20, 12, 83, 45, 142, 14, 209, 223, 7, 179, 151, 70, 212, 79, 38, 51, 189, 175, 61, 207, 139, 79, 193, 22, 210, 244, 49, 168, 222, 70, 100, 114, 155, 150, 44, 0, 188, 142, 6, 113, 147, 214, 188, 207, 84, 125, 62, 210, 249, 173, 96, 178, 44, 85, 182, 231, 130, 73, 252, 171, 236, 77, 122, 230, 211, 83, 248, 123, 13, 181, 133, 237, 189, 237, 205, 148, 40, 151, 83, 7, 85, 141, 36, 85, 220, 9, 98, 113, 180, 237, 206, 115, 192, 53, 243, 111, 135, 188, 51, 164, 71, 227, 107, 121, 117, 45, 95, 79, 186, 182, 50, 3, 32, 176, 147, 206, 216, 51, 215, 177, 35, 220, 10, 43, 69, 69, 46, 84, 42, 18, 114, 187, 155, 216, 169, 160, 248, 58, 195, 92, 133, 198, 207, 42, 120, 240, 94, 41, 19, 4, 3, 208, 253, 56, 171, 147, 124, 54, 180, 83, 247, 98, 3, 25, 232, 223, 227, 95, 74, 254, 206, 158, 16, 240, 47, 141, 255, 0, 110, 47, 15, 120, 71, 80, 180, 77, 127, 194, 122, 134, 149, 112, 37, 242, 103, 150, 5, 44, 45, 222, 85, 108, 198, 202, 195, 13, 26, 140, 103, 191, 61, 13, 125, 161, 241, 7, 246, 40, 248, 19, 166, 207, 226, 11, 75, 123, 61, 86, 11, 230, 137, 26, 22, 143, 85, 148, 165, 129, 59, 137, 3, 113, 57, 227, 105, 195, 238, 60, 142, 153, 171, 167, 21, 39, 203, 107, 179, 58, 142, 80, 138, 159, 53, 147, 63, 36, 207, 195, 155, 44, 253, 216, 255, 0, 241, 239, 254, 42, 138, 250, 238, 251, 224, 231, 192, 219, 11, 219, 139, 89, 126, 37, 220, 44, 144, 200, 209, 178, 181, 237, 190, 65, 7, 4, 31, 147, 218, 138, 233, 246, 17, 236, 190, 244, 115, 123, 106, 157, 223, 226, 121, 191, 236, 225, 225, 237, 38, 235, 196, 90, 30, 175, 127, 4, 114, 125, 140, 93, 100, 191, 241, 6, 27, 54, 253, 48, 77, 124, 243, 241, 167, 198, 35, 226, 39, 196, 237, 94, 235, 78, 139, 26, 104, 185, 107, 125, 58, 218, 17, 144, 33, 86, 33, 118, 129, 221, 190, 241, 247, 106, 244, 107, 47, 23, 73, 225, 15, 133, 90, 133, 196, 13, 229, 220, 75, 20, 144, 68, 71, 4, 51, 182, 220, 143, 112, 9, 63, 133, 120, 5, 178, 204, 242, 55, 144, 28, 176, 82, 78, 204, 228, 14, 245, 203, 94, 126, 226, 130, 245, 59, 240, 112, 213, 212, 126, 136, 244, 13, 55, 74, 178, 240, 239, 135, 124, 77, 160, 235, 186, 69, 235, 248, 154, 254, 218, 6, 210, 86, 221, 247, 164, 18, 137, 163, 102, 50, 42, 57, 249, 140, 94, 114, 224, 130, 65, 113, 144, 59, 114, 87, 90, 123, 216, 216, 219, 93, 164, 166, 11, 168, 159, 99, 194, 210, 1, 42, 54, 73, 4, 40, 59, 128, 192, 28, 144, 57, 53, 235, 31, 7, 143, 143, 126, 30, 106, 54, 94, 32, 240, 236, 210, 232, 154, 157, 131, 75, 50, 203, 106, 26, 43, 150, 67, 20, 76, 81, 164, 94, 118, 178, 49, 194, 156, 242, 132, 17, 212, 87, 97, 241, 150, 255, 0, 196, 30, 54, 240, 54, 163, 172, 248, 150, 120, 237, 158, 105, 197, 202, 202, 2, 192, 215, 239, 130, 0, 242, 219, 27, 74, 156, 238, 0, 99, 43, 129, 201, 192, 227, 183, 83, 177, 212, 229, 146, 91, 220, 227, 127, 103, 175, 137, 175, 225, 175, 142, 190, 1, 241, 13, 228, 134, 40, 99, 186, 58, 117, 212, 209, 49, 70, 141, 103, 86, 133, 159, 35, 160, 11, 38, 239, 248, 11, 12, 98, 189, 215, 246, 171, 241, 135, 142, 45, 245, 173, 91, 77, 209, 124, 79, 126, 44, 245, 139, 159, 54, 243, 124, 196, 201, 147, 144, 64, 110, 170, 164, 99, 229, 30, 149, 241, 45, 148, 139, 230, 52, 82, 62, 200, 228, 227, 118, 126, 235, 127, 11, 126, 127, 161, 53, 245, 126, 187, 227, 120, 254, 34, 120, 99, 70, 241, 35, 184, 150, 226, 242, 216, 45, 216, 207, 41, 118, 152, 89, 129, 244, 203, 124, 224, 127, 118, 68, 174, 202, 18, 188, 92, 14, 76, 92, 57, 92, 106, 37, 177, 226, 171, 240, 158, 2, 163, 204, 190, 99, 39, 241, 125, 123, 209, 91, 242, 106, 110, 36, 108, 103, 25, 52, 86, 156, 144, 254, 83, 139, 219, 213, 254, 98, 75, 109, 16, 120, 175, 192, 113, 105, 198, 65, 19, 191, 207, 28, 135, 160, 96, 73, 25, 246, 237, 248, 215, 157, 234, 191, 12, 124, 83, 160, 193, 113, 52, 154, 116, 173, 104, 138, 124, 201, 237, 220, 58, 21, 235, 147, 131, 211, 128, 121, 244, 174, 183, 71, 241, 141, 151, 135, 60, 63, 100, 247, 83, 22, 148, 198, 25, 97, 143, 150, 111, 240, 252, 107, 152, 241, 151, 197, 61, 91, 197, 182, 198, 199, 119, 216, 244, 204, 130, 109, 227, 57, 47, 142, 155, 219, 191, 211, 165, 101, 87, 217, 181, 119, 185, 215, 134, 85, 163, 39, 20, 189, 219, 255, 0, 86, 56, 239, 51, 228, 219, 142, 125, 107, 214, 62, 16, 252, 25, 241, 47, 199, 75, 235, 75, 107, 101, 187, 155, 78, 179, 30, 76, 183, 140, 75, 45, 180, 99, 36, 12, 177, 194, 168, 207, 78, 131, 53, 15, 134, 252, 1, 168, 63, 129, 228, 241, 11, 91, 88, 106, 0, 198, 124, 184, 46, 98, 102, 109, 163, 142, 10, 144, 115, 199, 124, 213, 95, 17, 106, 30, 37, 248, 117, 161, 157, 30, 211, 84, 159, 79, 178, 212, 80, 61, 205, 189, 155, 180, 105, 38, 224, 172, 59, 231, 161, 0, 250, 226, 185, 121, 26, 179, 107, 67, 181, 212, 231, 188, 96, 245, 48, 190, 38, 248, 13, 62, 29, 120, 170, 243, 71, 77, 98, 203, 89, 16, 57, 95, 58, 206, 64, 227, 232, 112, 72, 4, 122, 100, 214, 175, 195, 127, 19, 182, 157, 165, 221, 233, 247, 26, 149, 188, 86, 79, 47, 157, 29, 172, 163, 14, 36, 192, 5, 149, 136, 192, 4, 0, 8, 207, 59, 87, 142, 5, 112, 166, 202, 115, 100, 110, 202, 17, 0, 144, 71, 188, 247, 98, 9, 199, 228, 42, 189, 17, 151, 44, 174, 141, 37, 14, 120, 114, 201, 158, 181, 37, 234, 51, 177, 15, 193, 39, 24, 52, 87, 147, 110, 62, 166, 138, 232, 250, 199, 145, 195, 245, 37, 252, 223, 128, 249, 216, 179, 140, 146, 112, 160, 115, 244, 162, 220, 3, 113, 16, 35, 32, 176, 227, 241, 162, 138, 228, 61, 37, 178, 62, 222, 240, 253, 180, 48, 120, 14, 241, 34, 137, 35, 65, 230, 0, 168, 160, 1, 197, 121, 119, 199, 187, 120, 158, 227, 74, 221, 26, 55, 250, 29, 185, 229, 71, 247, 18, 138, 43, 210, 173, 252, 63, 184, 249, 236, 63, 241, 126, 103, 156, 120, 158, 24, 227, 248, 96, 74, 162, 169, 254, 215, 65, 144, 49, 199, 144, 213, 230, 180, 81, 94, 124, 186, 30, 229, 47, 132, 40, 162, 138, 147, 99, 255, 217}++ Expect(code).To(Equal(http.StatusOK))+ Expect(ioutil.ReadAll(response.Body)).To(Equal(expectedAvatar))+}++func TestGravatarQueryStringHandler(t *testing.T) {+ RegisterTestingT(t)++ server, services := mock.NewServer()+ user := &models.User{+ Name: "Darth Vader",+ Email: "[email protected]",+ Tenant: mock.DemoTenant,+ }+ services.Users.Register(user)+ code, response := server.+ OnTenant(mock.DemoTenant).+ WithURL("/avatars/0/50/Darth%[email protected]").+ AddParam("size", 50).+ AddParam("name", user.Name).+ Execute(handlers.Avatar())++ expectedAvatar := []byte{255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 254, 0, 59, 67, 82, 69, 65, 84, 79, 82, 58, 32, 103, 100, 45, 106, 112, 101, 103, 32, 118, 49, 46, 48, 32, 40, 117, 115, 105, 110, 103, 32, 73, 74, 71, 32, 74, 80, 69, 71, 32, 118, 54, 50, 41, 44, 32, 113, 117, 97, 108, 105, 116, 121, 32, 61, 32, 57, 48, 10, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, 9, 5, 5, 9, 20, 13, 11, 13, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 255, 192, 0, 17, 8, 0, 50, 0, 50, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 252, 207, 109, 22, 21, 199, 12, 61, 112, 213, 57, 209, 237, 33, 182, 105, 165, 46, 168, 163, 183, 57, 62, 149, 245, 7, 236, 5, 225, 255, 0, 3, 235, 159, 181, 46, 155, 99, 227, 221, 31, 79, 214, 244, 137, 244, 107, 150, 182, 179, 213, 33, 89, 160, 123, 133, 101, 32, 148, 111, 148, 144, 130, 67, 200, 237, 94, 239, 255, 0, 5, 55, 248, 123, 240, 166, 203, 194, 254, 23, 210, 126, 29, 120, 111, 194, 158, 24, 214, 165, 214, 86, 43, 171, 171, 8, 161, 179, 45, 7, 145, 35, 54, 66, 224, 20, 12, 83, 45, 142, 14, 209, 223, 7, 179, 151, 70, 212, 79, 38, 51, 189, 175, 61, 207, 139, 79, 193, 22, 210, 244, 49, 168, 222, 70, 100, 114, 155, 150, 44, 0, 188, 142, 6, 113, 147, 214, 188, 207, 84, 125, 62, 210, 249, 173, 96, 178, 44, 85, 182, 231, 130, 73, 252, 171, 236, 77, 122, 230, 211, 83, 248, 123, 13, 181, 133, 237, 189, 237, 205, 148, 40, 151, 83, 7, 85, 141, 36, 85, 220, 9, 98, 113, 180, 237, 206, 115, 192, 53, 243, 111, 135, 188, 51, 164, 71, 227, 107, 121, 117, 45, 95, 79, 186, 182, 50, 3, 32, 176, 147, 206, 216, 51, 215, 177, 35, 220, 10, 43, 69, 69, 46, 84, 42, 18, 114, 187, 155, 216, 169, 160, 248, 58, 195, 92, 133, 198, 207, 42, 120, 240, 94, 41, 19, 4, 3, 208, 253, 56, 171, 147, 124, 54, 180, 83, 247, 98, 3, 25, 232, 223, 227, 95, 74, 254, 206, 158, 16, 240, 47, 141, 255, 0, 110, 47, 15, 120, 71, 80, 180, 77, 127, 194, 122, 134, 149, 112, 37, 242, 103, 150, 5, 44, 45, 222, 85, 108, 198, 202, 195, 13, 26, 140, 103, 191, 61, 13, 125, 161, 241, 7, 246, 40, 248, 19, 166, 207, 226, 11, 75, 123, 61, 86, 11, 230, 137, 26, 22, 143, 85, 148, 165, 129, 59, 137, 3, 113, 57, 227, 105, 195, 238, 60, 142, 153, 171, 167, 21, 39, 203, 107, 179, 58, 142, 80, 138, 159, 53, 147, 63, 36, 207, 195, 155, 44, 253, 216, 255, 0, 241, 239, 254, 42, 138, 250, 238, 251, 224, 231, 192, 219, 11, 219, 139, 89, 126, 37, 220, 44, 144, 200, 209, 178, 181, 237, 190, 65, 7, 4, 31, 147, 218, 138, 233, 246, 17, 236, 190, 244, 115, 123, 106, 157, 223, 226, 121, 191, 236, 225, 225, 237, 38, 235, 196, 90, 30, 175, 127, 4, 114, 125, 140, 93, 100, 191, 241, 6, 27, 54, 253, 48, 77, 124, 243, 241, 167, 198, 35, 226, 39, 196, 237, 94, 235, 78, 139, 26, 104, 185, 107, 125, 58, 218, 17, 144, 33, 86, 33, 118, 129, 221, 190, 241, 247, 106, 244, 107, 47, 23, 73, 225, 15, 133, 90, 133, 196, 13, 229, 220, 75, 20, 144, 68, 71, 4, 51, 182, 220, 143, 112, 9, 63, 133, 120, 5, 178, 204, 242, 55, 144, 28, 176, 82, 78, 204, 228, 14, 245, 203, 94, 126, 226, 130, 245, 59, 240, 112, 213, 212, 126, 136, 244, 13, 55, 74, 178, 240, 239, 135, 124, 77, 160, 235, 186, 69, 235, 248, 154, 254, 218, 6, 210, 86, 221, 247, 164, 18, 137, 163, 102, 50, 42, 57, 249, 140, 94, 114, 224, 130, 65, 113, 144, 59, 114, 87, 90, 123, 216, 216, 219, 93, 164, 166, 11, 168, 159, 99, 194, 210, 1, 42, 54, 73, 4, 40, 59, 128, 192, 28, 144, 57, 53, 235, 31, 7, 143, 143, 126, 30, 106, 54, 94, 32, 240, 236, 210, 232, 154, 157, 131, 75, 50, 203, 106, 26, 43, 150, 67, 20, 76, 81, 164, 94, 118, 178, 49, 194, 156, 242, 132, 17, 212, 87, 97, 241, 150, 255, 0, 196, 30, 54, 240, 54, 163, 172, 248, 150, 120, 237, 158, 105, 197, 202, 202, 2, 192, 215, 239, 130, 0, 242, 219, 27, 74, 156, 238, 0, 99, 43, 129, 201, 192, 227, 183, 83, 177, 212, 229, 146, 91, 220, 227, 127, 103, 175, 137, 175, 225, 175, 142, 190, 1, 241, 13, 228, 134, 40, 99, 186, 58, 117, 212, 209, 49, 70, 141, 103, 86, 133, 159, 35, 160, 11, 38, 239, 248, 11, 12, 98, 189, 215, 246, 171, 241, 135, 142, 45, 245, 173, 91, 77, 209, 124, 79, 126, 44, 245, 139, 159, 54, 243, 124, 196, 201, 147, 144, 64, 110, 170, 164, 99, 229, 30, 149, 241, 45, 148, 139, 230, 52, 82, 62, 200, 228, 227, 118, 126, 235, 127, 11, 126, 127, 161, 53, 245, 126, 187, 227, 120, 254, 34, 120, 99, 70, 241, 35, 184, 150, 226, 242, 216, 45, 216, 207, 41, 118, 152, 89, 129, 244, 203, 124, 224, 127, 118, 68, 174, 202, 18, 188, 92, 14, 76, 92, 57, 92, 106, 37, 177, 226, 171, 240, 158, 2, 163, 204, 190, 99, 39, 241, 125, 123, 209, 91, 242, 106, 110, 36, 108, 103, 25, 52, 86, 156, 144, 254, 83, 139, 219, 213, 254, 98, 75, 109, 16, 120, 175, 192, 113, 105, 198, 65, 19, 191, 207, 28, 135, 160, 96, 73, 25, 246, 237, 248, 215, 157, 234, 191, 12, 124, 83, 160, 193, 113, 52, 154, 116, 173, 104, 138, 124, 201, 237, 220, 58, 21, 235, 147, 131, 211, 128, 121, 244, 174, 183, 71, 241, 141, 151, 135, 60, 63, 100, 247, 83, 22, 148, 198, 25, 97, 143, 150, 111, 240, 252, 107, 152, 241, 151, 197, 61, 91, 197, 182, 198, 199, 119, 216, 244, 204, 130, 109, 227, 57, 47, 142, 155, 219, 191, 211, 165, 101, 87, 217, 181, 119, 185, 215, 134, 85, 163, 39, 20, 189, 219, 255, 0, 86, 56, 239, 51, 228, 219, 142, 125, 107, 214, 62, 16, 252, 25, 241, 47, 199, 75, 235, 75, 107, 101, 187, 155, 78, 179, 30, 76, 183, 140, 75, 45, 180, 99, 36, 12, 177, 194, 168, 207, 78, 131, 53, 15, 134, 252, 1, 168, 63, 129, 228, 241, 11, 91, 88, 106, 0, 198, 124, 184, 46, 98, 102, 109, 163, 142, 10, 144, 115, 199, 124, 213, 95, 17, 106, 30, 37, 248, 117, 161, 157, 30, 211, 84, 159, 79, 178, 212, 80, 61, 205, 189, 155, 180, 105, 38, 224, 172, 59, 231, 161, 0, 250, 226, 185, 121, 26, 179, 107, 67, 181, 212, 231, 188, 96, 245, 48, 190, 38, 248, 13, 62, 29, 120, 170, 243, 71, 77, 98, 203, 89, 16, 57, 95, 58, 206, 64, 227, 232, 112, 72, 4, 122, 100, 214, 175, 195, 127, 19, 182, 157, 165, 221, 233, 247, 26, 149, 188, 86, 79, 47, 157, 29, 172, 163, 14, 36, 192, 5, 149, 136, 192, 4, 0, 8, 207, 59, 87, 142, 5, 112, 166, 202, 115, 100, 110, 202, 17, 0, 144, 71, 188, 247, 98, 9, 199, 228, 42, 189, 17, 151, 44, 174, 141, 37, 14, 120, 114, 201, 158, 181, 37, 234, 51, 177, 15, 193, 39, 24, 52, 87, 147, 110, 62, 166, 138, 232, 250, 199, 145, 195, 245, 37, 252, 223, 128, 249, 216, 179, 140, 146, 112, 160, 115, 244, 162, 220, 3, 113, 16, 35, 32, 176, 227, 241, 162, 138, 228, 61, 37, 178, 62, 222, 240, 253, 180, 48, 120, 14, 241, 34, 137, 35, 65, 230, 0, 168, 160, 1, 197, 121, 119, 199, 187, 120, 158, 227, 74, 221, 26, 55, 250, 29, 185, 229, 71, 247, 18, 138, 43, 210, 173, 252, 63, 184, 249, 236, 63, 241, 126, 103, 156, 120, 158, 24, 227, 248, 96, 74, 162, 169, 254, 215, 65, 144, 49, 199, 144, 213, 230, 180, 81, 94, 124, 186, 30, 229, 47, 132, 40, 162, 138, 147, 99, 255, 217}++ Expect(code).To(Equal(http.StatusOK))+ Expect(ioutil.ReadAll(response.Body)).To(Equal(expectedAvatar))+}++func TestGravatarNotFound_LetterAvatarHandler(t *testing.T) {+ RegisterTestingT(t)++ server, services := mock.NewServer()+ user := &models.User{+ Name: "Darth Vader",+ Email: "[email protected]",+ Tenant: mock.DemoTenant,+ }+ services.Users.Register(user)+ code, response := server.+ OnTenant(mock.DemoTenant).+ AddParam("id", user.ID).+ AddParam("size", 50).+ AddParam("name", user.Name).+ Execute(handlers.Avatar())++ expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 143, 73, 68, 65, 84, 120, 156, 236, 152, 193, 107, 19, 79, 20, 199, 191, 155, 166, 45, 109, 55, 205, 239, 151, 10, 145, 216, 106, 116, 27, 49, 168, 141, 151, 122, 16, 188, 40, 244, 234, 65, 176, 8, 94, 197, 147, 39, 241, 159, 240, 230, 205, 147, 122, 241, 80, 60, 136, 7, 43, 8, 22, 65, 16, 105, 109, 13, 141, 218, 36, 164, 182, 198, 10, 38, 216, 38, 134, 53, 169, 217, 102, 87, 94, 50, 77, 54, 33, 232, 62, 108, 106, 15, 243, 165, 12, 223, 125, 59, 59, 243, 225, 205, 155, 153, 18, 183, 117, 235, 42, 246, 158, 92, 255, 26, 160, 189, 36, 22, 71, 18, 139, 35, 137, 197, 145, 196, 226, 72, 98, 113, 36, 177, 56, 146, 88, 28, 73, 44, 142, 220, 142, 122, 133, 79, 227, 196, 153, 198, 227, 207, 18, 10, 235, 248, 24, 67, 58, 209, 8, 42, 46, 92, 184, 134, 238, 94, 232, 121, 60, 189, 223, 102, 144, 137, 43, 240, 238, 67, 197, 192, 227, 59, 168, 84, 118, 2, 203, 243, 63, 2, 135, 91, 131, 145, 179, 200, 124, 198, 244, 93, 20, 54, 232, 209, 50, 177, 89, 196, 161, 99, 228, 95, 79, 35, 151, 109, 29, 33, 60, 78, 38, 181, 248, 71, 38, 254, 34, 62, 159, 194, 147, 123, 120, 246, 0, 177, 87, 168, 108, 193, 63, 130, 201, 27, 24, 240, 138, 183, 241, 57, 97, 180, 177, 214, 15, 71, 79, 9, 147, 120, 227, 100, 30, 38, 214, 234, 7, 164, 162, 88, 154, 197, 204, 20, 30, 222, 134, 81, 70, 191, 138, 243, 147, 226, 109, 58, 142, 162, 94, 133, 136, 180, 126, 24, 170, 98, 109, 150, 176, 242, 190, 3, 88, 118, 101, 210, 88, 152, 33, 19, 60, 14, 143, 143, 140, 105, 34, 185, 64, 198, 127, 16, 158, 255, 26, 61, 85, 47, 246, 7, 201, 164, 162, 148, 227, 206, 98, 1, 72, 190, 165, 86, 1, 180, 147, 34, 18, 223, 94, 35, 205, 150, 48, 45, 66, 125, 236, 171, 220, 89, 172, 252, 118, 93, 15, 250, 132, 201, 124, 66, 254, 27, 90, 202, 171, 230, 11, 57, 124, 89, 222, 21, 44, 211, 132, 97, 144, 233, 247, 52, 130, 137, 121, 106, 3, 26, 250, 84, 50, 125, 42, 14, 140, 194, 113, 177, 239, 4, 22, 128, 174, 46, 106, 141, 178, 13, 171, 58, 189, 75, 17, 73, 210, 198, 200, 115, 86, 240, 175, 177, 6, 188, 112, 85, 71, 208, 243, 141, 96, 46, 75, 187, 161, 190, 31, 107, 123, 48, 187, 134, 141, 204, 110, 97, 141, 132, 132, 249, 186, 218, 20, 175, 21, 254, 240, 81, 12, 14, 97, 56, 4, 251, 86, 232, 56, 150, 187, 27, 227, 19, 100, 126, 20, 144, 78, 54, 189, 74, 206, 83, 217, 117, 185, 112, 238, 18, 165, 211, 180, 68, 193, 117, 22, 75, 81, 16, 56, 130, 139, 215, 225, 243, 163, 118, 244, 91, 102, 83, 135, 162, 46, 174, 203, 218, 93, 180, 150, 68, 177, 192, 154, 193, 217, 157, 88, 215, 229, 155, 128, 133, 222, 1, 202, 4, 128, 138, 137, 151, 143, 176, 242, 174, 77, 207, 248, 28, 130, 97, 225, 151, 102, 121, 179, 176, 177, 250, 85, 97, 12, 131, 142, 236, 232, 11, 170, 229, 182, 90, 142, 161, 92, 70, 79, 15, 181, 169, 69, 46, 150, 226, 232, 103, 183, 62, 213, 118, 50, 89, 40, 233, 226, 238, 251, 189, 188, 67, 112, 247, 96, 171, 140, 239, 235, 92, 44, 103, 217, 42, 233, 244, 199, 21, 159, 166, 174, 61, 250, 223, 169, 196, 226, 72, 98, 113, 36, 177, 56, 146, 88, 28, 73, 44, 142, 36, 22, 71, 18, 139, 163, 95, 1, 0, 0, 255, 255, 231, 10, 191, 199, 156, 125, 3, 241, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}+ Expect(code).To(Equal(http.StatusOK))+ Expect(ioutil.ReadAll(response.Body)).To(Equal(expectedAvatar))+}++func TestUnknownUser_LetterAvatarHandler(t *testing.T) {RegisterTestingT(t)server, _ := mock.NewServer()code, response := server.OnTenant(mock.DemoTenant).- AsUser(mock.JonSnow).+ AddParam("id", 0).AddParam("size", 50).AddParam("name", "Jon Snow").- Execute(handlers.LetterAvatar())-- expectedAvatar := []byte{- 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145,- 93, 31, 230, 0, 0, 2, 150, 73, 68, 65, 84, 120, 156, 236, 152, 91, 79, 226, 64, 20, 128, 167, 115, 233, 141,- 94, 160, 84, 164, 46, 198, 93, 55, 217, 248, 255, 255, 200, 190, 154, 189, 100, 141, 138, 130, 86, 64, 218,- 210, 206, 244, 182, 129, 106, 117, 163, 49, 51, 89, 34, 62, 204, 247, 212, 28, 79, 207, 124, 158, 30, 78, 9,- 248, 251, 233, 47, 240, 241, 128, 187, 22, 120, 29, 169, 37, 130, 212, 18, 65, 106, 137, 32, 181, 68, 144, 90,- 34, 72, 45, 17, 164, 150, 8, 82, 75, 4, 252, 63, 55, 219, 29, 115, 224, 117, 1, 0, 227, 105, 152, 49, 214, 4,- 33, 132, 126, 215, 113, 172, 142, 70, 214, 197, 243, 162, 140, 146, 85, 184, 88, 230, 69, 241, 78, 90, 24, 161,- 142, 174, 53, 42, 77, 132, 16, 124, 252, 105, 168, 17, 210, 230, 32, 21, 234, 170, 235, 185, 246, 217, 213, 52,- 73, 179, 247, 208, 122, 201, 104, 224, 107, 132, 212, 0, 220, 220, 45, 238, 147, 164, 174, 129, 169, 107, 67, 191,- 71, 16, 58, 10, 246, 79, 207, 46, 170, 170, 226, 169, 179, 205, 217, 66, 8, 218, 166, 1, 0, 88, 44, 227, 233, 108,- 158, 81, 70, 25, 155, 47, 163, 203, 105, 184, 105, 45, 116, 173, 14, 103, 169, 109, 118, 75, 81, 148, 230, 162,- 252, 183, 37, 73, 154, 221, 221, 71, 155, 120, 185, 3, 173, 162, 40, 105, 158, 107, 132, 120, 174, 157, 164,- 217, 125, 156, 52, 241, 170, 170, 198, 55, 161, 80, 169, 45, 47, 136, 241, 205, 93, 93, 3, 168, 40, 71, 193,- 224, 219, 209, 104, 224, 117, 213, 103, 227, 191, 51, 173, 120, 149, 254, 190, 188, 74, 233, 122, 89, 232,- 42, 25, 246, 123, 39, 159, 71, 199, 163, 192, 212, 245, 93, 106, 1, 0, 86, 25, 253, 121, 62, 254, 51, 158,- 204, 163, 184, 25, 50, 203, 208, 191, 30, 6, 125, 215, 225, 47, 178, 229, 5, 209, 18, 173, 210, 104, 149,- 66, 69, 113, 237, 78, 224, 123, 24, 161, 131, 65, 63, 78, 51, 250, 184, 117, 223, 134, 183, 91, 16, 66,- 140, 16, 70, 232, 121, 80, 121, 186, 172, 1, 0, 134, 166, 117, 109, 171, 107, 91, 237, 71, 178, 170, 235,- 249, 50, 62, 159, 220, 54, 201, 174, 101, 114, 30, 199, 219, 45, 191, 235, 12, 251, 61, 0, 192, 233, 217,- 5, 203, 31, 94, 35, 132, 60, 220, 94, 148, 155, 135, 101, 26, 129, 191, 206, 249, 113, 206, 50, 250, 212,- 149, 246, 26, 65, 238, 46, 112, 230, 165, 143, 165, 219, 17, 33, 24, 123, 142, 221, 188, 245, 88, 158,- 3, 0, 150, 73, 82, 111, 254, 116, 176, 215, 111, 251, 170, 40, 74, 191, 251, 112, 75, 198, 114, 206,- 227, 120, 187, 21, 175, 210, 148, 50, 67, 83, 247, 122, 174, 99, 153, 121, 81, 26, 154, 134, 224, 250,- 97, 93, 135, 179, 38, 135, 178, 124, 18, 206, 2, 223, 179, 12, 253, 228, 203, 97, 70, 89, 89, 85, 154,- 74, 84, 140, 155, 127, 108, 17, 197, 156, 199, 41, 252, 191, 111, 97, 140, 70, 131, 61, 167, 99, 180,- 145, 162, 172, 38, 225, 108, 182, 140, 158, 167, 57, 29, 115, 223, 239, 25, 170, 218, 70, 106, 0, 22,- 81, 124, 125, 59, 43, 74, 222, 45, 47, 160, 213, 160, 18, 172, 107, 42, 84, 96, 94, 20, 105, 70, 171,- 186, 126, 53, 109, 221, 36, 66, 16, 132, 69, 89, 102, 148, 241, 11, 53, 8, 47, 8, 150, 23, 237, 200,- 191, 1, 101, 57, 229, 158, 164, 151, 124, 208, 111, 167, 82, 75, 4, 169, 37, 130, 212, 18, 65, 106, 137,- 32, 181, 68, 144, 90, 34, 72, 45, 17, 254, 6, 0, 0, 255, 255, 195, 184, 4, 70, 45, 232, 84, 206, 0,- 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}+ Execute(handlers.Avatar())+ expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 150, 73, 68, 65, 84, 120, 156, 236, 152, 91, 79, 226, 64, 20, 128, 167, 115, 233, 141, 94, 160, 84, 164, 46, 198, 93, 55, 217, 248, 255, 255, 200, 190, 154, 189, 100, 141, 138, 130, 86, 64, 218, 210, 206, 244, 182, 129, 106, 117, 163, 49, 51, 89, 34, 62, 204, 247, 212, 28, 79, 207, 124, 158, 30, 78, 9, 248, 251, 233, 47, 240, 241, 128, 187, 22, 120, 29, 169, 37, 130, 212, 18, 65, 106, 137, 32, 181, 68, 144, 90, 34, 72, 45, 17, 164, 150, 8, 82, 75, 4, 252, 63, 55, 219, 29, 115, 224, 117, 1, 0, 227, 105, 152, 49, 214, 4, 33, 132, 126, 215, 113, 172, 142, 70, 214, 197, 243, 162, 140, 146, 85, 184, 88, 230, 69, 241, 78, 90, 24, 161, 142, 174, 53, 42, 77, 132, 16, 124, 252, 105, 168, 17, 210, 230, 32, 21, 234, 170, 235, 185, 246, 217, 213, 52, 73, 179, 247, 208, 122, 201, 104, 224, 107, 132, 212, 0, 220, 220, 45, 238, 147, 164, 174, 129, 169, 107, 67, 191, 71, 16, 58, 10, 246, 79, 207, 46, 170, 170, 226, 169, 179, 205, 217, 66, 8, 218, 166, 1, 0, 88, 44, 227, 233, 108, 158, 81, 70, 25, 155, 47, 163, 203, 105, 184, 105, 45, 116, 173, 14, 103, 169, 109, 118, 75, 81, 148, 230, 162, 252, 183, 37, 73, 154, 221, 221, 71, 155, 120, 185, 3, 173, 162, 40, 105, 158, 107, 132, 120, 174, 157, 164, 217, 125, 156, 52, 241, 170, 170, 198, 55, 161, 80, 169, 45, 47, 136, 241, 205, 93, 93, 3, 168, 40, 71, 193, 224, 219, 209, 104, 224, 117, 213, 103, 227, 191, 51, 173, 120, 149, 254, 190, 188, 74, 233, 122, 89, 232, 42, 25, 246, 123, 39, 159, 71, 199, 163, 192, 212, 245, 93, 106, 1, 0, 86, 25, 253, 121, 62, 254, 51, 158, 204, 163, 184, 25, 50, 203, 208, 191, 30, 6, 125, 215, 225, 47, 178, 229, 5, 209, 18, 173, 210, 104, 149, 66, 69, 113, 237, 78, 224, 123, 24, 161, 131, 65, 63, 78, 51, 250, 184, 117, 223, 134, 183, 91, 16, 66, 140, 16, 70, 232, 121, 80, 121, 186, 172, 1, 0, 134, 166, 117, 109, 171, 107, 91, 237, 71, 178, 170, 235, 249, 50, 62, 159, 220, 54, 201, 174, 101, 114, 30, 199, 219, 45, 191, 235, 12, 251, 61, 0, 192, 233, 217, 5, 203, 31, 94, 35, 132, 60, 220, 94, 148, 155, 135, 101, 26, 129, 191, 206, 249, 113, 206, 50, 250, 212, 149, 246, 26, 65, 238, 46, 112, 230, 165, 143, 165, 219, 17, 33, 24, 123, 142, 221, 188, 245, 88, 158, 3, 0, 150, 73, 82, 111, 254, 116, 176, 215, 111, 251, 170, 40, 74, 191, 251, 112, 75, 198, 114, 206, 227, 120, 187, 21, 175, 210, 148, 50, 67, 83, 247, 122, 174, 99, 153, 121, 81, 26, 154, 134, 224, 250, 97, 93, 135, 179, 38, 135, 178, 124, 18, 206, 2, 223, 179, 12, 253, 228, 203, 97, 70, 89, 89, 85, 154, 74, 84, 140, 155, 127, 108, 17, 197, 156, 199, 41, 252, 191, 111, 97, 140, 70, 131, 61, 167, 99, 180, 145, 162, 172, 38, 225, 108, 182, 140, 158, 167, 57, 29, 115, 223, 239, 25, 170, 218, 70, 106, 0, 22, 81, 124, 125, 59, 43, 74, 222, 45, 47, 160, 213, 160, 18, 172, 107, 42, 84, 96, 94, 20, 105, 70, 171, 186, 126, 53, 109, 221, 36, 66, 16, 132, 69, 89, 102, 148, 241, 11, 53, 8, 47, 8, 150, 23, 237, 200, 191, 1, 101, 57, 229, 158, 164, 151, 124, 208, 111, 167, 82, 75, 4, 169, 37, 130, 212, 18, 65, 106, 137, 32, 181, 68, 144, 90, 34, 72, 45, 17, 254, 6, 0, 0, 255, 255, 195, 184, 4, 70, 45, 232, 84, 206, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}Expect(code).To(Equal(http.StatusOK))Expect(ioutil.ReadAll(response.Body)).To(Equal(expectedAvatar))}diff --git a/app/middlewares/cache.go b/app/middlewares/cache.goindex 961e1cb9f..a7cf062e6 100644--- a/app/middlewares/cache.go+++ b/app/middlewares/cache.go@@ -1,12 +1,17 @@package middlewares-import "github.com/getfider/fider/app/pkg/web"+import (+ "fmt"+ "time"-// OneYearCache adds Cache-Control header for one year-func OneYearCache() web.MiddlewareFunc {+ "github.com/getfider/fider/app/pkg/web"+)++// ClientCache adds Cache-Control header for X seconds+func ClientCache(d time.Duration) web.MiddlewareFunc {return func(next web.HandlerFunc) web.HandlerFunc {return func(c web.Context) error {- c.Response.Header().Add("Cache-Control", "public, max-age=30672000")+ c.Response.Header().Add("Cache-Control", fmt.Sprintf("public, max-age=%.f", d.Seconds()))return next(c)}}diff --git a/app/middlewares/cache_test.go b/app/middlewares/cache_test.goindex 4529ffce6..c7b338e54 100644--- a/app/middlewares/cache_test.go+++ b/app/middlewares/cache_test.go@@ -3,6 +3,7 @@ package middlewares_testimport ("net/http""testing"+ "time""github.com/getfider/fider/app/middlewares""github.com/getfider/fider/app/pkg/mock"@@ -14,7 +15,7 @@ func TestCache(t *testing.T) {RegisterTestingT(t)server, _ := mock.NewServer()- server.Use(middlewares.OneYearCache())+ server.Use(middlewares.ClientCache(5 * time.Minute))handler := func(c web.Context) error {return c.NoContent(http.StatusOK)}@@ -22,5 +23,5 @@ func TestCache(t *testing.T) {status, response := server.Execute(handler)Expect(status).To(Equal(http.StatusOK))- Expect(response.Header().Get("Cache-Control")).To(Equal("public, max-age=30672000"))+ Expect(response.Header().Get("Cache-Control")).To(Equal("public, max-age=300"))}diff --git a/app/models/identity.go b/app/models/identity.goindex a3d6f5d50..6c79b9c2e 100644--- a/app/models/identity.go+++ b/app/models/identity.go@@ -29,7 +29,6 @@ type User struct {ID int `json:"id"`Name string `json:"name"`Email string `json:"-"`- Gravatar string `json:"gravatar"`Tenant *Tenant `json:"-"`Role Role `json:"role"`Providers []*UserProvider `json:"-"`diff --git a/app/pkg/log/logger.go b/app/pkg/log/logger.goindex e2271ce19..7baa91e55 100644--- a/app/pkg/log/logger.go+++ b/app/pkg/log/logger.go@@ -66,7 +66,11 @@ func (l *ConsoleLogger) Errorf(format string, args ...interface{}) {// Error logs a ERROR messagefunc (l *ConsoleLogger) Error(err error) {- l.log(ERROR, err.Error())+ if err != nil {+ l.log(ERROR, err.Error())+ } else {+ l.log(ERROR, "nil")+ }}func (l *ConsoleLogger) log(level Level, format string, args ...interface{}) {diff --git a/app/storage/postgres/user.go b/app/storage/postgres/user.goindex e518b65d2..6a965f29c 100644--- a/app/storage/postgres/user.go+++ b/app/storage/postgres/user.go@@ -1,14 +1,11 @@package postgresimport (- "crypto/md5""strings""time""database/sql"- "fmt"-"github.com/getfider/fider/app""github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx"@@ -33,7 +30,6 @@ func (u *dbUser) toModel() *models.User {ID: int(u.ID.Int64),Name: u.Name.String,Email: u.Email.String,- Gravatar: fmt.Sprintf("%x", md5.Sum([]byte(u.Email.String))),Tenant: u.Tenant.toModel(),Role: models.Role(u.Role.Int64),Providers: make([]*models.UserProvider, len(u.Providers)),diff --git a/package-lock.json b/package-lock.jsonindex 596292af9..b394f8e0b 100644--- a/package-lock.json+++ b/package-lock.json@@ -16,15 +16,6 @@"integrity": "sha512-FWR7QB7EqBRq1s9BMk0ccOSOuRLfVEWYpHQYpFPaXtCoqN6dJx2ttdsdQbUxLLnAlKpYeVjveGGhQ3583TTa7g==","dev": true},- "@types/md5": {- "version": "2.1.32",- "resolved": "https://registry.npmjs.org/@types/md5/-/md5-2.1.32.tgz",- "integrity": "sha1-k+I0N/zRenucqY0CqmAC6DWEL+g=",- "dev": true,- "requires": {- "@types/node": "8.0.32"- }- },"@types/mocha": {"version": "2.2.44","resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.44.tgz",@@ -607,11 +598,6 @@"supports-color": "2.0.0"}},- "charenc": {- "version": "0.0.2",- "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",- "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="- },"chokidar": {"version": "1.7.0","resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz",@@ -873,11 +859,6 @@"which": "1.3.0"}},- "crypt": {- "version": "0.0.2",- "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",- "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="- },"cryptiles": {"version": "3.1.2","resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz",@@ -3527,16 +3508,6 @@"integrity": "sha1-3oGf282E3M2PrlnGrreWFbnSZqw=","dev": true},- "md5": {- "version": "2.2.1",- "resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz",- "integrity": "sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=",- "requires": {- "charenc": "0.0.2",- "crypt": "0.0.2",- "is-buffer": "1.1.5"- }- },"md5.js": {"version": "1.3.4","resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",diff --git a/package.json b/package.jsonindex 2c033042b..171927e10 100644--- a/package.json+++ b/package.json@@ -9,7 +9,6 @@"inversify-inject-decorators": "^3.0.2","jquery": "^3.2.1","markdown-it": "^8.4.0",- "md5": "^2.2.1","moment": "^2.19.2","react": "^16.1.1","react-dom": "^16.1.1",@@ -20,7 +19,6 @@"devDependencies": {"@types/jquery": "^3.2.16","@types/markdown-it": "0.0.4",- "@types/md5": "^2.1.32","@types/mocha": "^2.2.44","@types/react": "^16.0.25","@types/react-dom": "^16.0.3",diff --git a/public/components/common/Gravatar.tsx b/public/components/common/Gravatar.tsxindex 34e881f82..4fd650dae 100644--- a/public/components/common/Gravatar.tsx+++ b/public/components/common/Gravatar.tsx@@ -1,5 +1,4 @@import * as React from 'react';-import md5 = require('md5');import { getBaseUrl } from '@fider/utils/page';import { User } from '@fider/models';@@ -10,19 +9,20 @@ interface GravatarProps {}export const Gravatar = (props: GravatarProps) => {- const name = props.name ? props.name : props.user ? props.user.name : '';- const hash = props.email ? md5(props.email) : props.user ? props.user.gravatar : '';- const fallback = `${getBaseUrl()}/avatars/50/${name}`;+ const name = props.name ? props.name : props.user ? props.user.name : '_';+ const id = props.user ? props.user.id : 0;+ const queryString = props.email ? `?e=${encodeURIComponent(props.email)}` : '';++ const url = `${getBaseUrl()}/avatars/50/${id}/${encodeURIComponent(name)}${queryString}`;const isCollaborator = props.user ? props.user.role >= 2 : false;let element: any;return (<imgref={(e) => element = e}- onError={() => { element.src = fallback; }}className={`fdr-avatar image ${isCollaborator && 'staff'}`}title={name}- src={`https://www.gravatar.com/avatar/${hash}?d=${encodeURIComponent(fallback)}`}+ src={url}/>);};diff --git a/public/models/identity.ts b/public/models/identity.tsindex 7dbd468f5..1c05720af 100644--- a/public/models/identity.ts+++ b/public/models/identity.ts@@ -10,7 +10,6 @@ export interface Tenant {export interface User {id: number;name: string;- gravatar: string;role: number;}@@ -24,6 +23,5 @@ export interface CurrentUser {id: number;name: string;email: string;- gravatar: string;role: number;}diff --git a/public/pages/signup/SignUpPage.tsx b/public/pages/signup/SignUpPage.tsxindex 40f832b1c..d99bc997a 100644--- a/public/pages/signup/SignUpPage.tsx+++ b/public/pages/signup/SignUpPage.tsx@@ -141,12 +141,12 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {<p>Hello, <Gravatar name={this.user.name} email={this.user.email} />- <b>{this.user.name}</b> ({this.user.email})+ <b>{this.user.name}</b> {this.user.email && `(${this.user.email})`}</p></div> :<div><p>We need to identify you to setup your new Fider account.</p>- <SignInControl signInByEmail={false} />+ <SignInControl signInByEmail={false} /><div className="ui form"><DisplayError fields={['name', 'email']} error={this.state.error} /><div className="fluid field">diff --git a/routes.go b/routes.goindex 3e07dda63..6986757f2 100644--- a/routes.go+++ b/routes.go@@ -1,6 +1,8 @@package mainimport (+ "time"+"github.com/getfider/fider/app/handlers""github.com/getfider/fider/app/middlewares""github.com/getfider/fider/app/models"@@ -37,19 +39,19 @@ func GetMainEngine(settings *models.AppSettings) *web.Engine {emailer := initEmailer()r.Use(middlewares.Compress())+ r.Use(middlewares.Setup(db, emailer))assets := r.Group(){- assets.Use(middlewares.OneYearCache())- assets.Get("/avatars/:size/:name", handlers.LetterAvatar())+ assets.Use(middlewares.ClientCache(72 * time.Hour))+ assets.Use(middlewares.Tenant())+ assets.Get("/avatars/:size/:id/:name", handlers.Avatar())assets.Static("/favicon.ico", "favicon.ico")assets.Static("/assets/*filepath", "dist")}noTenant := r.Group(){- noTenant.Use(middlewares.Setup(db, emailer))-noTenant.Post("/api/tenants", handlers.CreateTenant())noTenant.Get("/api/tenants/:subdomain/availability", handlers.CheckAvailability())noTenant.Get("/signup", handlers.SignUp())@@ -64,14 +66,12 @@ func GetMainEngine(settings *models.AppSettings) *web.Engine {verify := r.Group(){- verify.Use(middlewares.Setup(db, emailer))verify.Use(middlewares.Tenant())verify.Get("/signup/verify", handlers.VerifySignUpKey())}page := r.Group(){- page.Use(middlewares.Setup(db, emailer))page.Use(middlewares.Tenant())page.Use(middlewares.JwtGetter())page.Use(middlewares.JwtSetter())