From a702da69ccf59fc91c94730dbcc25dfa17f33e2b Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Wed, 7 Feb 2024 16:12:23 +0100 Subject: [PATCH] added test for federated user --- models/forgefed/federationhost.go | 3 +-- models/user/federated_user_test.go | 29 ++++++++++++++++++++++++ models/user/user_repository.go | 2 ++ models/user/user_service.go | 2 ++ routers/api/v1/activitypub/repository.go | 1 - 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 models/user/federated_user_test.go create mode 100644 models/user/user_repository.go create mode 100644 models/user/user_service.go diff --git a/models/forgefed/federationhost.go b/models/forgefed/federationhost.go index 936bbbd01a..eb1183a2a7 100644 --- a/models/forgefed/federationhost.go +++ b/models/forgefed/federationhost.go @@ -15,8 +15,7 @@ import ( // FederationHost data type // swagger:model type FederationHost struct { - ID int64 `xorm:"pk autoincr"` - // TODO: implement a toLower here & add a toLowerValidation + ID int64 `xorm:"pk autoincr"` HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"` NodeInfo NodeInfo `xorm:"extends NOT NULL"` LatestActivity time.Time `xorm:"NOT NULL"` diff --git a/models/user/federated_user_test.go b/models/user/federated_user_test.go new file mode 100644 index 0000000000..6a2112666f --- /dev/null +++ b/models/user/federated_user_test.go @@ -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") + } +} diff --git a/models/user/user_repository.go b/models/user/user_repository.go new file mode 100644 index 0000000000..78be927498 --- /dev/null +++ b/models/user/user_repository.go @@ -0,0 +1,2 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/models/user/user_service.go b/models/user/user_service.go new file mode 100644 index 0000000000..78be927498 --- /dev/null +++ b/models/user/user_service.go @@ -0,0 +1,2 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index 516e87ec88..2f61283bc3 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -245,7 +245,6 @@ func createFederationInfo(ctx *context.APIContext, actorID forgefed.ActorID) (fo return result, nil } -// ToDo: Maybe use externalLoginUser 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? actionsUser := user_model.NewActionsUser()