forgejo/tests/integration/admin_auth_source_test.go
Gusted b51f97e97d feat: add option to allow non-local users to change usernames (#8714)
Add a new config option for OAuth2 authentication sources: allow users to change their username.

In the case where OAuth2 is more like a social OAuth2 login there's no need to not allow users to change their username. The information how the user is linked to the authentication source is stored in different fields.

Resolves forgejo/forgejo#687

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8714
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
2025-08-06 20:25:13 +02:00

32 lines
821 B
Go

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later.
package integration
import (
"fmt"
"net/http"
"testing"
"forgejo.org/models/auth"
"forgejo.org/tests"
)
func TestAdminAuthAllowUsernameChangeSetting(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user1")
source := addAuthSource(t, map[string]string{
"type": fmt.Sprintf("%d", auth.OAuth2),
"name": "some-name",
"is_active": "on",
"allow_username_change": "on",
"oauth2_provider": "gitlab",
})
response := session.MakeRequest(t, NewRequestf(t, "GET", "/admin/auths/%d", source.ID), http.StatusOK)
htmlDoc := NewHTMLParser(t, response.Body)
htmlDoc.AssertElement(t, "#allow_username_change[checked]", true)
}