mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-28 11:14:54 -04:00
feat: show note that user has no SSH keys (#11143)
- Resolves forgejo/forgejo#11064 - Show a note similar to that of GPG keys, when a user has no SSH keys uploaded through Forgejo. The content is recognized as a comment in SSH authorized files format and ends with a newline. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11143 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Reviewed-by: Beowulf <beowulf@beocode.eu> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
d9df2337b0
commit
7f7c2c0918
2 changed files with 23 additions and 0 deletions
|
|
@ -713,6 +713,11 @@ func ShowSSHKeys(ctx *context.Context) {
|
|||
buf.WriteString(keys[i].OmitEmail())
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
|
||||
if buf.Len() == 0 {
|
||||
buf.WriteString("# Note: This user hasn't uploaded any SSH keys.\n")
|
||||
}
|
||||
|
||||
ctx.PlainTextBytes(http.StatusOK, buf.Bytes())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1237,3 +1237,21 @@ func TestActivateEmailAddress(t *testing.T) {
|
|||
unittest.AssertNotExistsBean(t, &auth_model.AuthorizationToken{ID: authToken.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{UID: user2.ID, IsActivated: true, Email: "newemail@example.org"})
|
||||
}
|
||||
|
||||
func TestExportUserSSHKeys(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
t.Run("No exported keys", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
resp := MakeRequest(t, NewRequest(t, "GET", "/user1.keys"), http.StatusOK)
|
||||
|
||||
assert.Equal(t, "# Note: This user hasn't uploaded any SSH keys.\n", resp.Body.String())
|
||||
})
|
||||
|
||||
t.Run("Exported key", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
resp := MakeRequest(t, NewRequest(t, "GET", "/user2.keys"), http.StatusOK)
|
||||
|
||||
assert.Equal(t, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDWVj0fQ5N8wNc0LVNA41wDLYJ89ZIbejrPfg/avyj3u/ZohAKsQclxG4Ju0VirduBFF9EOiuxoiFBRr3xRpqzpsZtnMPkWVWb+akZwBFAx8p+jKdy4QXR/SZqbVobrGwip2UjSrri1CtBxpJikojRIZfCnDaMOyd9Jp6KkujvniFzUWdLmCPxUE9zhTaPu0JsEP7MW0m6yx7ZUhHyfss+NtqmFTaDO+QlMR7L2QkDliN2Jl3Xa3PhuWnKJfWhdAq1Cw4oraKUOmIgXLkuiuxVQ6mD3AiFupkmfqdHq6h+uHHmyQqv3gU+/sD8GbGAhf6ftqhTsXjnv1Aj4R8NoDf9BS6KRkzkeun5UisSzgtfQzjOMEiJtmrep2ZQrMGahrXa+q4VKr0aKJfm+KlLfwm/JztfsBcqQWNcTURiCFqz+fgZw0Ey/de0eyMzldYTdXXNRYCKjs9bvBK+6SSXRM7AhftfQ0ZuoW5+gtinPrnmoOaSCEJbAiEiTO/BzOHgowiM=\n", resp.Body.String())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue