mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-03-25 13:13:03 -04:00
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing-integration / test-mariadb (v10.6) (push) Waiting to run
testing-integration / test-mariadb (v11.8) (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Document that the token is only valid for a minute. Add a link to get a new token. Resolves #8048 Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9002 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: dawe <dawedawe@posteo.de> Co-committed-by: dawe <dawedawe@posteo.de>
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestVerifySSHkeyPage(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
// user2 has an SSH key in fixtures to test this on
|
|
session := loginUser(t, "user2")
|
|
|
|
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user/settings/keys"), http.StatusOK).Body)
|
|
link, exists := page.Find("#keys-ssh a.button[href^='?verify_ssh=']").Attr("href")
|
|
assert.True(t, exists)
|
|
|
|
page = NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("/user/settings/keys%s", link)), http.StatusOK).Body)
|
|
|
|
// QueryUnescape the link for selector matching
|
|
link, err := url.QueryUnescape(link)
|
|
require.NoError(t, err)
|
|
|
|
// The hint contains a link to the same page the user is at now to get it reloaded if followed
|
|
page.AssertElement(t, fmt.Sprintf("#keys-ssh form[action='/user/settings/keys'] .help a[href='%s']", link), true)
|
|
|
|
// The token changes every minute, we can avoid this sleep via timeutil and mocking.
|
|
test.SleepTillNextMinute()
|
|
|
|
// Verify that if you refresh it via the link another token is shown.
|
|
token, exists := page.Find("#keys-ssh form input[readonly]").Attr("value")
|
|
assert.True(t, exists)
|
|
|
|
link = url.QueryEscape(strings.TrimPrefix(link, "?verify_ssh="))
|
|
page = NewHTMLParser(t, session.MakeRequest(t, NewRequestf(t, "GET", "/user/settings/keys?verify_ssh=%s", link), http.StatusOK).Body)
|
|
otherToken, exists := page.Find("#keys-ssh form .field input[readonly]").Attr("value")
|
|
assert.True(t, exists)
|
|
assert.NotEqual(t, token, otherToken)
|
|
}
|