added test for federated user

This commit is contained in:
Michael Jerger 2024-02-07 16:12:23 +01:00
parent 67f3f66be4
commit a702da69cc
5 changed files with 34 additions and 3 deletions

View file

@ -16,7 +16,6 @@ import (
// swagger:model // swagger:model
type FederationHost struct { type FederationHost struct {
ID int64 `xorm:"pk autoincr"` ID int64 `xorm:"pk autoincr"`
// TODO: implement a toLower here & add a toLowerValidation
HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"` HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"`
NodeInfo NodeInfo `xorm:"extends NOT NULL"` NodeInfo NodeInfo `xorm:"extends NOT NULL"`
LatestActivity time.Time `xorm:"NOT NULL"` LatestActivity time.Time `xorm:"NOT NULL"`

View file

@ -0,0 +1,29 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
import (
"testing"
"code.gitea.io/gitea/modules/validation"
)
func Test_FederatedUserValidation(t *testing.T) {
sut := FederatedUser{
UserID: 12,
ExternalID: "12",
FederationHostID: 1,
}
if res, err := validation.IsValid(sut); !res {
t.Errorf("sut should be valid but was %q", err)
}
sut = FederatedUser{
ExternalID: "12",
FederationHostID: 1,
}
if res, _ := validation.IsValid(sut); res {
t.Errorf("sut should be invalid")
}
}

View file

@ -0,0 +1,2 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT

View file

@ -0,0 +1,2 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT

View file

@ -245,7 +245,6 @@ func createFederationInfo(ctx *context.APIContext, actorID forgefed.ActorID) (fo
return result, nil return result, nil
} }
// ToDo: Maybe use externalLoginUser
func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*user_model.User, error) { func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*user_model.User, error) {
// ToDo: Do we get a publicKeyId from server, repo or owner or repo? // ToDo: Do we get a publicKeyId from server, repo or owner or repo?
actionsUser := user_model.NewActionsUser() actionsUser := user_model.NewActionsUser()