From 4769ee7e9704b39d8313529c436508342cec0f88 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 1 Mar 2022 20:45:44 +0000 Subject: [PATCH 1/3] Prevent invalid key response. --- routers/web/user/home.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 33512d97c06e4..3f80a8ef07070 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -736,6 +736,11 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { ctx.ServerError("ListGPGKeys", err) return } + if len(keys) == 0 { + ctx.NotFound("", nil) + return + } + entities := make([]*openpgp.Entity, 0) failedEntitiesID := make([]string, 0) for _, k := range keys { From 21fefc79cadfbebf43f89b3d9c389a242cbc5c65 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 2 Mar 2022 07:44:00 +0100 Subject: [PATCH 2/3] Display note instead of 404 response. --- routers/web/user/home.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 3f80a8ef07070..379e1f8e20762 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -736,10 +736,6 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { ctx.ServerError("ListGPGKeys", err) return } - if len(keys) == 0 { - ctx.NotFound("", nil) - return - } entities := make([]*openpgp.Entity, 0) failedEntitiesID := make([]string, 0) @@ -760,6 +756,8 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { headers := make(map[string]string) if len(failedEntitiesID) > 0 { // If some key need re-import to be exported headers["Note"] = fmt.Sprintf("The keys with the following IDs couldn't be exported and need to be reuploaded %s", strings.Join(failedEntitiesID, ", ")) + } else if len(entities) == 0 { + headers["Note"] = "This user hasn't uploaded any GPG keys." } writer, _ := armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", headers) for _, e := range entities { From f88e8b1b05ef46ff7c2d0e24279f2e021c0c5d06 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 2 Mar 2022 12:08:54 +0000 Subject: [PATCH 3/3] Fixed test. --- integrations/user_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/user_test.go b/integrations/user_test.go index c12c2be40e628..4cfe7700e17f8 100644 --- a/integrations/user_test.go +++ b/integrations/user_test.go @@ -121,6 +121,7 @@ func TestExportUserGPGKeys(t *testing.T) { defer prepareTestEnv(t)() // Export empty key list testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK----- +Note: This user hasn't uploaded any GPG keys. =twTO